// jscript.js

//
// START INDEX STYLE SHEET
//

function checkNoOfChildren( value ) {

    if( value < 0 )
	return "-Number of Children cannot be less then 0\n";
	else return "";
 
}

//
// END INDEX STYLE SHEET
//

var msg = new Array();		// to hold arrary error messages
var msgIndex = 0; 	// mesage index
var mandatory = false; 	// default mandatory is false

function pop(url,name) { 
	return window.open(url,name,'top=20,left=20,width=600,height=600,scrollbars=1');
}

function popupWin(file,width,height) 
{
	if (navigator.appName == "Microsoft Internet Explorer") { width=width+20; height=height+20;}

	if (parseInt(navigator.appVersion) < 4)  
	{ 
		width=width+20; 
		height=height+20; 
	}

	newWindow = window.open(file,"PopupWindow","target=_blank,alwaysRaised=yes,dependent=no,toolbar=no,location=no,status=no,scrollbars=yes,resizable=no,width="+width+",height="+height);


	if (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 3) 
	    newWindow = window.open(windowLoc,"PopupWindow","status=no,alwaysRaised=yes,scrollbars=yes,resizable=no,width="+width+",height="+height);


	if (parseInt(navigator.appVersion) >= 3 && navigator.appName == "Netscape")
	newWindow.focus();

}

var DEBUG=false;
var defaultEmptyOK = false


// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}


/* FUNCTIONS TO NOTIFY USER OF INPUT REQUIREMENTS OR MISTAKES. */


// Display prompt string s in status bar.

function prompt (s)
{   window.status = s
}

function trim(strText) {
   // this will get rid of leading spaces
   while (strText.substring(0,1) == ' ')
       strText = strText.substring(1, strText.length);

   // this will get rid of trailing spaces
   while (strText.substring(strText.length-1,strText.length) == ' ')
       strText = strText.substring(0, strText.length-1);

  return strText;
} 

//
//  Status bar functions
//

function showStatus (str) {
window.status = str; 
return true;
}


function isEligible()
{
   var argv=isEligible.arguments;
   var argc=argv.length;
   var i=0;
   var applicantCountry;
   var spouseCountry;
   switch(argc)
   {
	case 1:
		break;
	case 2: 
		applicantCountry=document.getElementById(argv[1]);
		applicantCountry=applicantCountry.options[applicantCountry.selectedIndex].value;
		if(isEligibleCountry(applicantCountry))
		{
		   ShowContent(argv[0]);
		}
		break;	
	case 3:
		applicantCountry=document.getElementById(argv[1]);
		
                applicantCountry=applicantCountry.options[applicantCountry.selectedIndex].value;
                spouseCountry=document.getElementById(argv[2]);
		spouseCountry=spouseCountry.options[spouseCountry.selectedIndex].value;
		if(isEligibleCountry(applicantCountry) && isEligibleCountry(spouseCountry))
		{
		   ShowContent(argv[0]);	
		}
		else
		{
		   HideContent(argv[0]);
		}
		break;
	case 4:
                applicantCountry=document.getElementById(argv[2]);
                applicantCountry=applicantCountry.options[applicantCountry.selectedIndex].value;
		if(argv[3] == "countdown")
		{
		  if(isEligibleCountry(applicantCountry))
		  {
			ShowContent(argv[0]);
			ShowContent(argv[1]);
		  }
		}		
		else
		{
                spouseCountry=document.getElementById(argv[3]);
                spouseCountry=spouseCountry.options[spouseCountry.selectedIndex].value;
                if(isEligibleCountry(applicantCountry) && isEligibleCountry(spouseCountry))
                {
                   ShowContent(argv[0]);
                   ShowContent(argv[1]);
                }
                else
                {
                   HideContent(argv[0]);
                   HideContent(argv[1]);
                }

		}




		break;
	case 5:
		applicantCountry=document.getElementById(argv[0]);

                applicantCountry=applicantCountry.options[applicantCountry.selectedIndex].value;
		if(!isEligibleCountry(applicantCountry))
		{
			HideContent(argv[3]);
                        HideContent(argv[4]);
		}
		else
		{
		     if(document.getElementById(argv[1]).checked)
		     {
			HideContent(argv[4]);
			ShowContent(argv[3]);
		     }
                     if(document.getElementById(argv[2]).checked) 
                     {
                        HideContent(argv[3]);
                        ShowContent(argv[4]);
                     }
		}
		break;
       case 6:
                applicantCountry=document.getElementById(argv[0]);

                applicantCountry=applicantCountry.options[applicantCountry.selectedIndex].value;
                if(!isEligibleCountry(applicantCountry))
                {
                        HideContent(argv[3]);
                        HideContent(argv[4]);
                        HideContent(argv[5]);			
                }
                else
                {
                     if(document.getElementById(argv[1]).checked)
                     {
                        HideContent(argv[5]);
                        HideContent(argv[4]);
                        ShowContent(argv[3]);
                     }
                     if(document.getElementById(argv[2]).checked)
                     {
                        HideContent(argv[3]);
                        ShowContent(argv[4]);
                        ShowContent(argv[5]);
                     }
                }
                break;

   }	
}

