﻿var pre = "ctl00_cph1_";
   //steps  
    function toTop(){
		window.scroll(0,0)
	}
	
	curStep = 1;
	maxStep = 5;
    function goTo(stepNum) {
        if(stepNum < maxStep) {
            document.getElementById("formSec" + curStep).style.display = "none";
            document.getElementById("formSec" + stepNum).style.display = "";
            document.getElementById("formBtn" + stepNum).className = "button buttonSelected"; 	
            //if (stepNum + 1 < maxStep){
            //    document.getElementById("formBtn" + (stepNum + 1)).className = "button buttonSelectable";		
            //}
            if (curStep > stepNum){
                document.getElementById("formBtn" + curStep).className = "button";		
            }
        } else {		
            for (c=1; c<maxStep; c++) {
                document.getElementById("formSec" + c).style.display = "";
                document.getElementById("formBtnBottom" + c).style.display = "none";
            }
            document.getElementById("submitFormBtn").style.display = "";          
        }
        curStep = stepNum;
		toTop();
    }
    function goBack() {
        for (c=1; c<maxStep; c++) {
            document.getElementById("formSec" + c).style.display = "none";
            document.getElementById("formBtnBottom" + c).style.display = "";
        }
        document.getElementById("submitFormBtn").style.display = "none";     
        curStep --;
        goTo(maxStep - 1)
    }
    
    
    
    //plan selection  
    function select(dv){
        inpt = dv.getElementsByTagName("input")[0];
        inpt.checked= true;
        document.getElementById(pre+"hdnAmount").value = inpt.value
    }
    
    
    //form submission    
            function submitForm(){
                showAll();
                var theForm = getTheForm();
                var validationResult = true;
		        if (typeof(Page_ClientValidate) == 'function') {
			        validationResult = Page_ClientValidate("");
			    }
		        if (validationResult) {
			        theForm.style.display = "none";
			        //document.getElementById("keys").style.display = "none";
			        document.getElementById("divWait").style.display = "block";
			        theForm.submit()
		        }else{
					document.getElementById("serverError").style.display = "none";
		            goToFirstError();
		        }
		    }
    
    function showAll(){
        for (c=1; c<maxStep; c++) {
            document.getElementById("formSec" + c).style.display = "";
            document.getElementById("formBtnBottom" + c).style.display = "none";
            document.getElementById("lastBackBtn").style.display = "none";  
        }
        document.getElementById("formBtnBottom4").style.display = "";
    }
    
    function getTheForm() {
        var theForm = document.forms[0];
        if (!theForm) {
            theForm = document.form1;
        } 
        return theForm;     
    }

function getElementsByClassName(className, tag, elm){
	var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i];
		//added to include class name ONLY if display is not none
		if(testClass.test(current.className) && elements[i].style.display != "none"){
			returnElements.push(current);
		}
	}
	return returnElements;
}
function alertSize() {
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}
function goToFirstError(){
    theForm=getTheForm();
    errors = getElementsByClassName("error", "span", theForm);
    offTop = errors[0].offsetParent.offsetTop -(alertSize()/2);
	//alert(offTop)
	//if (navigator.appName.indexOf('Microsoft')>-1) offTop += 100;
	window.scroll(0,offTop);
	//alert ("Please correct the highlighted fields, and resubmit the application");
}
    
    function toTop(){
		window.scroll(0,0)
	}
	
function serverError(msg){
    showAll();
	goToFirstError();
	alert(msg);
}	
	
	//heb ajax
	
function GetXmlHttpObject() { 
    var objXMLHttp=null
        if (window.XMLHttpRequest) {
           objXMLHttp=new XMLHttpRequest()
        }
        else if (window.ActiveXObject) {
            objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
        }
    return objXMLHttp
} 

