
/*	LOAD DEFAULTS TO THE COMBO BOXES*/
function initialComboSetup(selectedDobDay, selectedDobYear, selectedDoaDay, selectedDoaYear, selectedAddType, selectedCountry, selectedState, selectedCity) {
document.getElementById("title").focus();
	/*
	*loadDOY(param1,param2) //INIT DATE OF YEAR COMBO
	@param1 Document ID 
	@param2 selectedValue
	*/
	loadDOYGuru("dobyear", selectedDobYear);
	loadDOYGuru("doayear", selectedDoaYear);
	/*
	*loadDay(param1,param2)	//INIT DATE OF DAY COMBO
	@param1 Document ID 
	@param2 selectedValue
	*/
	loadDay("dobday", selectedDobDay);
	loadDay("doaday", selectedDoaDay);
	//INIT ADD TYPE COMBO
	initAddTypeCombo(selectedAddType);
	initCountryCombo(selectedCountry, selectedState, selectedCity);
	//initOtherTextFields(countryOther,stateOther,cityOther);		
}

///doy for guru
function loadDOYGuru(elementId, selectedYr) {
	var selectedFlag = false;
	document.formGuruRegBaseInfo.pwd.value = "";
	document.formGuruRegBaseInfo.confPwd.value = "";
	if (selectedYr != "" && selectedYr != null) {
		selectedFlag = true;
	}
	var today = new Date();
	var currYear = today.getFullYear();
	var index = 1;
	var frmYr = currYear - 5;
	var toYr = currYear - 30;
	if (elementId == "dobyear") {
		frmYr = currYear - 18;
		/*---------CHANGED BY ISHA DATE:24 NOV, GURU REG YEAR SHOULD BE FROM 1929 not 1911-----------*/
		toYr = currYear - 80;
	}
	if (elementId == "doayear") {
		frmYr = currYear;
		toYr = currYear - 100;
	}
	for (var yr = frmYr; yr > toYr; yr--) {
		document.getElementById(elementId).options[index] = new Option("" + yr + "", yr);
		if (selectedFlag) {
			if (selectedYr == yr) {
				document.getElementById(elementId).options[index].selected = true;
			}
		}
		index++;
	}
}
function initOtherTextFields(countryOther, stateOther, cityOther) {
	var country = document.formGuruRegBaseInfo.country.value;
	var conOtherId = document.formGuruRegBaseInfo.countryOther; //countryOther Document ID
	if ("null" == country && conOtherId != undefined) {
		conOtherId.value = countryOther;
	}
	var state = document.formGuruRegBaseInfo.state.value;
	var stateOtherId = document.formGuruRegBaseInfo.stateOther; //state other id
	if ("null" == state && stateOtherId != undefined) {
		stateOtherId.value = stateOther;
	}
	var city = document.formGuruRegBaseInfo.city.value;
	var cityOtherId = document.formGuruRegBaseInfo.cityOther; // state other id
	if ("null" == city && cityOtherId != undefined) {
		cityOtherId.value = cityOther;
	}
}
/* 

JSP	  : studentRegistrationpage2.jsp
Functionality : Ajax implementation of loading address types list on page load.
*/
function initAddTypeCombo(selectedAddType) {
	xmlHttp = getXMLHttpRequest();
	var queryString = "op=loadAddtypes";
	xmlHttp.open("POST", url, false);
	//xmlHttp.onreadystatechange = function () {
    
		//handleStateChangeForAddTypes(selectedAddType);
	//};
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.send(queryString);
	/*
}
function handleStateChangeForAddTypes(selectedAddType) {
*/
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			parseResultsForAddTypes(selectedAddType);
		}
	}
}
function parseResultsForAddTypes(selectedAddType) {
	var selectedFlag = false;
	if (selectedAddType != undefined) {
		selectedFlag = true;
	}
	var size = xmlHttp.responseXML.getElementsByTagName("Size")[0].firstChild.data;
	if ("0" != size) {
		for (var index = 0; index < size; index++) {
			var cnId = xmlHttp.responseXML.getElementsByTagName("Id")[index].firstChild.data;
			var cnName = xmlHttp.responseXML.getElementsByTagName("Name")[index].firstChild.data;
			document.getElementById("guru_add_type").options[index + 1] = new Option(cnName, cnId);
			if (selectedFlag) {
				if (selectedAddType == cnId) {
					document.getElementById("guru_add_type").options[index + 1].selected = true;
				}
			}
		}
	}
	//document.getElementById("guru_add_type").options[index + 1] = new Option("Other", null);
}
/* END OF Ajax implementation for loading address types on page load .*/
function initCountryCombo(selectedCountry, selectedState, selectedCity) {
	xmlHttp = getXMLHttpRequest();
	var queryString = "op=loadCountries";
	xmlHttp.open("POST", url, false);
	//xmlHttp.onreadystatechange = function () {
		//handleStateForCountry(selectedCountry, selectedState, selectedCity);
	//};
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.send(queryString);
	/*
}
function handleStateForCountry(selectedCountry, selectedState, selectedCity) {
*/
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			parseResultsForCountry(selectedCountry, selectedState, selectedCity);
		}
	}
}
function parseResultsForCountry(selectedCountry, selectedState, selectedCity) {
	var selectedFlag = false;
	if (selectedCountry != undefined) {
		selectedFlag = true;
	}
	var size = xmlHttp.responseXML.getElementsByTagName("Size")[0].firstChild.data;
	if ("0" != size) {
		var countries = xmlHttp.responseXML.getElementsByTagName("Country");
		for (var index = 0; index < size; index++) {
			var cnId = xmlHttp.responseXML.getElementsByTagName("Id")[index].firstChild.data;
			var cnName = xmlHttp.responseXML.getElementsByTagName("Name")[index].firstChild.data;
			document.getElementById("country").options[index + 1] = new Option(cnName, cnId);
			if (selectedFlag) {
				if (selectedCountry == cnId) {
					document.getElementById("country").options[index + 1].selected = true;
				}
			}
		}
	}
	//document.getElementById("country").options[index + 1] = new Option("Other", null);
	//if (selectedFlag && selectedCountry == "null") {
	//	document.getElementById("country").options[index + 1].selected = true;
	//}
	get_states_from_country(document.formGuruRegBaseInfo.country, document.formGuruRegBaseInfo.state, selectedState, selectedCity);
}
function get_states_from_country(field, field2, state, city) {
	/*
	*	CLEAR ALL OTHER OPTION( EX:- COUNTRYOTHER,STATEOTHER,CITYOTHER)
	
	*	AND ISDCODE FIELDS TO BLANK IF USER SELECTS A NEW COUNTRY
	*/
	document.formGuruRegBaseInfo.hiddenSTD1.value = "";
	document.formGuruRegBaseInfo.hiddenSTD2.value = "";
	if (state == undefined || state == null) {
		document.getElementById("stdCode1").value = "";
		document.getElementById("stdCode2").value = "";
	}
	if ("null" != document.getElementById("country").value) {
		document.getElementById("countryother1").style.display = "none";
		document.getElementById("stateother1").style.display = "none";
		document.getElementById("cityother1").style.display = "none";
	} else {
		document.getElementById("countryother1").style.display = "block";
		document.getElementById("stateother1").style.visiblity = "block";
		document.getElementById("cityother1").style.visiblity = "block";
	}
	if ("null" == state) {
		//document.getElementById("isdCode1").value = "";
		//document.getElementById("isdCode2").value = "";
	}
	if ("null" == city) {
		document.getElementById("stdCode1").value = "";
		document.getElementById("stdCode2").value = "";
	}
	/* IF USER SELECTS 'Select Your Country' OR 'Other' 
	call setDefaults() and return to JSP.		*/
	if ("0" == field.value || "null" == field.value) {
		setDefaults(city);
		return;
	}
	var req = getXMLHttpRequest();
	var country = field.options[field.selectedIndex].value;
	var query = "op=fetchStates&country=" + encodeURI(country);
	req.open("POST", url, false);
	//req.onreadystatechange = function () {
		//update_callbackForStates(req, field.id, field2.id, state, city);
	//};
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send(query);
	/*
}

function update_callbackForStates(req, field_id, field2_id, state, city) {
*/
	if (req.readyState == 4) {
		if (req.status == 200) {
			var xmlDocument = req.responseXML;
			update_sequenceForStates(field.id, xmlDocument, field2.id, state, city);
		}
	}
}
function update_sequenceForStates(field_id, xmlDocument, field2_id, state, city) {
	var selectedFlag = false;
	if (state != undefined) {
		selectedFlag = true;
	}
	document.getElementById(field2_id).options.length = 0;
	var isAvailable = xmlDocument.getElementsByTagName("isAvailable")[0].firstChild.data;
	document.getElementById(field2_id).options[0] = new Option("--Select Your State--", 0);
	if ("true" == isAvailable) {
		var size = xmlDocument.getElementsByTagName("Size")[0].firstChild.data;
		for (var z = 0; z < size; z++) {
			var id = xmlDocument.getElementsByTagName("Id")[z].firstChild.data;
			var name = xmlDocument.getElementsByTagName("Name")[z].firstChild.data;
			document.getElementById(field2_id).options[z + 1] = new Option(name, id);
			if (selectedFlag) {
				if (state == id) {
					document.getElementById(field2_id).options[z + 1].selected = true;
				}
			}
		}
		//
		document.getElementById(field2_id).options[z + 1] = new Option("Other", null);
		if (selectedFlag && state == "null") {
			document.getElementById(field2_id).options[z + 1].selected = true;
		}
		var isdcode = xmlDocument.getElementsByTagName("ISDCode")[0].firstChild.data;
		if ("null" != isdcode && !selectedFlag) {
			document.getElementById("isdCode1").value = isdcode;
			document.getElementById("isdCode2").value = isdcode;
		}
	}
	//alert("sadda");
	get_cities_from_state(document.formGuruRegBaseInfo.state, document.formGuruRegBaseInfo.city, city);
}
/*
Event : If user selects 'Select Your Country'/ 'Other'
Functionality	:	Clear old values of state list box
	load 'Select Your Country' if user has selected 'Select Your Country'
	load 'Select Your Country and 'Other' if 'Other' is selected.
	Also create a new text control for entering a country
	if user has selected 'other' in the country list.
*/
function setDefaults(selectedCity) {
	document.getElementById("state").options.length = 0;
	if ("null" == document.getElementById("country").value) {
		document.getElementById("state").options[0] = new Option("Other", null);
		document.getElementById("countryother1").style.display = "block";
		//document.getElementById("countrypanel").innerHTML = "Please enter your Country  <input type=text name='countryOther' id='countryOther' maxlength='50'/>";
		get_cities_from_state(document.formGuruRegBaseInfo.state, document.formGuruRegBaseInfo.city, selectedCity);
	} else {
		document.getElementById("state").options[0] = new Option("--Select Your State--", 0);
		get_cities_from_state(document.formGuruRegBaseInfo.state, document.formGuruRegBaseInfo.city, selectedCity);
	}
	document.getElementById("state").options[0].selected = true;
	return;
}
/*
AJAX response tracker for state population
*/
/*
AJAX response parser for state population
*/
function get_cities_from_state(field, field2, city) {
	document.formGuruRegBaseInfo.hiddenSTD1.value = "";
	document.formGuruRegBaseInfo.hiddenSTD2.value = "";
	if (city == null || city == undefined) {
		document.getElementById("stdCode1").value = "";
		document.getElementById("stdCode2").value = "";
	}
	if ("null" != document.formGuruRegBaseInfo.state.value) {
		document.getElementById("stateother1").style.display = "none";
		document.getElementById("cityother1").style.display = "none";
	}	
	//document.getElementById("stdCode1").value = "";
	//document.getElementById("stdCode2").value = "";
	if ("0" == field.value || "null" == field.value) {
		setDefaultsForCities();
		return;
	}
	var req = getXMLHttpRequest();
	var state = field.options[field.selectedIndex].value;
	var query = "op=fetchCities&state=" + encodeURI(state);
	req.open("POST", url, false);
	//req.onreadystatechange = function () {
		//update_callbackForCities(req, field.id, field2.id, city);
	//};
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send(query);
	/*	
}
function update_callbackForCities(req, field_id, field2_id, city) {
*/

//alert("FDGdfgdf"+req.readyState)
	if (req.readyState == 4) {
		if (req.status == 200) {
			var xmlDocument = req.responseXML;
			update_sequenceForCities(field.id, xmlDocument, field2.id, city);
		}
	}
}
function setDefaultsForCities() {
	document.getElementById("city").options.length = 0;
	if ("null" == document.getElementById("state").value) {
		document.getElementById("city").options[0] = new Option("Other", null);
		document.getElementById("stateother1").style.display = "block";
		get_std_from_city(document.formGuruRegBaseInfo.city);
	} else {
		document.getElementById("city").options[0] = new Option("--Select Your City--", 0);
	}
	document.getElementById("city").options[0].selected = true;
	return;
}
function update_sequenceForCities(field_id, xmlDocument, field2_id, city) {

	
	var selectedFlag = false;
	if (city != undefined) {
		selectedFlag = true;
	}
	document.getElementById(field2_id).options.length = 0;
	document.getElementById(field2_id).options[0] = new Option("--Select Your City--", 0);
	var isAvailable = xmlDocument.getElementsByTagName("isAvailable")[0].firstChild.data;
	if ("true" == isAvailable) {
		var size = xmlDocument.getElementsByTagName("Size")[0].firstChild.data;
		for (var z = 0; z < size; z++) {
			
			if (selectedFlag) {
				if (city == xmlDocument.getElementsByTagName("Id")[z].firstChild.data) {
					var id = xmlDocument.getElementsByTagName("Id")[z].firstChild.data;
					var name = xmlDocument.getElementsByTagName("Name")[z].firstChild.data;
					document.getElementById(field2_id).options[z + 1] = new Option(name, id);
					document.getElementById(field2_id).options[z + 1].selected = true;
				} else {
					var id = xmlDocument.getElementsByTagName("Id")[z].firstChild.data;
					var name = xmlDocument.getElementsByTagName("Name")[z].firstChild.data;
					document.getElementById(field2_id).options[z + 1] = new Option(name, id);
				}
			} else {
				var id = xmlDocument.getElementsByTagName("Id")[z].firstChild.data;
				var name = xmlDocument.getElementsByTagName("Name")[z].firstChild.data;
				document.getElementById(field2_id).options[z + 1] = new Option(name, id);
				document.getElementById(field2_id).options[0].selected = true;
			}
		}
		document.getElementById(field2_id).options[z + 1] = new Option("Other", null);
		if (selectedFlag && city == "null") {			
			document.getElementById(field2_id).options[z + 1].selected = true;
			setDefaultsForSTD()
		}
	}
}
function get_std_from_city(field) {
	
	document.getElementById("stdCode1").value = "";
	document.getElementById("stdCode2").value = "";
	//document.getElementById("citypanel").innerHTML = "";
	document.getElementById("cityother1").style.display = "none";
	if ("0" == field.value || "null" == field.value) {
		
		setDefaultsForSTD();
		return;
	}
	var req = getXMLHttpRequest();
	var city = field.options[field.selectedIndex].value;
	var query = "op=fetchStd&city=" + encodeURI(city);
	req.open("POST", url, false);
	//req.onreadystatechange = function () {
		//update_callbackForSTD(req, field.id);
	//};
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send(query);
	/*	
}
function update_callbackForSTD(req, field_id) {*/
	if (req.readyState == 4) {
		if (req.status == 200) {
			var xmlDocument = req.responseXML;
			update_sequenceForSTD(field.id, xmlDocument);
		}
	}
}
function setDefaultsForSTD() {
	
	if ("null" == document.getElementById("city").value) {
		
		document.getElementById("cityother1").style.display = "block";
		//document.getElementById("citypanel").innerHTML = "Please enter your Cityt<input type=text name='cityOther' id='cityOther' maxlength='50'/>";
	}
	return;
}