function isEligibleCountry(value)
{
     var eligibleCountries = "-61-65-81-86-82-91-165-223-95-102-175-104-106-112-120-140-146-156-163-221-190-177-181-183-187-261-262-189-194-147-182-185-1000-0-";
     var country = "-" + value + "-";
     if(eligibleCountries.indexOf(country) >= 0)
	{
	return true;
	}
     else
	{
	return false;
	}

}

function HideContent() {
   var argv=HideContent.arguments;
   var argc=argv.length;
   var i;
   if(argc < 1) { return; }
   for(i=0;i< argc;i++)
   {
      document.getElementById(argv[i]).style.display = "none";
   }

}
function ShowContent() {
   var argv=ShowContent.arguments;
   var argc=argv.length;
   if(argc < 1) { return; }
   for(i=0;i< argc;i++)
   {
       document.getElementById(argv[i]).style.display = "";
   }
}

var plan1;
var plan2;
var plan3;
var plan4;
var plan5;
var plan6;
var plan7;
var amount1="$69";
var amount2="$119";
var amount3="$79";
var amount4="$99";
var amount5="$199";
var amount6="$499";
var amount7="$499";
var extamount1="$79";
var extamount2="$129";
var extamount3="$89";
var extamount4="$109";
var extamount5="$209";
var extamount6="$509";
var extamount7="$509";

function displayPlan()
{
   var argv=displayPlan.arguments;
   var argc=argv.length;
   var id = argv[0];
   document.getElementById(argv[1]).innerHTML=plan1;
   if(id == "applicationType.1" && document.getElementById(id).checked)
   {
      
      document.getElementById(argv[2]).innerHTML=plan1;
      document.getElementById(argv[1]).innerHTML=plan1;
      document.getElementById(argv[3]).innerHTML=amount1;
      document.getElementById(argv[4]).innerHTML=amount1;
      if(document.getElementById(argv[5]) != null && document.getElementById(argv[5]) != undefined)
      {
	document.getElementById(argv[5]).innerHTML=extamount1;
      }
   }
   if(id == "applicationType.2" && document.getElementById(id).checked)
   {
      document.getElementById(argv[2]).innerHTML=plan2;
      document.getElementById(argv[1]).innerHTML=plan2;
      document.getElementById(argv[3]).innerHTML=amount2;
      document.getElementById(argv[4]).innerHTML=amount2;
      if(document.getElementById(argv[5]) != null && document.getElementById(argv[5]) != undefined)
      {
        document.getElementById(argv[5]).innerHTML=extamount2;
      }

   }
   if(id == "applicationType.3" && document.getElementById(id).checked)
   {
      document.getElementById(argv[2]).innerHTML=plan3;
      document.getElementById(argv[1]).innerHTML=plan3;
      document.getElementById(argv[3]).innerHTML=amount3;
      document.getElementById(argv[4]).innerHTML=amount3;
      if(document.getElementById(argv[5]) != null && document.getElementById(argv[5]) != undefined)
      {
        document.getElementById(argv[5]).innerHTML=extamount3;
      }


   }
   if(id == "applicationType.4" && document.getElementById(id).checked)
   {
      document.getElementById(argv[2]).innerHTML=plan4;
      document.getElementById(argv[1]).innerHTML=plan4;
      document.getElementById(argv[3]).innerHTML=amount4;
      document.getElementById(argv[4]).innerHTML=amount4;
      if(document.getElementById(argv[5]) != null && document.getElementById(argv[5]) != undefined)
      {
        document.getElementById(argv[5]).innerHTML=extamount4;
      }


   }
   if(id == "applicationType.5" && document.getElementById(id).checked)
   {
      document.getElementById(argv[2]).innerHTML=plan5;
      document.getElementById(argv[1]).innerHTML=plan5;
      document.getElementById(argv[3]).innerHTML=amount5;
      document.getElementById(argv[4]).innerHTML=amount5;
      if(document.getElementById(argv[5]) != null && document.getElementById(argv[5]) != undefined)
      {
        document.getElementById(argv[5]).innerHTML=extamount5;
      }


   }
   if(id == "applicationType.6" && document.getElementById(id).checked)
   {
      document.getElementById(argv[2]).innerHTML=plan6;
      document.getElementById(argv[1]).innerHTML=plan6;
      document.getElementById(argv[3]).innerHTML=amount6;
      document.getElementById(argv[4]).innerHTML=amount6;
      if(document.getElementById(argv[5]) != null && document.getElementById(argv[5]) != undefined)
      {
        document.getElementById(argv[5]).innerHTML=extamount6;
      }


   }
   if(id == "applicationType.7" && document.getElementById(id).checked)
   {
      document.getElementById(argv[2]).innerHTML=plan7;
      document.getElementById(argv[1]).innerHTML=plan7;
      document.getElementById(argv[3]).innerHTML=amount7;
      document.getElementById(argv[4]).innerHTML=amount7;
      if(document.getElementById(argv[5]) != null && document.getElementById(argv[5]) != undefined)
      {
        document.getElementById(argv[5]).innerHTML=extamount7;
      }


   }
   

}

