var exp = new Date();
exp.setFullYear(2100);

function NeatBackground(sHTML, sTitle, bCancel)
{
  window.neatBackground = null;
  this.elt = null;
  if (document.createElement && document.getElementById)
  {
    var dbg = document.createElement("div");
    dbg.id = "nd-bdg";
    dbg.className = "neat-dialog-bg";

    var dgc = document.createElement("div");
    dgc.className = "neat-dialog-cont";
    dgc.appendChild(dbg);
    //dgc.appendChild(dg);

    //adjust positioning if body has a margin
    if (document.body.offsetLeft > 0)
      dgc.style.marginLeft = document.body.offsetLeft + "px";

    document.body.appendChild(dgc);
    //if (bCancel) document.getElementById("nd-cancel").onclick = function()
    //{
    //  window.neatBackground.close();
    //};
    this.elt = dgc;
    window.neatBackground = this;


  }
}
NeatBackground.prototype.close = function()
{
  if (this.elt)
  {
    this.elt.style.display = "none";
    this.elt.parentNode.removeChild(this.elt);
  } 
  window.neatBackground = null;
  selects(true);
}
function openDialog()
  {
    var sHTML = '<p>Are you sure you want to destroy the world?</p>'+
      '<p><button onclick="window.neatBackground.close()">YES!</button></p>';
    selects(false);
    new NeatBackground(sHTML, "NeatBackground!", false);
  }

function selects(status)
{
var allselects = document.getElementsByTagName("select");
for (var i = 0; i < allselects.length; i++) {

status ? allselects[i].style.visibility="visible" : allselects[i].style.visibility="hidden";
		
}
}
function survey(){
parent.document.body.rows='100%,0%';
  if (document.createElement && document.getElementById)
  {
    var die = document.createElement("iframe");
    die.src = "newbot2.asp";
    die.name = "fake";
    die.id="fake";
    die.width="800";
    die.height="400";

    die.frameBorder="0";

    //adjust positioning if body has a margin
    if (document.body.offsetLeft > 0)
      die.style.marginLeft = document.body.offsetLeft + "px";
//    alert("appended");
    document.body.appendChild(die);

  }

openDialog();

document.getElementById('survey').style.visibility = "visible";
document.getElementById('survey').style.display = "block";


}

function closeSurvey(){
//alert('ok');
var fake = document.getElementById('fake');
fake.parentNode.removeChild(fake);
//die.parentNode.removeChild(die);
document.getElementById('survey').style.visibility = "hidden";
document.getElementById('survey').style.display = "none";
//parent.document.body.rows='285,*';
parent.document.body.rows='321,*';
window.neatBackground.close();

}


function closeNews(){
var fake = parent.document.getElementById('fake');
fake.parentNode.removeChild(fake);

//die.parentNode.removeChild(die);
parent.document.getElementById('survey').style.visibility = "hidden";
parent.document.getElementById('survey').style.display = "none";
//top.document.body.rows='285,*';
top.document.body.rows='321,*';
//parent.document.getElementById("u").setAttribute("rows",'285,*'); // U is framset
parent.window.neatBackground.close();

var botfr = top.document.getElementById("botfr");

if(!parent.document.getElementById('source').value){
//alert("reloading bottom")
/*if(botfr.document)
	botfr.document.location.reload()
else if(botfr.contentDocument)
	botfr.contentDocument.location.reload();
*/
top.botfr.location.reload();  //Works for both IE and FF
}
else{
	//alert("translating bottom");
	parent.go_ahead();
}

//parent.window.getFrame("botfr",window.parent).reload();
//top.document.getElementById("botfr").document.location.reload();
//parent.getElementById("botfr").reload();
//go_ahead();
var surveyiframe = parent.document.getElementById('portalsignup_iframe');
surveyiframe.parentNode.removeChild(surveyiframe);


}
function fill_iframe(step)
{

var ourdiv=document.getElementById("survey");
var ouriframe = document.createElement("iframe");
step?ouriframe.src = "survey.asp?step="+step:ouriframe.src = "survey.asp";
ouriframe.name = "survey_iframe";
ouriframe.id = "survey_iframe";

if(navigator.userAgent.indexOf("sv1") == -1){
   if(navigator.appName == "Microsoft Internet Explorer"){
	ouriframe.width = "600";
	ouriframe.height="362";
   }else{
	ouriframe.width = "620";
	ouriframe.height="370";
   }	

}else{
   if(navigator.appName == "Microsoft Internet Explorer"){
	ouriframe.width = "600";
	ouriframe.height="350";
   }else{
	ouriframe.width = "620";
	ouriframe.height="370";
   }	
}

ouriframe.frameBorder="0";
ouriframe.scalling="no";
ouriframe.title="Translator iframe";
ourdiv.appendChild(ouriframe);
//<iframe src="news.asp" width="400" height="320" frameborder="0" scrolling="no"  title="Translator iframe"></iframe>
}
function fill_iframe_newssignup(step)
{

var ourdiv=document.getElementById("survey");
var ouriframe = document.createElement("iframe");
ouriframe.src = "news.asp";
ouriframe.name = "newssignup_iframe";
ouriframe.id = "newssignup_iframe";

if(navigator.userAgent.indexOf("sv1") == -1){
   if(navigator.appName == "Microsoft Internet Explorer"){
	ouriframe.width = "400";
	ouriframe.height="349";
   }else{
	ouriframe.width = "420";
	ouriframe.height="350";
   }	

}else{
   if(navigator.appName == "Microsoft Internet Explorer"){
	ouriframe.width = "400";
	ouriframe.height="335";
   }else{
	ouriframe.width = "420";
	ouriframe.height="350";
   }	
}

ouriframe.frameBorder="0";
ouriframe.scalling="no";
ouriframe.scrolling="no";
ouriframe.title="Translator iframe";
ourdiv.appendChild(ouriframe);
//<iframe src="news.asp" width="400" height="320" frameborder="0" scrolling="no"  title="Translator iframe"></iframe>
}