//Changes By: Lokesh Thakar//
//Purpose: Conditionally populating the STD Textbox//
var temp1Std = "";
var temp2Std = "";
function update_sequenceForSTD(field_id, xmlDocument) {
	var stdcode = xmlDocument.getElementsByTagName("STDCode")[0].firstChild.data;
	if ("NA" == stdcode) {
		stdcode = "";
		document.formGuruRegBaseInfo.hiddenSTD1.value = "";
		document.formGuruRegBaseInfo.hiddenSTD2.value = "";
		temp1Std = "";
		temp2Std = "";
	}
	if ("null" != stdcode) {
		if (document.formGuruRegBaseInfo.tel1Type.value != "Mobile") {
			//alert("STD val if---"+document.getElementById("stdCode1").value)	
			document.getElementById("stdCode1").value = stdcode;
			document.formGuruRegBaseInfo.hiddenSTD2.value = stdcode;
			document.formGuruRegBaseInfo.hiddenSTD1.value = stdcode;
		} else {
			document.formGuruRegBaseInfo.hiddenSTD1.value = stdcode;
			document.formGuruRegBaseInfo.hiddenSTD2.value = stdcode;
			temp1Std = stdcode;
			//alert("STD val else---"+temp1Std)	
		}
		if (document.formGuruRegBaseInfo.tel2Type.value != "Mobile") {
			document.getElementById("stdCode2").value = stdcode;
		} else {
			temp2Std = stdcode;
		}
	}
}
/*	FORM VALIDATION AND SUBMISSION	*/
function validateForm() {
	var errorMsgs = new Array();
	var errorFlag = true;
	var errorIndex = 0;
	var title = document.formGuruRegBaseInfo.title.value;
	if ("null" == title) {
		errorMsgs[errorIndex] = emptyTitle;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	var fname = document.getElementById("fname").value;
	if (isEmpty(fname)) {
		errorMsgs[errorIndex] = emptyFirstName;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	if (!isValidGName(fname) && !isEmpty(fname)) {
		errorMsgs[errorIndex] = invalidFirstName;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	var mname = document.getElementById("mname").value;
	if (!isEmpty(mname) && !isValidGName(mname)) {
		errorMsgs[errorIndex] = invalidMiddleName;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	var lname = document.getElementById("lname").value;
	if (isEmpty(lname)) {
		errorMsgs[errorIndex] = emptyLastName;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	if (!isValidGName(lname) && !isEmpty(lname)) {
		errorMsgs[errorIndex] = invalidLastName;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	var nickName = document.formGuruRegBaseInfo.nickName.value;
	if (isEmpty(nickName)) {
		errorMsgs[errorIndex] = emptyNickName;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	if (!isEmpty(nickName)  && !isValidNickName(nickName) ) {
		errorMsgs[errorIndex] = invalidNickName;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	var emailId = document.formGuruRegBaseInfo.emailId.value;
	if (isEmpty(emailId)) {
		errorMsgs[errorIndex] = emptyEmailAddress;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	var x = isValidEmail(emailId);
	if (!isEmpty(emailId) && -1 != x) {
		errorMsgs[errorIndex] = emailError[x];
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	var confEmailId = document.formGuruRegBaseInfo.confEmailId.value;
	if (isEmpty(confEmailId)) {
		errorMsgs[errorIndex] = emptyConfirmEmail;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	/*
	var y = isValidEmail(confEmailId);
	if (!isEmpty(confEmailId) && -1 != y) {
		errorMsgs[errorIndex] = "Confirm Email Address:" + emailError[y];
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	*/
	if ((!isEmpty(confEmailId)) && (!isEmpty(emailId))) {
		if (emailId.toLowerCase() != confEmailId.toLowerCase()) {
			errorMsgs[errorIndex] = confirmEmailMistmatch;
			errorIndex = errorIndex + 1;
			errorFlag = false;
		}
	}
	var password = document.formGuruRegBaseInfo.pwd.value;
	if (isEmpty(password)) {
		errorMsgs[errorIndex] = emptyPwd;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	if (!isEmpty(password) && !isValidPwd(password)) {
		errorMsgs[errorIndex] = invalidPwd;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	var confirmPwd = document.formGuruRegBaseInfo.confPwd.value;
	if (isEmpty(confirmPwd)) {
		errorMsgs[errorIndex] = emptyConfirmPwd;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	if (!isEmpty(confirmPwd) && !isValidPwd(confirmPwd)) {
		errorMsgs[errorIndex] = invalidConfirmPwd;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	if ((!isEmpty(password) && isValidPwd(password)) && (!isEmpty(confirmPwd) && isValidPwd(confirmPwd))) {
		if (document.getElementById("pwd").value != document.getElementById("confPwd").value) {
			errorMsgs[errorIndex] = confirmPwdMistmatch;
			document.formGuruRegBaseInfo.confPwd.value = "";
			document.formGuruRegBaseInfo.pwd.value = "";
			errorIndex = errorIndex + 1;
			errorFlag = false;
		}
	}
	var day = document.getElementById("dobday").value;
	if (day == "null") {
		errorMsgs[errorIndex] = emptyBirthDay;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	var month = document.getElementById("dobmonth").value;
	if (month == "null") {
		errorMsgs[errorIndex] = emptyBirthMonth;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	var year = document.getElementById("dobyear").value;
	if (year == "null") {
		errorMsgs[errorIndex] = emptyBirthYear;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	if ("null" != day && "null" != month && "null" != year) {
		if (!isValidDate(day, month, year)) {
			errorMsgs[errorIndex] = invalidDOB;
			errorIndex = errorIndex + 1;
			errorFlag = false;
		}
	}
	//@aurthor:lokesh thakar
	//puprose: doa vs dob validation
	var doaday = document.getElementById("doaday").value;
	var doamonth = document.getElementById("doamonth").value;
	var doayear = document.getElementById("doayear").value;
	/*
	*date of anniversary is now not mandatory
	var doaday = document.getElementById("doaday").value;	
	if (doaday == "null" && document.formGuruRegBaseInfo.married[1].checked) {
		errorMsgs[errorIndex] = emptyAnniversaryDay;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	var doamonth = document.getElementById("doamonth").value;
	if (doamonth == "null" && document.formGuruRegBaseInfo.married[1].checked) {
		errorMsgs[errorIndex] = emptyAnniversaryMonth;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	var doayear = document.getElementById("doayear").value;
	if (doayear == "null" && document.formGuruRegBaseInfo.married[1].checked) {
		errorMsgs[errorIndex] = emptyAnniversaryYear;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}*/
	//var doaflag= false;
	if ((("null" != doaday) && ("null" != doamonth) && ("null" != doayear)) && (document.formGuruRegBaseInfo.married[1].checked)) {
		if (!isValidDate(doaday, doamonth, doayear)) {
			errorMsgs[errorIndex] = invalidDOA;
			//doaflag=true;
			errorIndex = errorIndex + 1;
			errorFlag = false;
		}
	}
	if (("null" != doaday) || ("null" != doamonth) || ("null" != doayear)) {
		if ("null" == doaday) {
			errorMsgs[errorIndex] = emptyAnniversaryDay;
			errorIndex = errorIndex + 1;
			errorFlag = false;
		}
		if ("null" == doamonth) {
			errorMsgs[errorIndex] = emptyAnniversaryMonth;
			errorIndex = errorIndex + 1;
			errorFlag = false;
		}
	}
	if (("null" != doaday) || ("null" != doamonth) || ("null" == doayear)) {
		if ("30" == doaday) {
			if ("1" == doamonth) {
				errorMsgs[errorIndex] = invalidDateMonthCombo;
				errorIndex = errorIndex + 1;
				errorFlag = false;
			}
		}
		if ("31" == doaday) {
			if ("1" == doamonth) {
				errorMsgs[errorIndex] = invalidDateMonthCombo;
				errorIndex = errorIndex + 1;
				errorFlag = false;
			}
			if ("3" == doamonth) {
				errorMsgs[errorIndex] = invalidDateMonthCombo;
				errorIndex = errorIndex + 1;
				errorFlag = false;
			}
			if ("5" == doamonth) {
				errorMsgs[errorIndex] = invalidDateMonthCombo;
				errorIndex = errorIndex + 1;
				errorFlag = false;
			}
			if ("8" == doamonth) {
				errorMsgs[errorIndex] = invalidDateMonthCombo;
				errorIndex = errorIndex + 1;
				errorFlag = false;
			}
			if ("10" == doamonth) {
				errorMsgs[errorIndex] = invalidDateMonthCombo;
				errorIndex = errorIndex + 1;
				errorFlag = false;
			}
		}
	}
	if (("null" != day) && ("null" != month) && ("null" != year)) {
		if ((doayear < year) && (("null" != doaday) && ("null" != doamonth))) {
			errorMsgs[errorIndex] = invalidDOAvsDOB;
			errorIndex = errorIndex + 1;
			errorFlag = false;
		}
	}
	var addType = document.getElementById("guru_add_type").value;
	if (addType == "null") {
		errorMsgs[errorIndex] = emptyAddressType;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	var add = document.getElementById("address").value;
	//alert(add)
	if (isEmpty(add)) {
		errorMsgs[errorIndex] = emptyAddress;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	if (add.length > 250) {
		errorMsgs[errorIndex] = addressFieldExceeds;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	var postalCd = document.getElementById("postalCode").value;
	if (isEmpty(postalCd)) {
		errorMsgs[errorIndex] = emptyPostalCode;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	var country = document.getElementById("country").value;
	if ("0" == country) {
		errorMsgs[errorIndex] = emptyCountry;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	
	
	var selectedTimezoneId;
	var selectedTimezone;
	var selectedTime;
	for (i = 0; i < document.getElementById("selTmz").options.length; i++) {
		if (document.getElementById("selTmz").options[i].selected) {
			selectedTimezone = document.getElementById("selTmz").options[i].text;
			selectedTimezoneId = document.getElementById("selTmz").options[i].value;
						
			selectedTime=selectedTimezone.substring(selectedTimezone.lastIndexOf("-")+1,selectedTimezone.length);
			}
	}
	
	document.getElementById("timezoneid").value=selectedTimezoneId;	
	document.getElementById("timezone").value = selectedTime;
	
	
	
	
	if("sel" == document.getElementById("selTmz").value)
	{
		errorMsgs[errorIndex] ="Please select your Timezone"
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	//var countryOther = document.formGuruRegBaseInfo.countryOther;
	var countryOther = document.getElementById("countryOther");
	if ("null" == country && (undefined != countryOther && isEmpty(countryOther.value))) {
		errorMsgs[errorIndex] = emptyCountryOther;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	} else {
		if (!isValidOther(countryOther.value)) {
			errorMsgs[errorIndex] = invalidCountryOther;
			errorIndex = errorIndex + 1;
			errorFlag = false;
		}
	} 
	//============================================
	var state = document.getElementById("state").value;
	if ("0" == state) {
		errorMsgs[errorIndex] = emptyState;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	//var stateOther = document.formGuruRegBaseInfo.stateOther;
	var stateOther = document.getElementById("stateOther");
	if ("null" == state && (undefined != stateOther && isEmpty(stateOther.value))) {
		errorMsgs[errorIndex] = emptyStateOther;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	} else {
		if (!isValidOther(stateOther.value)) {
			errorMsgs[errorIndex] = invalidStateOther;
			errorIndex = errorIndex + 1;
			errorFlag = false;
		}
	} 
	//================================================
	var city = document.getElementById("city").value;
	if ("0" == city) {
		errorMsgs[errorIndex] = emptyCity;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	//var cityOther = document.formGuruRegBaseInfo.cityOther;
	var cityOther = document.getElementById("cityOther");
	if ("null" == city && (undefined != cityOther && isEmpty(cityOther.value))) {
		errorMsgs[errorIndex] = emptyCityOther;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	} else {
		if (!isValidOther(cityOther.value)) {
			errorMsgs[errorIndex] = invalidCityOther;
			errorIndex = errorIndex + 1;
			errorFlag = false;
		}
	} 
	//======================================================

//CONTACT ONE  VALIDATIONS
	var phone1 = document.formGuruRegBaseInfo.phone1.value;
	var tel1type = document.formGuruRegBaseInfo.tel1Type.value;
	var isdid1 = document.formGuruRegBaseInfo.isdCode1.value;
	var std1 = document.formGuruRegBaseInfo.stdCode1.value;
	if (!isEmpty(phone1)) {
		if (isEmpty(isdid1)) {
			errorMsgs[errorIndex] = emptyISD1;
			errorIndex = errorIndex + 1;
			errorFlag = false;
		}
		if (!isEmpty(isdid1) && !isValidISD(isdid1)) {
			errorMsgs[errorIndex] = invalidISD1;
			errorIndex = errorIndex + 1;
			errorFlag = false;
		}
		/*
		if (isEmpty(std1) && tel1type!='Mobile') {
			errorMsgs[errorIndex] = emptySTD1;
			errorIndex = errorIndex + 1;
			errorFlag = false;
		}
		*/
		if (!isEmpty(std1) && !isValidSTD(std1)) {
			errorMsgs[errorIndex] = invalidSTD1;
			errorIndex = errorIndex + 1;
			errorFlag = false;
		}
		if (("Home" == tel1type || "Office" == tel1type) && !isValidGPhone(phone1)) {
			errorMsgs[errorIndex] = invalidConNumber1;
			errorIndex = errorIndex + 1;
			errorFlag = false;
		}
		if (("Mobile" == tel1type) && !isValidMobile(phone1)) {
			errorMsgs[errorIndex] = "Primary Contact Number: " + invalidMobileNumber;
			errorIndex = errorIndex + 1;
			errorFlag = false;
		}
	}
	var tel2type = document.formGuruRegBaseInfo.tel2Type.value;
	var phone2 = document.formGuruRegBaseInfo.phone2.value;
	var isdid2 = document.formGuruRegBaseInfo.isdCode2.value;
	var std2 = document.formGuruRegBaseInfo.stdCode2.value;
	if (!isEmpty(phone2)) {
		if (isEmpty(isdid2)) {
			errorMsgs[errorIndex] = emptyISD2;
			errorIndex = errorIndex + 1;
			errorFlag = false;
		}
		if (!isEmpty(isdid2) && !isValidISD(isdid2)) {
			errorMsgs[errorIndex] = invalidISD2;
			errorIndex = errorIndex + 1;
			errorFlag = false;
		}
	
//	var std2 = document.formGuruRegBaseInfo.sdtCode2; 
		/*
		if (isEmpty(std2) && document.formGuruRegBaseInfo.tel2Type !='Mobile') {
			errorMsgs[errorIndex] = emptySTD2;
			errorIndex = errorIndex + 1;
			errorFlag = false;
		}
		*/
		if (!isEmpty(std2) && !isValidSTD(std2)) {
			errorMsgs[errorIndex] = invalidSTD2;
			errorIndex = errorIndex + 1;
			errorFlag = false;
		}
		if (("Home" == tel2type || "Office" == tel2type || "Hand" == tel2type) && !isValidGPhone(phone2)) {
			errorMsgs[errorIndex] = invalidConNumber2;
			errorIndex = errorIndex + 1;
			errorFlag = false;
		}
		if (("Mobile" == tel2type) && !isValidMobile(phone2)) {
			errorMsgs[errorIndex] = "Alternate Contact Number: " + invalidMobileNumber;
			errorIndex = errorIndex + 1;
			errorFlag = false;
		}
	}
	if (isEmpty(phone1) && isEmpty(phone2)) {
		errorMsgs[errorIndex] = emptyConNumbers;
		errorIndex = errorIndex + 1;
		errorFlag = false;
	}
	if (errorFlag) {
		var emailValue = document.formGuruRegBaseInfo.emailId.value;
		checkIfEmailExisting(emailValue);
	} else {
		document.getElementById("errorPanel").style.display = "block";
		document.getElementById("errorPanel").focus();
		var errorMsg = "";
		for (var i = 0; i < errorIndex; i++) {
			errorMsg = errorMsg + errorMsgs[i] + "<br />";
		}
		document.getElementById("errorPanel").innerHTML = errorMsg;
		document.getElementById("errorPanel").setAttribute("class", "error");
		return;
	}
}
//=========================Changes Made By: Lokesh Thakar=============================//
//=============Purpose: To introduce proper Navigation In Contacttype1 and contactType2==================//
function contactValidation1() {
	var contactType1 = document.formGuruRegBaseInfo.tel1Type.value;
	var temp1STD = document.formGuruRegBaseInfo.hiddenSTD1.value;
	//alert(temp1STD);
	if (contactType1 == "Mobile") {
		temp1STD = document.formGuruRegBaseInfo.stdCode1.value;
		document.formGuruRegBaseInfo.stdCode1.value = "";
		document.formGuruRegBaseInfo.stdCode1.disabled = true;
	} else {
		document.formGuruRegBaseInfo.stdCode1.disabled = false;
		document.formGuruRegBaseInfo.stdCode1.value = temp1STD;
	}
}
function contactValidation2() {
	var contactType2 = document.formGuruRegBaseInfo.tel2Type.value;
	var temp2STD = document.formGuruRegBaseInfo.hiddenSTD2.value;
	//alert(temp2STD);
	if (contactType2 == "Mobile") {
		temp2STD = document.formGuruRegBaseInfo.stdCode2.valuel;
		document.formGuruRegBaseInfo.stdCode2.value = "";
		document.formGuruRegBaseInfo.stdCode2.disabled = true;
	} else {
		document.formGuruRegBaseInfo.stdCode2.disabled = false;
		document.formGuruRegBaseInfo.stdCode2.value = temp2STD;
	}
}
function updateSTD1() {
	//alert('hello')
	temp1Std = document.formGuruRegBaseInfo.stdCode1.value;
}
function updateSTD2() {
	temp2Std = document.formGuruRegBaseInfo.stdCode2.value;
}

//Changes By:Lokesh Thakar 18/07/2008//
///Purpose: To validate Date of Anniversary according to the martial status Selected//
function enableDisableDoa() {
	//for(var i=0;i<2;i++){
		//if(married) then retrieve the values from session
	if (document.formGuruRegBaseInfo.married[1].checked) {
		document.formGuruRegBaseInfo.doaday.disabled = false;
		document.formGuruRegBaseInfo.doamonth.disabled = false;
		document.formGuruRegBaseInfo.doayear.disabled = false;
	} 
		//if(single) then clear all value and store in a hidden varriable
	if (document.formGuruRegBaseInfo.married[0].checked) {
		document.formGuruRegBaseInfo.doaday.disabled = true;
		document.formGuruRegBaseInfo.doamonth.disabled = true;
		document.formGuruRegBaseInfo.doayear.disabled = true;
		document.formGuruRegBaseInfo.doaday.value = "null";
		document.formGuruRegBaseInfo.doayear.value = "null";
		document.formGuruRegBaseInfo.doamonth.value = "null";
	}
	//}
}
/*=======
//Changes By:Lokesh Thakar 18/07/2008//
///Purpose: To validate Date of Anniversary according to the martial status Selected//
function enableDisableDoa(){
	for(var i=0;i<2;i++){
		if(document.formGuruRegBaseInfo.married[0].checked){
			document.formGuruRegBaseInfo.doaday.value='null';
			document.formGuruRegBaseInfo.doaday.disabled=true;
			document.formGuruRegBaseInfo.doamonth.value='null';
			document.formGuruRegBaseInfo.doamonth.disabled=true;
			document.formGuruRegBaseInfo.doayear.value='null';
			document.formGuruRegBaseInfo.doayear.disabled=true;
		}else{
			document.formGuruRegBaseInfo.doaday.disabled=false;
			document.formGuruRegBaseInfo.doamonth.disabled=false;
			document.formGuruRegBaseInfo.doayear.disabled=false;
		}
	}
}
*/
/*
var omitformtags = ["input"];
omitformtags = omitformtags.join("|");
function disableselect(e) {
	if (omitformtags.indexOf(e.target.tagName.toLowerCase()) == -1) {
		return false;
	}
}
function reEnable() {
	return true;
}
if (typeof document.onselectstart != "undefined") {
	document.onselectstart = new Function("return false");
} else {
	document.onmouseover = enableselect;
	document.onmousedown = disableselect;
	document.onmouseup = reEnable;
}
var omitformtags = ["input"];
omitformtags = omitformtags.join("|");
function disableselect(e) {
	if (omitformtags.indexOf(e.target.tagName.toLowerCase()) == -1) {
		return false;
	}
}
function reEnable() {
	return true;
}
if (typeof document.onselectstart != "undefined") {
	document.onselectstart = new Function("return false");
} else {
	document.onmouseover = enableselect;
	document.onmousedown = disableselect;
	document.onmouseup = reEnable;
}
*/
function checkIfEmailExisting(email) {
	xmlHttp = getXMLHttpRequest();
	var queryString = "op=chkForDupEmail&emailId=" + encodeURI(email);
	xmlHttp.open("POST", url, false);
	/*xmlHttp.onreadystatechange = function () {
		handleStateForCountry(selectedCountry, selectedState, selectedCity, selectedSchool);
	};*/
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.send(queryString);
//}
//function handleStateForCountry(selectedCountry, selectedState, selectedCity, selectedSchool) {
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			parseResultsForisExistingEmail();
		}
	}
}
function parseResultsForisExistingEmail() {
	var isExisting = xmlHttp.responseXML.getElementsByTagName("isExisting")[0].firstChild.data;
	if ("true" != isExisting) {
		var length = document.getElementById("country").options.length;
		for (i = 0; i < length; i++) {
			if (document.getElementById("country").options[i].selected) {
				document.getElementById("hiddenCountryValue").value = document.getElementById("country").options[i].text;
			}
		}
		var length = document.getElementById("state").options.length;
		for (i = 0; i < length; i++) {
			if (document.getElementById("state").options[i].selected) {
				document.getElementById("hiddenStateValue").value = document.getElementById("state").options[i].text;
			}
		}
		document.formGuruRegBaseInfo.action = "guruRegistrationStepTwo.do";
		document.formGuruRegBaseInfo.submit();
	} else {
		document.getElementById("errorPanel").style.display = "block";
		document.getElementById("errorPanel").focus();
		document.getElementById("errorPanel").innerHTML = isExistingEmail;
		document.getElementById("errorPanel").setAttribute("class", "error");
		return;
	}
}
function openwindow(url) {
	window.open(url, "MyWindow", "menubar=0,resizable=1,toolbar=0,status=0,scrollbars=yes");
}
function setSTD(std2, tel2type, std1, tel1type) {
	document.formGuruRegBaseInfo.hiddenSTD1.value = "";
	document.formGuruRegBaseInfo.hiddenSTD2.value = "";
	if (std1 != "") {
		document.formGuruRegBaseInfo.hiddenSTD1.value = std1;
	} else {
		document.formGuruRegBaseInfo.hiddenSTD1.value = std2;
	}
	if (std2 != "") {
		document.formGuruRegBaseInfo.hiddenSTD2.value = std2;
	} else {
		document.formGuruRegBaseInfo.hiddenSTD2.value = std1;
	}
	if (std2 != "" && std2 != null && tel2type != "Mobile") {
		document.getElementById("stdCode2").value = std2;
	}
	if (std1 != "" && std1 != null && tel1type != "Mobile") {
		document.getElementById("stdCode1").value = std1;
	}
}