function displayInstruction()
{
   var argv=displayInstruction.arguments;
var originalContent = document.getElementById(argv[1]).innerHTML;
var dynamicContent = document.getElementById(argv[2]).innerHTML;
document.getElementById(argv[1]).innerHTML=dynamicContent;
var content = document.getElementById(argv[0]).innerHTML;
document.getElementById(argv[1]).innerHTML=originalContent;
popupWin=window.open("","",'toolbars=no,scrollbars=yes,noresize,resizable=yes,width=600,height=1300');
popupWin.document.write('<html><head><title>USAGS</title> <link rel="stylesheet" type="text/css" href="/css/styles.css" /><link rel="stylesheet" type="text/css" href="/css/photos.css" /></head><body><div id="offlineInstructions">');
popupWin.document.write(content);
popupWin.document.write('<div class="formButtons border-top"><div class="formButtonsLeft"><input type="button" id="print" value="');
popupWin.document.write(argv[3]);
popupWin.document.write('" onclick="javascript:self.print();" /></div><div class="formButtonsRight"><input type="button" value="');
popupWin.document.write(argv[4]);
popupWin.document.write('" onclick="window.close()" /></div>    </div></div></body></html>');
popupWin.document.close();
popupWin.focus();
}

var accoutNumber;
function accountNumberWesternUnion(accNo){
accountNumber=accNo;
}

function displayInstructionWesternUnion()
{
window.open("/westernunion.html","",'toolbars=no,scrollbars=yes,noresize,resizable=yes,width=750,height=1300');
}

function setPlanContent()
{
   var argv=setPlanContent.arguments;
   var argc=argv.length;
    plan1 =argv[0];
    plan2 =argv[1];
    plan3 =argv[2];
    plan4 =argv[3];
    plan5 =argv[4];
    plan6 =argv[5];
    plan7 =argv[6];
    if(argv[7] != null)
    {
	amount1 += " " + argv[7];
        amount2 += " " + argv[7];
        amount3 += " " + argv[7];
        amount4 += " " + argv[7];
        amount5 += " " + argv[7];
        amount6 += " " + argv[7];
        amount7 += " " + argv[7];
    }
}

function eligibilityDisable(id,secid)
{
document.getElementById(id).disabled=true;
document.getElementById(secid).className="none";
}

function eligibilityEnable(id,secid)
{
document.getElementById(id).disabled=false;
document.getElementById(secid).className="";

}