function fill_iframe_portalsignup(step)
{

  var frame1 = document.getElementById('portalsignup_iframe');
  if(frame1)	frame1.parentNode.removeChild(frame1);

   if(!document.getElementById('portalsignup_iframe')){

var ourdiv=document.getElementById("survey");
var ouriframe = document.createElement("iframe");
ouriframe.src = "portal.asp";
ouriframe.name = "portalsignup_iframe";
ouriframe.id = "portalsignup_iframe";

if(navigator.userAgent.indexOf("sv1") == -1){
   if(navigator.appName == "Microsoft Internet Explorer"){
	ouriframe.width = "600";
	ouriframe.height="349";
   }else{
	ouriframe.width = "620";
	ouriframe.height="350";
   }	

}else{
   if(navigator.appName == "Microsoft Internet Explorer"){
	ouriframe.width = "600";
	ouriframe.height="335";
   }else{
	ouriframe.width = "620";
	ouriframe.height="350";
   }	
}
ouriframe.frameBorder="0";
ouriframe.scalling="no";
ouriframe.scrolling="no";
ouriframe.title="Translator iframe";
ourdiv.appendChild(ouriframe);
}

}



function init_survey(trans){

/* Set to true to stop survey */
var disableSurvey = true;

if(disableSurvey){
//if(trans){setCookie("nOFt",getCookie("nOFt")*1+1,exp);}
}

//---------------Check if cookies are supported------------------//
//---------------Skip Opera browsers-----------------------------//
setCookie("test",1);
if(getCookie("test") == 1 && navigator.userAgent.indexOf("opera") == -1 && !disableSurvey){



var exp = new Date();
exp.setFullYear(2100);
//alert(getCookie("survey"));
//deleteCookie("survey_shown");
//deleteCookie("survey_yes_later");
//-------------Increment Number of Translations------------------//

//if(trans){setCookie("nOFt",getCookie("nOFt")*1+1,exp);}
//---------------------------------------------------------------//

//alert("survey_shown " +getCookie("survey_shown"));
if (getCookie("survey_shown")!=1)
{
var t = Math.ceil(Math.random()*3);  //RANDOM 1 or 2


//t=2;
//alert(t);
//alert("switch");
switch(t){

case 1: 
	//alert(t); 
	setCookie("survey_later",1,exp); 
        d(exp);
	break;

case 2: 
	//alert(t); 
	setCookie("survey_now",1,exp); 
	fill_iframe();
	survey(); 
	d(exp);
	break;

case 3: 
	//alert(t); 
	setCookie("survey_yes_later",1,exp); 
	fill_iframe();
	survey();
	d(exp);
	break;


default: break;
}

}
else{
//alert("else...number of trans "+getCookie('nOFt')+" survey_now "+getCookie('survey_now')+" survey_later "+getCookie('survey_later')+" survey_shown "+getCookie('survey_shown')+" yes_later "+ getCookie('survey_yes_later'));
}



//alert(getCookie("nOFt"));
if (getCookie("nOFt") == 5 && getCookie("survey_later") == "1"){
	fill_iframe();
	survey();
//	setCookie("nOFt",getCookie("nOFt")*1+1,exp);
}
if(getCookie("nOFt") == 5 && getCookie("survey_yes_later") == "2"){ 
	fill_iframe(1);
	survey();
//	setCookie("nOFt",getCookie("nOFt")*1+1,exp);
}


}



} 
function d(exp){
//alert("d");
setCookie("survey_shown",1,exp);
}

function init_newssignup(trans){
if(document.getElementById('gp').checked==true) setCookie("nOFt",0,exp);
//alert(getCookie("nOFt"));

  if (getCookie("nOFt") >= 150){
	fill_iframe_portalsignup();
	survey();        
        setCookie("nOFt",0,exp);
  }
  else setCookie("nOFt",getCookie("nOFt")*1+1,exp);

}

function init_signup_first_load(){
	fill_iframe_portalsignup();
	survey();        
        setCookie("nOFt",0,exp);
}