function getHeb() {
    m = document.getElementById(pre + "slcPassMonth");
    d = document.getElementById(pre + "slcPassDay");
    y = document.getElementById(pre + "slcPassYear");
    sunset = "";
    if (document.getElementById(pre + "rbTime_1").checked) sunset = "&sunset=1";
	xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null) {
		return alert ("Your browser does not support AJAX.\nPlease enable HTTP requests or use a different browser.")
	}
	url = "/hebdate.ashx?date=" + m.value + "/" + d.value + "/"+ y.value + sunset;
    xmlHttp.onreadystatechange = getResultAddRecord;
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
	
}
function getResultAddRecord() {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
        if (xmlHttp.responseText != 0) {
            document.getElementById(pre + "txtHebrewDateClient").value = xmlHttp.responseText;
            document.getElementById(pre + "txtHebrewDate").value = xmlHttp.responseText;
        }else{
            document.getElementById(pre + "txtHebrewDateClient").value = ""; 
            document.getElementById(pre + "txtHebrewDate").value = "";
        }
    }
}


//validation


    
    function numeralsOnly(evt) {
        evt = (evt) ? evt : event;
        if (evt.charCode == 0 && (evt.keyCode > 34 && evt.keyCode < 47)) return true;
        var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
        if (charCode > 31 && (charCode < 48 || charCode > 57)) {
            return false;
        }
        return true;
    }
    
    function numeralsPlusOnly(evt) {
        evt = (evt) ? evt : event;
        if (evt.charCode == 0 && (evt.keyCode > 34 && evt.keyCode < 47)) return true;
        var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
        if (charCode > 32 && (charCode < 40 || charCode > 57 || charCode == 47 || charCode == 44 || charCode == 42)) {
            return false;
        }
        return true;
    }
    
    function phoneComp(inpt) {
        if(inpt.value.length == 3){
			inpt.nextSibling.nextSibling.focus();
        }
    }


function countryChange(){
    drpCountry = document.getElementById(pre + 'drpCountry');
    if (drpCountry.value == 'USA'){
        document.getElementById('dvCountryOther').style.display = 'none';
        document.getElementById(pre +'rfvCountryOther').enabled = false;
        document.getElementById(pre +'rfvCity').enabled = true;
        document.getElementById(pre +'rfvState').enabled = true;
        document.getElementById(pre +'rfvZip').enabled = true;
        document.getElementById(pre +'lblCityState').innerHTML = '*City, State:';
        document.getElementById(pre +'lblZip').innerHTML = '*Zip Code:';
    }else{
        document.getElementById('dvCountryOther').style.display = '';
        document.getElementById(pre +'rfvCountryOther').enabled = true;
        document.getElementById(pre +'rfvCity').enabled = false;
        document.getElementById(pre +'rfvState').enabled = false;
        document.getElementById(pre +'rfvZip').enabled = false;
        document.getElementById(pre +'lblCityState').innerHTML = 'City, State:';
        document.getElementById(pre +'lblZip').innerHTML = 'Zip Code:';
    }

}
function relationshipChange(){
    drpCountry = document.getElementById(pre + 'drpDeceasedRelate');
    if (drpCountry.value == 'Other'){
        document.getElementById('dvRelationOther').style.display = '';
        document.getElementById(pre +'rfvRelationship').enabled = true;
        document.getElementById(pre +'lblRelationship').innerHTML = '*Relationship:';
    }else{
        document.getElementById('dvRelationOther').style.display = 'none';
        document.getElementById(pre + 'txtRelationship').value = '';
        document.getElementById(pre +'rfvRelationship').enabled = false;
        document.getElementById(pre +'lblRelationship').innerHTML = 'Relationship:';
    }
}

function relationshipRemindChange(){
    drpCountry = document.getElementById(pre + 'drpRemindRelate');
    if (drpCountry.value == 'Other'){
        document.getElementById('dvRemindRelationOther').style.display = '';
    }else{
        document.getElementById('dvRemindRelationOther').style.display = 'none';
        document.getElementById(pre + 'txtRemindRelationship').value = '';
    }
}

function relationshipRemind2Change(){
    drpCountry = document.getElementById(pre + 'drpRemind2Relate');
    if (drpCountry.value == 'Other'){
        document.getElementById('dvRemind2RelationOther').style.display = '';
    }else{
        document.getElementById('dvRemind2RelationOther').style.display = 'none';
        document.getElementById(pre + 'txtRemind2Relationship').value = '';
    }
}



function skipToStep2(plan) {
    inpt = document.getElementById(pre + 'plan' + plan);
    inpt.checked= true;
    document.getElementById(pre+"hdnAmount").value = inpt.value;
    goTo(2);
}