function checkBoxContentCheck()
{
   var argv=checkBoxContentCheck.arguments;
   var argc=argv.length;
   var id1;
   var id2;
   var id3;
   var id4;
   var id5;
   var id6;
   var id7;
   if(document.getElementById(argv[0]).checked)
   {
        id1=argv[1] + "-1";
        id2=argv[2] + "-1";
        id3=argv[3] + "-1";
        id4=argv[4] + "-1";
        id5=argv[5] + "-1";
        id6=argv[6] + "-1";
        HideContent(id1,id2,id3,id4,id5,id6);
	
	id1=argv[1] + "-2";
        id2=argv[2] + "-2";
        id3=argv[3] + "-2";
        id4=argv[4] + "-2";
        id5=argv[5] + "-2";
        id6=argv[6] + "-2";
        ShowContent(id1,id2,id3,id4,id5,id6,argv[4]);
   }
   else
   {
        id1=argv[1] + "-2";
        id2=argv[2] + "-2";
        id3=argv[3] + "-2";
        id4=argv[4] + "-2";
        id5=argv[5] + "-2";
        id6=argv[6] + "-2";
        HideContent(id1,id2,id3,id4,id5,id6);

        id1=argv[1] + "-1";
        id2=argv[2] + "-1";
        id3=argv[3] + "-1";
        id4=argv[4] + "-1";
        id5=argv[5] + "-1";
        id6=argv[6] + "-1";
        ShowContent(id1,id2,id3,id4,id5,id6,argv[4]);

   }

}


function onStateSelect()
{
// Arguments : 1 - state control id
//	       2 - country control id
   var argv=onStateSelect.arguments;
   var argc=argv.length;   
   var selectCountry;
   var canadaStates = "-AB-BC-MB-NB-NL-NT-NS-NU-ON-PE-QC-SK-YT-";
   var selectedState = document.getElementById(argv[0]);
   selectedState = '-' + selectedState.options[selectedState.selectedIndex].value + '-';
   if(canadaStates.indexOf(selectedState) >= 0)
   {
	selectCountry = document.getElementById(argv[1]);
	//selectCountry.options[selectedCountry.selectedIndex].value = "221";
	selectCountry.value= "221";
   }
   else
   {
        selectCountry = document.getElementById(argv[1]);
       // selectCountry.options[selectedCountry.selectedIndex].value = "223";
	selectCountry.value= "223";
   }   
   

}

function onPaymentStateSelect()
{
// Arguments : 1 - state control id
//             2 - country control id
   var argv=onPaymentStateSelect.arguments;
   var argc=argv.length;
   var selectCountry;
   var canadaStates = "-AB-BC-MB-NB-NL-NT-NS-NU-ON-PE-QC-SK-YT-";
   var selectedState = document.getElementById(argv[0]);
   selectedState = '-' + selectedState.options[selectedState.selectedIndex].value + '-';
   if(canadaStates.indexOf(selectedState) >= 0)
   {
        selectCountry = document.getElementById(argv[1]);
        //selectCountry.options[selectedCountry.selectedIndex].value = "221";
        selectCountry.value= "CA";
        if(document.getElementById(argv[2]).value == "NA")
        {
           document.getElementById(argv[2]).value="";
        }
        if(document.getElementById(argv[3]).value == "NA")
        {
           document.getElementById(argv[3]).value="";
        }
        if(document.getElementById(argv[4]).value == "NA")
        {
           document.getElementById(argv[4]).value="";
        }
        if(document.getElementById(argv[5]).value == "NA")
        {
           document.getElementById(argv[5]).value="";
        }
   }
   else
   {
        selectCountry = document.getElementById(argv[1]);
       // selectCountry.options[selectedCountry.selectedIndex].value = "223";
        selectCountry.value= "US";
        if(document.getElementById(argv[2]).value == "NA")
        {
           document.getElementById(argv[2]).value="";
        }
        if(document.getElementById(argv[3]).value == "NA")
        {
           document.getElementById(argv[3]).value="";
        }
        if(document.getElementById(argv[4]).value == "NA")
        {
           document.getElementById(argv[4]).value="";
        }
        if(document.getElementById(argv[5]).value == "NA")
        {
           document.getElementById(argv[5]).value="";
        }
   }


}

