// DHTML Rollover Script
var ns4, ie4, dom;

ns4 = (document.layers)? true:false;
ie4 = (document.all)? true:false;
dom = (document.getElementById) ? true:false;

function showDiv(id) {
	if (ns4) document.layers[id].visibility = "show";
	else if (ie4) document.all[id].style.visibility = "visible";
	else if (dom) document.getElementById(id).style.visibility = "visible";
}

function hideDiv(id) {
	if (ns4) document.layers[id].visibility = "hide";
	else if (ie4) document.all[id].style.visibility = "hidden";
	else if (dom) document.getElementById(id).style.visibility = "hidden";
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_selectedImage() { //v3.0
  var i,j=0,x,a=MM_selectedImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/**/
//hides the passed element
function hideObject(ID) {
  var obj = document.getElementById(ID);
  if(obj!=null)  obj.style.display = "none";
}	
	
// Shows a hidden page element
function showObject(ID) {
  var obj = document.getElementById(ID);
  if(obj!=null) obj.style.display = "block";
}


function switchPage(currentPage, nextPage) {
  if (areQuestionsComplete(currentPage)) {
    if (nextPage != null) {
      g_yesCount = parseInt(g_yesCount) + getYesCount();
      location.href= nextPage + "?yes=" + g_yesCount;
    }
    else {
      return true;
    }
  }
  else {
    if (nextPage != null) {
      showAlert(); //"Please answer all questions.");
    }
  }
}

function showAlert() {
    var hiddenMessage = document.getElementById("hidFillDetailsPopUpMsg");
    if (hiddenMessage != null) {
        alert(hiddenMessage.value);
    }
    else {
        alert("Please answer all questions.");
    }
}	

function stringStartsWith(obj, str) 
{return (obj.match("^"+str)==str)}

function getYesCount() {
  var qs = window.location.search.substring(1);
  var yes = qs.split("=");
  if (yes.length > 1) return parseInt(yes[1]);
  return 0;
}

var g_yesCount;

function isRadioButtonListChecked(ID) {
  if (isRadioButtonListYesChecked(ID))  g_yesCount++;
  
  var obj = document.getElementsByName(ID);
  var objChecked = false; 
  for (i = 0; i < obj.length; i++) {
    if (obj[i].checked == true) {
      objChecked = true;
    }
  }
  return objChecked;
}

function isRadioButtonListYesChecked(ID) {
  var obj = document.getElementsByName(ID);
  var objChecked = false; 
  for (i = 0; !objChecked && i < obj.length; i++) {
    if (stringStartsWith(obj[i].id, ("yes")) && obj[i].checked == true) {
      objChecked = true;
    }
  }
  return objChecked;
}

function areQuestionsComplete(pageDivId)
{
  g_yesCount = 0;
  switch(pageDivId)
  {
    case "page1":
      return isRadioButtonListChecked("question1") &&
          isRadioButtonListChecked("question2") &&
          isRadioButtonListChecked("question3");
    case "page2":
      return isRadioButtonListChecked("question4") &&
          isRadioButtonListChecked("question5") &&
          isRadioButtonListChecked("question6");
    case "page3":
      return isRadioButtonListChecked("question7") &&
          isRadioButtonListChecked("question8") &&
          isRadioButtonListChecked("question9");
          
    case "page4":
      return isRadioButtonListChecked("question10") &&
          isRadioButtonListChecked("question11") &&
          isRadioButtonListChecked("question12"); 
          
    case "page5":
      return isRadioButtonListChecked("question13") &&
          isRadioButtonListChecked("question14") &&
          isRadioButtonListChecked("question15");
          
    case "page6":
      return isRadioButtonListChecked("question16") &&
          isRadioButtonListChecked("question17") &&
          isRadioButtonListChecked("question18");
          
    default:
      return true;
  }
}
// cookie set get check

function getCookie(c_name) {
  if (document.cookie.length>0) {
    c_start=document.cookie.indexOf(c_name + "=");
    if (c_start!=-1) { 
      c_start=c_start + c_name.length+1; 
      c_end=document.cookie.indexOf(";",c_start);
      if (c_end==-1) c_end=document.cookie.length;
      return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
  return "";
}

function setCookie(c_name,value,expiredays) {
  var exdate=new Date();
  exdate.setDate(exdate.getDate()+expiredays);
  document.cookie=c_name+ "=" +escape(value)+
  ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function checkCookie() {
  username=getCookie('username');
  if (username!=null && username!="") {
    alert('Welcome again '+username+'!');
  }
  else {
    username=prompt('Please enter your name:',"");
    if (username!=null && username!="") {
      setCookie('username',username,1);
    }
  }
}



function ShowResults() {
  if (getYesCount() >= 7) {
    hideObject('ResultsUseRemax');
    showObject('ResultsDontNeedRemax');
  }
  else {
    showObject('ResultsUseRemax');
    hideObject('ResultsDontNeedRemax');
  }
}


function LanguageSelector () {

  var selectmenu=document.getElementById("sitelanguage")
  selectmenu.onclick=function() { //run some code when "onchange" event fires
    var chosenoption=this.options[this.selectedIndex] //this refers to "selectmenu"
    if (chosenoption.value!="nothing"){
		
      LangaugeChanged(chosenoption.value)
    }
  }
}


function LangaugeChanged(LangVal) {

  var curURL = location.href;
  var Params = location.search.replace(/^\?/,"");
  if (Params.length > 0)
    Params = Params.split('&');
  if (Params.length > 0)
    curURL = curURL.replace(/\?(.*)$/, "?");
  var KeyVal = null;
  var curQueryString = "";

  var LangKeyNotFound = true;
  for (var x = 0;x<Params.length;x++) {
    KeyVal = Params[x].split('=');
    if (/^lang$/i.test(KeyVal[0])) {
      KeyVal[1] = LangVal;
      LangKeyNotFound = false;
    }
    curQueryString += "&" + KeyVal[0] + "=" + KeyVal[1]
  }

  if (LangKeyNotFound)
    curQueryString += "&Lang=" + LangVal
  if (/\/$/.test(curURL)) {
    curURL += "Default.aspx?"
  }
  else if (curURL.Length - 4 == location.hostname.length) {
    curURL += "/Default.aspx?"
  }
  if (!/\?$/.test(curURL))
    curURL += '?'
  //location = curURL + curQueryString.replace(/^\&/,"");
  location.replace(curURL + curQueryString.replace(/^\&/,""));
}