function onCountrySelect()
{
   var argv=onCountrySelect.arguments;
   var argc=argv.length;
   var selectedCountry = document.getElementById(argv[0]);
   selectedCountry = selectedCountry.options[selectedCountry.selectedIndex].value;
   if(selectedCountry != "221" && selectedCountry != "223")
   {
	HideContent(argv[1]);
        HideContent(argv[2]);
   }
   else
   {
        ShowContent(argv[2]);
        ShowContent(argv[1]);
   }
}

function onPaymentCountrySelect()
{
   var argv=onPaymentCountrySelect.arguments;
   var argc=argv.length;
   var selectedCountry = document.getElementById(argv[0]);
   selectedCountry = selectedCountry.options[selectedCountry.selectedIndex].value;
	
   if(selectedCountry != "CA" && selectedCountry != "US")
   {
        HideContent(argv[1]);
        HideContent(argv[2]);
        HideContent(argv[3]);
        HideContent(argv[4]);
        HideContent(argv[5]);
        HideContent(argv[6]);
        HideContent(argv[7]);
        HideContent(argv[8]);
        HideContent(argv[9]);
        HideContent(argv[10]);
	document.getElementById(argv[11]).value="NA";
        document.getElementById(argv[12]).value="NA";
        document.getElementById(argv[13]).value="NA";
        document.getElementById(argv[14]).value="NA";
        document.getElementById(argv[15]).value="NA";
   }
   else
   {
	if(selectedCountry == "CA" || selectedCountry == "US"){
	    document.getElementsByName("billTo_state")[0].value="";
	    //alert(document.getElementById("billTo_state")[0].value);	
	}
        ShowContent(argv[2]);
        ShowContent(argv[1]);
        ShowContent(argv[3]);
        ShowContent(argv[4]);
        ShowContent(argv[5]);
        ShowContent(argv[6]);
        ShowContent(argv[7]);
        ShowContent(argv[8]);
        ShowContent(argv[9]);
        ShowContent(argv[10]);
        if(document.getElementById(argv[11]).value == "NA")
        {
           document.getElementById(argv[11]).value="";
        }
        if(document.getElementById(argv[12]).value == "NA")
        {
           document.getElementById(argv[12]).value="";
        }
        if(document.getElementById(argv[13]).value == "NA")
        {
           document.getElementById(argv[13]).value="";
        }
        if(document.getElementById(argv[14]).value == "NA")
        {
           document.getElementById(argv[14]).value="";
        }
        if(document.getElementById(argv[15]).value == "NA")
        {
           document.getElementById(argv[15]).value="";
        }

   }
}

function savecontinue(actn)
{
// alert (actn);
if(actn=='savecontinue')
{
//alert ("I am IN");
document.forms[0].opr.value='scon';
//alert('Checking for hidden field' + document.forms[0].opr.value);
}

}

function resetnextpage()
{
 document.forms[0].opr.value='nextPage';
}

function planValue()
{
    var user_input;
    for ( var i=0;i<document.forms[0].applicationType.length;i++) {
     if (document.forms[0].applicationType[i].checked) {
//              user_input = document.forms[0].applicationType[i].value;
       }
  }

 //document.forms[0].prodId.value=user_input;
    if(user_input == 1)
       document.forms[0].amount.value="49.00";
    if(user_input == 2)
    document.forms[0].amount.value="69.00";
    if(user_input == 3)
    document.forms[0].amount.value="119.00";
    if(user_input == 4)
    document.forms[0].amount.value="79.00";
    if(user_input == 5)
    document.forms[0].amount.value="99.00";
    if(user_input == 6)
    document.forms[0].amount.value="199.00";
    if(user_input == 7)
    document.forms[0].amount.value="299.00";
}

function setCheckBoxValue(id)
{
if(document.getElementById(id).checked)
  document.getElementById(id).value=true;
else
  document.getElementById(id).value=false;
}
function planSubmit()
{
   var action = document.forms[0].action;
   if (action.indexOf("?") != -1) {
        action += "&planselect=success";
   } else {
        action += "?planselect=success";
   }
   document.forms[0].action = action;
   document.forms[0].submit();
}

/* FAQ  - Show and Hide of Answers */

function getFAQId(qstId)
{
	var Id = qstId
	document.getElementById('ans-div').style.display = "";
	for(var i=1;i<54;i++)
	{
		if(document.getElementById('ans'+i).style.display != "none")
		{
			document.getElementById('ans'+i).style.display = "none";
		}
	}
	if (Id == 'q1'){document.getElementById('ans1').style.display = "";}
	if (Id == 'q2'){document.getElementById('ans2').style.display = "";}
	if (Id == 'q3'){document.getElementById('ans3').style.display = "";}
	if (Id == 'q4'){document.getElementById('ans4').style.display = "";}
	if (Id == 'q5'){document.getElementById('ans5').style.display = "";}
	if (Id == 'q6'){document.getElementById('ans6').style.display = "";}
	if (Id == 'q7'){document.getElementById('ans7').style.display = "";}
	if (Id == 'q8'){document.getElementById('ans8').style.display = "";}
	if (Id == 'q9'){document.getElementById('ans9').style.display = "";}
	if (Id == 'q10'){document.getElementById('ans10').style.display = "";}
	if (Id == 'q11'){document.getElementById('ans11').style.display = "";}
	if (Id == 'q12'){document.getElementById('ans12').style.display = "";}
	if (Id == 'q13'){document.getElementById('ans13').style.display = "";}
	if (Id == 'q14'){document.getElementById('ans14').style.display = "";}
	if (Id == 'q15'){document.getElementById('ans15').style.display = "";}
	if (Id == 'q16'){document.getElementById('ans16').style.display = "";}
	if (Id == 'q17'){document.getElementById('ans17').style.display = "";}
	if (Id == 'q18'){document.getElementById('ans18').style.display = "";}
	if (Id == 'q19'){document.getElementById('ans19').style.display = "";}
	if (Id == 'q20'){document.getElementById('ans20').style.display = "";}
	if (Id == 'q21'){document.getElementById('ans21').style.display = "";}
	if (Id == 'q22'){document.getElementById('ans22').style.display = "";}
	if (Id == 'q23'){document.getElementById('ans23').style.display = "";}
	if (Id == 'q24'){document.getElementById('ans24').style.display = "";}
	if (Id == 'q25'){document.getElementById('ans25').style.display = "";}
	if (Id == 'q26'){document.getElementById('ans26').style.display = "";}
	if (Id == 'q27'){document.getElementById('ans27').style.display = "";}
	if (Id == 'q28'){document.getElementById('ans28').style.display = "";}
	if (Id == 'q29'){document.getElementById('ans29').style.display = "";}
	if (Id == 'q30'){document.getElementById('ans30').style.display = "";}
	if (Id == 'q31'){document.getElementById('ans31').style.display = "";}
	if (Id == 'q32'){document.getElementById('ans32').style.display = "";}
	if (Id == 'q33'){document.getElementById('ans33').style.display = "";}
	if (Id == 'q34'){document.getElementById('ans34').style.display = "";}
	if (Id == 'q35'){document.getElementById('ans35').style.display = "";}
	if (Id == 'q36'){document.getElementById('ans36').style.display = "";}
	if (Id == 'q37'){document.getElementById('ans37').style.display = "";}
	if (Id == 'q38'){document.getElementById('ans38').style.display = "";}
	if (Id == 'q39'){document.getElementById('ans39').style.display = "";}
	if (Id == 'q40'){document.getElementById('ans40').style.display = "";}
	if (Id == 'q41'){document.getElementById('ans41').style.display = "";}
	if (Id == 'q42'){document.getElementById('ans42').style.display = "";}
	if (Id == 'q43'){document.getElementById('ans43').style.display = "";}
	if (Id == 'q44'){document.getElementById('ans44').style.display = "";}
	if (Id == 'q45'){document.getElementById('ans45').style.display = "";}
	if (Id == 'q46'){document.getElementById('ans46').style.display = "";}
	if (Id == 'q47'){document.getElementById('ans47').style.display = "";}
	if (Id == 'q48'){document.getElementById('ans48').style.display = "";}
	if (Id == 'q49'){document.getElementById('ans49').style.display = "";}
	if (Id == 'q50'){document.getElementById('ans50').style.display = "";}
	if (Id == 'q51'){document.getElementById('ans51').style.display = "";}
	if (Id == 'q52'){document.getElementById('ans52').style.display = "";}
	if (Id == 'q53'){document.getElementById('ans53').style.display = "";}		
}