function validate_required(field,alerttxt) {
  with (field) {
    if (value==null||value=="") {
      if (alerttxt) {
        alert(alerttxt);
      }
      return false
    }
    else {
      return true
    }
  }
}

function validate_select(field,alerttxt) {
  with (field) {
    if (selectedIndex == 0 || value=="Select") {
      alert(alerttxt);return false
    }
    else {
      return true
    }
  }
}



function validate_email(field,alerttxt) {
  with (field) {
    if (/^\w+([\.\+-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,7})+$/.test(field.value)) {
      return true
    }
    else {
      alert(alerttxt);
      return false
    }
  }
}

function isNumeric(field, alerttxt) {
  var numericExpression = /^[0-9]+$/;
  with(field) {
    if(!value.match(numericExpression)) {
    alert(alerttxt);
    return false;
  }
    else {
        return true
    }
  }
}



function isAlpha(field, alerttxt) {
  var alphaExpression = /^[(a-z)|(A-Z)| ]+$/;
  with(field) {
    if(!value.match(alphaExpression)) {
    alert(alerttxt);
    return false;
  }
    else {
        return true
    }
  }
}

function fieldSet(obj,str) {
	if(obj.value == str) {
		obj.value = '';
	}
}

function fieldReset(obj,str) {
	if(obj.value == '') {
		obj.value = str;
	}
}

function validate_lead_form1(thisform,mail_str,name_str,contact_str,state_str,city_str) {
  with (thisform) {
  	if(email.value == mail_str)
  		email.value = '';
    if (validate_required(email,"Please specify your E-Mail Address")==false) {
      email.focus();
      return false
    }
    if (validate_email(email,"Not a valid e-mail address! Try Again")==false) {
      email.focus();
      return false
    }
  	if(name.value == name_str)
  		name.value = '';
    if (validate_required(name,"Please provide your Name")==false) {
      name.focus();
      return false
    }
    if (isAlpha(name,"Your Name should contain only alphabets!")==false) {
        name.focus();
        return false
    }
  	if(mobile.value == contact_str)
  		mobile.value = '';
    if (validate_required(mobile,"Please provide your Contact Number") == false) {
      mobile.focus();
      return false
    }
    if (isNumeric(mobile,"Please provide a valid Contact Number")==false) {
      mobile.focus();
      return false
    }
    var str = mobile.value.substring(0,3)
    if (str == '000') {
      alert( "Please provide a valid Contact Number" )
      mobile.focus();
      return false
    }
    if (mobile.value.length < 5) {
      alert("Please provide a valid Contact Number")
      mobile.focus();
      return false
    }
  	if(state.value == state_str)
  		state.value = -1;
    if (validate_select(state,"Please select your State of Residence")==false) {
      state.focus();
      return false
    }
	if(city.value == city_str)
  		city.value = -1;
    if (validate_select(city,"Please select your City of Residence")==false) {
      city.focus();
      return false
    }
/*
  	if(interest.value == interest_str)
  		interest.value = -1;
  	if (validate_select(interest,"Please select your Area of Interest")==false) {
      interest.focus();
      return false
    }
*/
    if ( check1.checked == false ) {
      alert("Please Agree to the Terms of Use to Continue")
      check1.focus();
      return false;
    }
  }
}

function validate_lead_form2(thisform,mail_str,name_str,contact_str,state_str,city_str,interest_str) {
  with (thisform) {
  	if(email.value == mail_str)
  		email.value = '';
    if (validate_required(email,"Please specify your E-Mail Address")==false) {
      email.focus();
      return false
    }
    if (validate_email(email,"Not a valid e-mail address! Try Again")==false) {
      email.focus();
      return false
    }
  	if(name.value == name_str)
  		name.value = '';
    if (validate_required(name,"Please provide your Name")==false) {
      name.focus();
      return false
    }
    if (isAlpha(name,"Your Name should contain only alphabets!")==false) {
        name.focus();
        return false
    }
  	if(mobile.value == contact_str)
  		mobile.value = '';
    if (validate_required(mobile,"Please provide your Contact Number") == false) {
      mobile.focus();
      return false
    }
    if (isNumeric(mobile,"Please provide a valid Contact Number")==false) {
      mobile.focus();
      return false
    }
    var str = mobile.value.substring(0,3)
    if (str == '000') {
      alert( "Please provide a valid Contact Number" )
      mobile.focus();
      return false
    }
    if (mobile.value.length < 5) {
      alert("Please provide a valid Contact Number")
      mobile.focus();
      return false
    }
  	if(state.value == state_str)
  		state.value = -1;
    if (validate_select(state,"Please select your State of Residence")==false) {
      state.focus();
      return false
    }
	if(city.value == city_str)
  		city.value = -1;
    if (validate_select(city,"Please select your City of Residence")==false) {
      city.focus();
      return false
    }

  	if(area_of_interest.value == interest_str)
  		area_of_interest.value = -1;
  	if (validate_select(area_of_interest,"Please select your Area of Interest")==false) {
      area_of_interest.focus();
      return false
    }

    if ( check1.checked == false ) {
      alert("Please Agree to the Terms of Use to Continue")
      check1.focus();
      return false;
    }
  }
}
function validate_lead_form2_1(thisform,mail_str,name_str,contact_str,state_str,city_str,interest_str) {
  with (thisform) {
  	if(email.value == mail_str)
  		email.value = '';
    if (validate_required(email,"Please specify your E-Mail Address")==false) {
      email.focus();
      return false
    }
    if (validate_email(email,"Not a valid e-mail address! Try Again")==false) {
      email.focus();
      return false
    }
  	if(name.value == name_str)
  		name.value = '';
    if (validate_required(name,"Please provide your Name")==false) {
      name.focus();
      return false
    }
    if (isAlpha(name,"Your Name should contain only alphabets!")==false) {
        name.focus();
        return false
    }
  	if(mobile.value == contact_str)
  		mobile.value = '';
    if (validate_required(mobile,"Please provide your Contact Number") == false) {
      mobile.focus();
      return false
    }
    if (isNumeric(mobile,"Please provide a valid Contact Number")==false) {
      mobile.focus();
      return false
    }
    var str = mobile.value.substring(0,3)
    if (str == '000') {
      alert( "Please provide a valid Contact Number" )
      mobile.focus();
      return false
    }
    if (mobile.value.length < 5) {
      alert("Please provide a valid Contact Number")
      mobile.focus();
      return false
    }
  	if(state.value == state_str)
  		state.value = -1;
    if (validate_select(state,"Please select your State of Residence")==false) {
      state.focus();
      return false
    }
	if(city.value == city_str)
  		city.value = -1;
    if (validate_select(city,"Please select your City of Residence")==false) {
      city.focus();
      return false
    }

  	if(area_of_interest.value == interest_str)
  		area_of_interest.value = -1;
  	if (validate_select(area_of_interest,"Please select your Area of Interest")==false) {
      area_of_interest.focus();
      return false
    }

    if ( check1.checked == false ) {
      alert("Please Agree to the Terms of Use to Continue")
      check1.focus();
      return false;
    }
  }
}

function validate_lead_form3(thisform,mail_str,name_str,contact_str,state_str,city_str,interest_str,country_str) {
  with (thisform) {

  	if(name.value == name_str)
  		name.value = '';
    if (validate_required(name,"Please provide your Name")==false) {
      name.focus();
      return false
    }
    if (isAlpha(name,"Your Name should contain only alphabets!")==false) {
        name.focus();
        return false
    }

	if(email.value == mail_str)
  		email.value = '';
    if (validate_required(email,"Please specify your E-Mail Address")==false) {
      email.focus();
      return false
    }
    if (validate_email(email,"Not a valid e-mail address! Try Again")==false) {
      email.focus();
      return false
    }
  	if(mobile.value == contact_str)
  		mobile.value = '';
    if (validate_required(mobile,"Please provide your Contact Number") == false) {
      mobile.focus();
      return false
    }
    if (isNumeric(mobile,"Please provide a valid Contact Number")==false) {
      mobile.focus();
      return false
    }
    var str = mobile.value.substring(0,3)
    if (str == '000') {
      alert( "Please provide a valid Contact Number" )
      mobile.focus();
      return false
    }
    if (mobile.value.length < 5) {
      alert("Please provide a valid Contact Number")
      mobile.focus();
      return false
    }
  	if(state.value == state_str)
  		state.value = -1;
    if (validate_select(state,"Please select your State of Residence")==false) {
      state.focus();
      return false
    }
	if(city.value == city_str)
  		city.value = -1;
    if (validate_select(city,"Please select your City of Residence")==false) {
      city.focus();
      return false
    }

	if(dest_country.value == country_str)
  		dest_country.value = -1;
  	if (validate_select(dest_country,"Please select your Country of Interest")==false) {
      dest_country.focus();
      return false
    }

  	if(area_of_interest.value == interest_str)
  		area_of_interest.value = -1;
  	if (validate_select(area_of_interest,"Please select your Area of Interest")==false) {
      area_of_interest.focus();
      return false
    }

    if ( check1.checked == false ) {
      alert("Please Agree to the Terms of Use to Continue")
      check1.focus();
      return false;
    }
  }
}
function validate_lead_form4(thisform,mail_str,name_str,contact_str,state_str,city_str,country_str) {
  with (thisform) {
  	if(email.value == mail_str)
  		email.value = '';
    if (validate_required(email,"Please specify your E-Mail Address")==false) {
      email.focus();
      return false
    }
    if (validate_email(email,"Not a valid e-mail address! Try Again")==false) {
      email.focus();
      return false
    }
	if(name.value == name_str)
  		name.value = '';
    if (validate_required(name,"Please provide your Name")==false) {
      name.focus();
      return false
    }
    if (isAlpha(name,"Your Name should contain only alphabets!")==false) {
        name.focus();
        return false
    }
  	if(mobile.value == contact_str)
  		mobile.value = '';
    if (validate_required(mobile,"Please provide your Contact Number") == false) {
      mobile.focus();
      return false
    }
    if (isNumeric(mobile,"Please provide a valid Contact Number")==false) {
      mobile.focus();
      return false
    }
    var str = mobile.value.substring(0,3)
    if (str == '000') {
      alert( "Please provide a valid Contact Number" )
      mobile.focus();
      return false
    }
    if (mobile.value.length < 5) {
      alert("Please provide a valid Contact Number")
      mobile.focus();
      return false
    }
  	if(state.value == state_str)
  		state.value = -1;
    if (validate_select(state,"Please select your State of Residence")==false) {
      state.focus();
      return false
    }
	if(city.value == city_str)
  		city.value = -1;
    if (validate_select(city,"Please select your City of Residence")==false) {
      city.focus();
      return false
    }

	if(dest_country.value == country_str)
  		dest_country.value = -1;
  	if (validate_select(dest_country,"Please select your Country of Interest")==false) {
      dest_country.focus();
      return false
    }

    if ( check1.checked == false ) {
      alert("Please Agree to the Terms of Use to Continue")
      check1.focus();
      return false;
    }
  }
}

function validate_lead_form5(thisform,mail_str,name_str,contact_str,state_str,city_str,interest_str) {
  with (thisform) {

  	if(name.value == name_str)
  		name.value = '';
    if (validate_required(name,"Please provide your Name")==false) {
      name.focus();
      return false
    }
    if (isAlpha(name,"Your Name should contain only alphabets!")==false) {
        name.focus();
        return false
    }

	if(email.value == mail_str)
  		email.value = '';
    if (validate_required(email,"Please specify your E-Mail Address")==false) {
      email.focus();
      return false
    }
    if (validate_email(email,"Not a valid e-mail address! Try Again")==false) {
      email.focus();
      return false
    }
  	if(mobile.value == contact_str)
  		mobile.value = '';
    if (validate_required(mobile,"Please provide your Contact Number") == false) {
      mobile.focus();
      return false
    }
    if (isNumeric(mobile,"Please provide a valid Contact Number")==false) {
      mobile.focus();
      return false
    }
    var str = mobile.value.substring(0,3)
    if (str == '000') {
      alert( "Please provide a valid Contact Number" )
      mobile.focus();
      return false
    }
    if (mobile.value.length < 5) {
      alert("Please provide a valid Contact Number")
      mobile.focus();
      return false
    }
  	if(state.value == state_str)
  		state.value = -1;
    if (validate_select(state,"Please select your State of Residence")==false) {
      state.focus();
      return false
    }
	if(city.value == city_str)
  		city.value = -1;
    if (validate_select(city,"Please select your City of Residence")==false) {
      city.focus();
      return false
    }

  	if(area_of_interest.value == interest_str)
  		area_of_interest.value = -1;
  	if (validate_select(area_of_interest,"Please select your Area of Interest")==false) {
      area_of_interest.focus();
      return false
    }

    if ( check1.checked == false ) {
      alert("Please Agree to the Terms of Use to Continue")
      check1.focus();
      return false;
    }
  }
}

function validate_lead_formAAU(thisform,mail_str,name_str,contact_str,address_str,state_str,city_str,interest_str) {
  with (thisform) {
  	if(email.value == mail_str)
  		email.value = '';
    if (validate_required(email,"Please specify your E-Mail Address")==false) {
      email.focus();
      return false
    }
    if (validate_email(email,"Not a valid e-mail address! Try Again")==false) {
      email.focus();
      return false
    }
  	if(name.value == name_str)
  		name.value = '';
    if (validate_required(name,"Please provide your Name")==false) {
      name.focus();
      return false
    }
    if (isAlpha(name,"Your Name should contain only alphabets!")==false) {
        name.focus();
        return false
    }
  	if(mobile.value == contact_str)
  		mobile.value = '';
    if (validate_required(mobile,"Please provide your Contact Number") == false) {
      mobile.focus();
      return false
    }
    if (isNumeric(mobile,"Please provide a valid Contact Number")==false) {
      mobile.focus();
      return false
    }
    var str = mobile.value.substring(0,3)
    if (str == '000') {
      alert( "Please provide a valid Contact Number" )
      mobile.focus();
      return false
    }
    if (mobile.value.length < 5) {
      alert("Please provide a valid Contact Number")
      mobile.focus();
      return false
    }
	if(address.value == address_str)
  		address.value = '';
    if (validate_required(address,"Please provide your Postal Address")==false) {
      address.focus();
      return false
    }
  	if(state.value == state_str)
  		state.value = -1;
    if (validate_select(state,"Please select your State of Residence")==false) {
      state.focus();
      return false
    }
	if(city.value == city_str)
  		city.value = -1;
    if (validate_select(city,"Please select your City of Residence")==false) {
      city.focus();
      return false
    }

  	if(area_of_interest.value == interest_str)
  		area_of_interest.value = -1;
  	if (validate_select(area_of_interest,"Please select your Area of Interest")==false) {
      area_of_interest.focus();
      return false
    }

    if ( check1.checked == false ) {
      alert("Please Agree to the Terms of Use to Continue")
      check1.focus();
      return false;
    }
  }
}

function validate_lead_form6(thisform,mail_str,name_str,contact_str,address_str,state_str,city_str,interest_str) {
  with (thisform) {
  	if(email.value == mail_str)
  		email.value = '';
    if (validate_required(email,"Please specify your E-Mail Address")==false) {
      email.focus();
      return false
    }
    if (validate_email(email,"Not a valid e-mail address! Try Again")==false) {
      email.focus();
      return false
    }
  	if(name.value == name_str)
  		name.value = '';
    if (validate_required(name,"Please provide your Name")==false) {
      name.focus();
      return false
    }
    if (isAlpha(name,"Your Name should contain only alphabets!")==false) {
        name.focus();
        return false
    }
  	if(mobile.value == contact_str)
  		mobile.value = '';
    if (validate_required(mobile,"Please provide your Contact Number") == false) {
      mobile.focus();
      return false
    }
    if (isNumeric(mobile,"Please provide a valid Contact Number")==false) {
      mobile.focus();
      return false
    }
    var str = mobile.value.substring(0,3)
    if (str == '000') {
      alert( "Please provide a valid Contact Number" )
      mobile.focus();
      return false
    }
    if (mobile.value.length < 5) {
      alert("Please provide a valid Contact Number")
      mobile.focus();
      return false
    }
	if(address.value == address_str)
  		address.value = '';
    if (validate_required(address,"Please provide your Postal Address")==false) {
      address.focus();
      return false
    }
  	if(state.value == state_str)
  		state.value = -1;
    if (validate_select(state,"Please select your State of Residence")==false) {
      state.focus();
      return false
    }
	if(city.value == city_str)
  		city.value = -1;
    if (validate_select(city,"Please select your City of Residence")==false) {
      city.focus();
      return false
    }

  	if(area_of_interest.value == interest_str)
  		area_of_interest.value = -1;
  	if (validate_select(area_of_interest,"Please select your Area of Interest")==false) {
      area_of_interest.focus();
      return false
    }

    if ( check1.checked == false ) {
      alert("Please Agree to the Terms of Use to Continue")
      check1.focus();
      return false;
    }
  }
}


function nullOptions(aMenu){
aMenu.options.length=0;
}
/* ####################### change Cities ####################### */
function changeCities(){
aMenu=document.contactUsForm.state;
aMenu1=document.contactUsForm.city;
with  (aMenu){
switch (selectedIndex) {
case 0:
aMenu1.options.length=0;
aMenu1.options[0]=
new Option("City *","none")
aMenu1.options[0].selected=true;
history.go(0)
break
case 1:
getCity1(aMenu1)
break
case 2:
getCity2(aMenu1)
break
case 3:
getCity3(aMenu1)
break
case 4:
getCity4(aMenu1)
break
case 5:
getCity5(aMenu1)
break
case 6:
getCity6(aMenu1)
break
case 7:
getCity7(aMenu1)
break
case 8:
getCity8(aMenu1)
break
case 9:
getCity9(aMenu1)
break
case 10:
getCity10(aMenu1)
break
case 11:
getCity11(aMenu1)
break
case 12:
getCity12(aMenu1)
break
case 13:
getCity13(aMenu1)
break
case 14:
getCity14(aMenu1)
break
case 15:
getCity15(aMenu1)
break
case 16:
getCity16(aMenu1)
break
case 17:
getCity17(aMenu1)
break
case 18:
getCity18(aMenu1)
break
case 19:
getCity19(aMenu1)
break
case 20:
getCity20(aMenu1)
break
case 21:
getCity21(aMenu1)
break
case 22:
getCity22(aMenu1)
break
case 23:
getCity23(aMenu1)
break
case 24:
getCity24(aMenu1)
break
case 25:
getCity25(aMenu1)
break
case 26:
getCity26(aMenu1)
break
case 27:
getCity27(aMenu1)
break
case 28:
getCity28(aMenu1)
break
case 29:
getCity29(aMenu1)
break
case 30:
getCity30(aMenu1)
break
}
}
}

/* ####################### change Cities ####################### */
function changeCitiesDGM(){
aMenu=document.contactUsForm.state;
aMenu1=document.contactUsForm.city;
with  (aMenu){
switch (selectedIndex) {
case 0:
aMenu1.options.length=0;
aMenu1.options[0]=
new Option("City *","none")
aMenu1.options[0].selected=true;
history.go(0)
break
case 1:
getCity1(aMenu1)
break
case 2:
getCity5(aMenu1)
break
case 3:
getCity8(aMenu1)
break
case 4:
getCity9(aMenu1)
break
case 5:
getCity13(aMenu1)
break
case 6:
getCity14(aMenu1)
break
case 7:
getCity16(aMenu1)
break
case 8:
getCity21(aMenu1)
break
case 9:
getCity23(aMenu1)
break
case 10:
getCity26(aMenu1)
break
}
}
}

/* ####################### change Cities name wise ####################### done by SV */
function changeCitiesNMS(){
aMenu=document.contactUsForm.state;
aMenu1=document.contactUsForm.city;
with  (aMenu){
switch (document.contactUsForm.state.value) {
case "State *":
aMenu1.options.length=0;
aMenu1.options[0]=
new Option("City *","none")
aMenu1.options[0].selected=true;
history.go(0)
break
case "Andhra Pradesh":
getCity1(aMenu1)
break
case "Chandigarh":
getCity5(aMenu1)
break
case "Gujarat":
getCity8(aMenu1)
break
case "Karnataka":
getCity13(aMenu1)
break
case "Kerala":
getCity14(aMenu1)
break
case "New Delhi":
getCity21(aMenu1)
break
case "Tamil Nadu":
getCity26(aMenu1)
break
}
}
}



function getCity1(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Anantapur","Anantapur");
options[2]=new Option("Andhra Pradesh- Other","");
options[3]=new Option("Guntakal","Guntakal");
options[4]=new Option("Guntur","Guntur");
options[5]=new Option("Hyderabad","Hyderabad");
options[6]=new Option("Kakinada","Kakinada");
options[7]=new Option("Kurnool","Kurnool");
options[8]=new Option("Nellore","Nellore");
options[9]=new Option("Nizamabad","Nizamabad");
options[10]=new Option("Rajahmundry","Rajahmundry");
options[11]=new Option("Tirupati","Tirupati");
options[12]=new Option("Vijayawada","Vijayawada");
options[13]=new Option("Visakhapatnam","Visakhapatnam");
options[14]=new Option("Warangal","Warangal");
}
}

function getCity2(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Arunachal Pradesh- Other","Arunachal Pradesh- Other");
options[2]=new Option("Itanagar","Itanagar");
}
}
function getCity3(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Assam - Other","Assam - Other");
options[2]=new Option("Guwahati","Guwahati");
options[3]=new Option("Silchar","Silchar");
}
}
function getCity4(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Bahgalpur","Bahgalpur");
options[2]=new Option("Bihar- Other","Bihar- Other");
options[3]=new Option("Patna","Patna");
}
}
function getCity5(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Chandigarh","Chandigarh");
}
}
function getCity6(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Bhillai","Bhillai");
options[2]=new Option("Bilaspur","Bilaspur");
options[3]=new Option("Chhattisgarh- Other","Chhattisgarh- Other");
options[4]=new Option("Raipur","Raipur");
}
}
function getCity7(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Goa - Other","Goa - Other");
options[2]=new Option("Panaji","Panaji");
options[3]=new Option("Vasco Da Gama","Vasco Da Gama");
}
}
function getCity8(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Ahmedabad","Ahmedabad");
options[2]=new Option("Anand","Anand");
options[3]=new Option("Ankleshwar","Ankleshwar");
options[4]=new Option("Bharuch","Bharuch");
options[5]=new Option("Bhavnagar","Bhavnagar");
options[6]=new Option("Bhuj","Bhuj");
options[7]=new Option("Gandhinagar","Gandhinagar");
options[8]=new Option("Gir","Gir");
options[9]=new Option("Gujrat- Other","Gujrat- Other");
options[10]=new Option("Jamnagar","Jamnagar");
options[11]=new Option("Kandla","Kandla");
options[12]=new Option("Porbandar","Porbandar");
options[13]=new Option("Rajkot","Rajkot");
options[14]=new Option("Surat","Surat");
options[15]=new Option("Vadodara","Vadodara");
options[16]=new Option("Valsad","Valsad");
options[17]=new Option("Vapi","Vapi");
}
}
function getCity9(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Ambala","Ambala");
options[2]=new Option("Chandigarh","Chandigarh");
options[3]=new Option("Faridabad","Faridabad");
options[4]=new Option("Gurgaon","Gurgaon");
options[5]=new Option("Haryana - Other","Haryana - Other");
options[6]=new Option("Hisar","Hisar");
options[7]=new Option("Karnal","Karnal");
options[8]=new Option("Kurukshetra","Kurukshetra");
options[9]=new Option("Panipat","Panipat");
options[10]=new Option("Rohtak","Rohtak");
}
}
function getCity10(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Dalhousie","Dalhousie");
options[2]=new Option("Dharmasala","Dharmasala");
options[3]=new Option("Himachal pradesh- Other","Himachal pradesh- Other");
options[4]=new Option("Kulu/Manali","Kulu/Manali");
options[5]=new Option("Shimla","Shimla");
}
}
function getCity11(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Jammu","Jammu");
options[2]=new Option("Jammu and kashmir- Other","Jammu and kashmir- Other");
options[3]=new Option("Srinagar","Srinagar");
}
}
function getCity12(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Bokaro","Bokaro");
options[2]=new Option("Dhanbad","Dhanbad");
options[3]=new Option("Jamshedpur","Jamshedpur");
options[4]=new Option("Jharkhand- Other","Jharkhand- Other");
options[5]=new Option("Ranchi","Ranchi");
}
}
function getCity13(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Bangalore","Bangalore");
options[2]=new Option("Belgaum","Belgaum");
options[3]=new Option("Bellary","Bellary");
options[4]=new Option("Bidar","Bidar");
options[5]=new Option("Dharwad","Dharwad");
options[6]=new Option("Gulbarga","Gulbarga");
options[7]=new Option("Hubli","Hubli");
options[8]=new Option("Karnataka- Other","Karnataka- Other");
options[9]=new Option("Kolar","Kolar");
options[10]=new Option("Mangalore","Mangalore");
options[11]=new Option("Mysore","Mysore");
}
}
function getCity14(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Calicut","Calicut");
options[2]=new Option("Cochin","Cochin");
options[3]=new Option("Ernakulam","Ernakulam");
options[4]=new Option("Kannur","Kannur");
options[5]=new Option("Kerala- Other","Kerala- Other");
options[6]=new Option("Kochi","Kochi");
options[7]=new Option("Kollam","Kollam");
options[8]=new Option("Kottayam","Kottayam");
options[9]=new Option("Kozhikode","Kozhikode");
options[10]=new Option("Palakkad","Palakkad");
options[11]=new Option("Palghat","Palghat");
options[12]=new Option("Thrissur","Thrissur");
options[13]=new Option("Trivandrum","Trivandrum");
}
}
function getCity15(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Bhopal","Bhopal");
options[2]=new Option("Gwalior","Gwalior");
options[3]=new Option("Indore","Indore");
options[4]=new Option("Jabalpur","Jabalpur");
options[5]=new Option("M.P.- Other","M.P.- Other");
options[6]=new Option("Ujjain","Ujjain");
}
}
function getCity16(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Ahmednagar","Ahmednagar");
options[2]=new Option("Aurangabad","Aurangabad");
options[3]=new Option("Jalgaon","Jalgaon");
options[4]=new Option("Kolhapur","Kolhapur");
options[5]=new Option("Maharashtra- Other","Maharashtra- Other");
options[6]=new Option("Mumbai","Mumbai");
options[7]=new Option("Mumbai Suburbs","Mumbai Suburbs");
options[8]=new Option("Nagpur","Nagpur");
options[9]=new Option("Nasik","Nasik");
options[10]=new Option("Navi Mumbai","Navi Mumbai");
options[11]=new Option("Pune","Pune");
options[12]=new Option("Sholapur","Sholapur");
}
}
function getCity17(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Imphal","Imphal");
options[2]=new Option("Manipur- Other","Manipur- Other");
}
}
function getCity18(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Meghalaya- Other","Meghalaya- Other");
options[2]=new Option("Shillong","Shillong");
}
}
function getCity19(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Aizawal","Aizawal");
options[2]=new Option("Mizoram- Other","Mizoram- Other");
}
}
function getCity20(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Dimapur","Dimapur");
options[2]=new Option("Nagaland- Other","Nagaland- Other");
}
}
function getCity21(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("New Delhi","New Delhi");
}
}
function getCity22(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Bhubaneshwar","Bhubaneshwar");
options[2]=new Option("Cuttack","Cuttack");
options[3]=new Option("Orissa- Other","Orissa- Other");
options[4]=new Option("Paradeep","Paradeep");
options[5]=new Option("Puri","Puri");
options[6]=new Option("Rourkela","Rourkela");
}
}
function getCity23(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Amritsar","Amritsar");
options[2]=new Option("Bathinda","Bathinda");
options[3]=new Option("Chandigarh","Chandigarh");
options[4]=new Option("Jalandhar","Jalandhar");
options[5]=new Option("Ludhiana","Ludhiana");
options[6]=new Option("Mohali","Mohali");
options[7]=new Option("Pathankot","Pathankot");
options[8]=new Option("Patiala","Patiala");
options[9]=new Option("Punjab-Other","Punjab-Other");
}
}
function getCity24(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Ajmer","Ajmer");
options[2]=new Option("Jaipur","Jaipur");
options[3]=new Option("Jaisalmer","Jaisalmer");
options[4]=new Option("Jodhpur","Jodhpur");
options[5]=new Option("Kota","Kota");
options[6]=new Option("Rajasthan- Other","Rajasthan- Other");
options[7]=new Option("Udaipur","Udaipur");
}
}
function getCity25(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Gangtok","Gangtok");
options[2]=new Option("Sikkim- Other","Sikkim- Other");
}
}
function getCity26(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Chennai","Chennai");
options[2]=new Option("Coimbatore","Coimbatore");
options[3]=new Option("Cuddalore","Cuddalore");
options[4]=new Option("Erode","Erode");
options[5]=new Option("Hosur","Hosur");
options[6]=new Option("Madurai","Madurai");
options[7]=new Option("Nagercoil","Nagercoil");
options[8]=new Option("Ooty","Ooty");
options[9]=new Option("Salem","Salem");
options[10]=new Option("T.N.- Other","T.N.- Other");
options[11]=new Option("Thanjavur","Thanjavur");
options[12]=new Option("Tirunalveli","Tirunalveli");
options[13]=new Option("Trichy","Trichy");
options[14]=new Option("Tuticorin","Tuticorin");
options[15]=new Option("Vellore","Vellore");
}
}
function getCity27(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Agartala","Agartala");
options[2]=new Option("Tripura- Other","Tripura- Other");
}
}
function getCity28(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Agra","Agra");
options[2]=new Option("Aligarh","Aligarh");
options[3]=new Option("Allahabad","Allahabad");
options[4]=new Option("Bareilly","Bareilly");
options[5]=new Option("Faizabad","Faizabad");
options[6]=new Option("Ghaziabad","Ghaziabad");
options[7]=new Option("Gorakhpur","Gorakhpur");
options[8]=new Option("Kanpur","Kanpur");
options[9]=new Option("Lucknow","Lucknow");
options[10]=new Option("Mathura","Mathura");
options[11]=new Option("Meerut","Meerut");
options[12]=new Option("Moradabad","Moradabad");
options[13]=new Option("Noida","Noida");
options[14]=new Option("Saharanpur","Saharanpur");
options[15]=new Option("U.P.- Other","U.P.- Other");
options[16]=new Option("Varanasi","Varanasi");
}
}
function getCity29(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Dehradun","Dehradun");
options[2]=new Option("Roorkee","Roorkee");
options[3]=new Option("Uttaranchal- Other","Uttaranchal- Other");
}
}
function getCity30(aMenu){
//Software
nullOptions(aMenu);
with (aMenu){

//Rewrites the text and values
options[0]=new Option("City *","none");
options[1]=new Option("Asansol","Asansol");
options[2]=new Option("Durgapur","Durgapur");
options[3]=new Option("Haldia","Haldia");
options[4]=new Option("Kharagpur","Kharagpur");
options[5]=new Option("Kolkata","Kolkata");
options[6]=new Option("Siliguri","Siliguri");
options[7]=new Option("West Bengal- Other","West Bengal- Other");
}
}

function validate_lead_form_airhost(thisform,mail_str,name_str,contact_str,state_str,city_str) {
  with (thisform) {
  	if(email.value == mail_str)
  		email.value = '';
    if (validate_required(email,"Please specify your E-Mail Address")==false) {
      email.focus();
      return false
    }
    if (validate_email(email,"Not a valid e-mail address! Try Again")==false) {
      email.focus();
      return false
    }
  	if(name.value == name_str)
  		name.value = '';
    if (validate_required(name,"Please provide your Name")==false) {
      name.focus();
      return false
    }
    if (isAlpha(name,"Your Name should contain only alphabets!")==false) {
        name.focus();
        return false
    }
  	if(mobile.value == contact_str)
  		mobile.value = '';
    if (validate_required(mobile,"Please provide your Contact Number") == false) {
      mobile.focus();
      return false
    }
    if (isNumeric(mobile,"Please provide a valid Contact Number")==false) {
      mobile.focus();
      return false
    }
    var str = mobile.value.substring(0,3)
    if (str == '000') {
      alert( "Please provide a valid Contact Number" )
      mobile.focus();
      return false
    }
    if (mobile.value.length < 5) {
      alert("Please provide a valid Contact Number")
      mobile.focus();
      return false
    }
  	if(state.value == state_str)
  		state.value = -1;
    if (validate_select(state,"Please select your State of Residence")==false) {
      state.focus();
      return false
    }
	if(city.value == city_str)
  		city.value = -1;
    if (validate_select(city,"Please select your City of Residence")==false) {
      city.focus();
      return false
    }
/*
  	if(interest.value == interest_str)
  		interest.value = -1;
  	if (validate_select(interest,"Please select your Area of Interest")==false) {
      interest.focus();
      return false
    }
*/
    if ( check1.checked == false ) {
      alert("Please Agree to the Terms of Use to Continue")
      check1.focus();
      return false;
    }
  }
}

function readSeesionCookie() {
  var name = 'PHPSESSID';
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function isPhpSessionOpen() {
    var sessionId = readSeesionCookie();
    if(sessionId==null || sessionId == '') {
      return false;
    }
    return true;
}

/**
 * Creates an HTTP GET request and sends the response to the callback function
 */
function HTTPGet(uri, callbackFunction, callbackParameter) {
  var xmlHttp = new XMLHttpRequest();
  var bAsync = true;
  if (!callbackFunction)
    bAsync = false;
  if(!isPhpSessionOpen())
    bAsync = false;
  xmlHttp.open('GET', uri, bAsync);
  xmlHttp.send(null);
  if (bAsync) {
    if (callbackFunction) {
      xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4){
            callbackFunction(xmlHttp.responseText, xmlHttp, callbackParameter);
        }
        }
    }
    return true;
  }
  else {
    if (callbackFunction) {
      callbackFunction(xmlHttp.responseText, xmlHttp, callbackParameter);
      return true;
    }    
    return xmlHttp.responseText;
  }
}

/**
 * Creates an HTTP POST request and sends the response to the callback function
 */
function HTTPPost(uri, object, callback_function, callback_parameter) {
  var xmlhttp = new XMLHttpRequest();
  var bAsync = true;
  if (!callback_function)
    bAsync = false;
  if(!isPhpSessionOpen())
    bAsync = false;    
  xmlhttp.open('POST', uri, bAsync);
  xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  var form_contents = '';
  for (var i in object)
    form_contents += (form_contents ? '&' : '') + i + '=' + escape(object[i]);
  xmlhttp.send(form_contents);
  if (bAsync) {
    if (callback_function)
      xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4)
          callback_function(xmlhttp.responseText, xmlhttp, callback_parameter);
      }
    return true;
  }
  else
    if (callback_function) {
      callback_function(xmlhttp.responseText, xmlhttp, callback_parameter);
      return true;
    }  
    return xmlhttp.responseText;
}

function url(str) {
  if ( clean_url ) {
    return base_url + '/' + str;
  }
  else {
    return '?q=' + str;
  }
}

/**
 * Make IE's XMLHTTP object accessible through XMLHttpRequest()
 */
if (typeof XMLHttpRequest == 'undefined') {
 XMLHttpRequest = function () {
   var msxmls = ['MSXML3', 'MSXML2', 'Microsoft']
   for (var i=0; i < msxmls.length; i++) {
     try {
       return new ActiveXObject(msxmls[i]+'.XMLHTTP')
     }
     catch (e) { }
   }
   throw new Error("No XML component installed!")
 }
}

function change_state_city_list(country_id){
    HTTPGet('/get_data.php?url=sp_state_city_list&country_id='+country_id, populate_state_city_list,'');
}

function populate_state_city_list(data) {
  var arr = data.split('^')
  var len = arr.length;
  var i;
  var obj_arr = document.getElementsByName('state_city');
  for(cc=0; cc<obj_arr.length; cc++) {
    var obj = obj_arr[cc];
    
    obj.options.length = 0;
    obj.innerHTML = '';
    var oGroup = document.createElement('optgroup');
  //  var optionM2 = new Option()
  //  var oGroup;
   
    var optionM2 = new Option('State/City*')
    optionM2.value = 'none';
    obj.options[0] = optionM2;
    
    for(i=0; i<len; i++) {
      var op_value = arr[i].split('/');
      if(op_value[0] == '[group]'){
        if(i != 0){
          oGroup = document.createElement('optgroup');
        }
        oGroup.label = op_value[1];
        obj.appendChild(oGroup);
  //      var oGroup = document.createElement('optgroup');
      }else{
        if(op_value[1] != ''){
  //        var optionM2 = new Option(op_value[1])
  //        obj.options[i] = optionM2;
  //        obj.options[i].value = escape(op_value[0]);
  
  var optionM2 = document.createElement("option");
  optionM2.text = op_value[1];
  optionM2.innerHTML = op_value[1];
  optionM2.value = op_value[0];
          oGroup.appendChild(optionM2);
  
        }
      }
    }
    obj.appendChild(oGroup);
  
  //  obj.appendChild(oGroup);

  }
}

function getParamValue( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
	return "";
  else
	return results[1];
}

function state_list(thisObj,stateId) {
  HTTPGet('/get_data.php?url=register/statelist&country_id='+thisObj.value, populate_select_box,stateId);
}

function city_list(thisObj,cityId) {
  HTTPGet('/get_data.php?url=register/citylist&state_id='+thisObj.value, populate_select_box,cityId);
}

function country_list(countryId){
	HTTPGet('/get_data.php?url=get_ajax_all_countries',populate_select_box,countryId);
}

function populate_specialization(category_data) {
     if (category_data != 'none') {
		 $.getJSON("/get_ajax_subcategory_list",{category: category_data, ajax: 'true'}, function(j){
			 var options = '';
			 options += '<option value="none">Select</option>';
			 for (var i = 0; i < j.length; i++) {
			 options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
			 }
			 $("select#specialization").html(options);
		 })
	} else {
		 var options = '';
		 options += '<option value="none">Select</option>';
	     $("select#specialization").html(options);
	}
}

function populate_course(category_data,institute_data){
     if (category_data != 'none' && institute_data != '') {
		 $.getJSON("/get_ajax_course_list",{category: category_data, institute: institute_data, ajax: 'true'}, function(j){
			 var options = '';
			 options += '<option value="none">Select course*</option>';
			 for (var i = 0; i < j.length; i++) {
			 options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
			 }
			 $("select#course").html(options);
		 })
	} else {
		 var options = '';
		 options += '<option value="none">Select course*</option>';
	     $("select#course").html(options);
	}
}

function validate_intentform(thisform, submit_button_id) {
  var validation_failed = false;
  with (thisform) {
  	if(area_of_interest.value == 'none' || area_of_interest.value == 0 ) {
  	   alert("Please specify your Area of Interest.")
  	   area_of_interest.focus();
  	   validation_failed = true;
  	   return false;
  	}
  }
  if (validation_failed == false) {
	  if (document.getElementById(submit_button_id)) {
	  		document.getElementById(submit_button_id).disabled = true;
	  }
  }
  return true;
}

/* Function for State and City */
var bool_change_first_option = 0;
var elem_change_first_option = '';
var text_change_first_option = '';

function call_change_first_option(elemId, text) {
	bool_change_first_option = 1;
	elem_change_first_option = elemId;
	text_change_first_option = text;
}

function change_first_option() {
	var elem = document.getElementById(elem_change_first_option);
	if(elem) {
		elem.options[0].text = text_change_first_option;
	}
}

/* * callback for getting states/cities */ 
function populate_select_box(text, xmlObj, targetElement) {
  if(!text || text=='') {
    text = '{"-1" : "Select"}';
  }
  var dataObj = !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(text.replace(/"(\\.|[^"\\])*"/g, ''))) && eval('(' + text + ')');

  var i;
  var obj = document.getElementById(targetElement);
  obj.options.length = 0;
  i=0;
  for (var key in dataObj) {
    var optionM2 = new Option(dataObj[key]);
    obj.options[i] = optionM2;
    obj.options[i].value = key;
    i++;
  }
  var optionM2 = new Option("Other");
	obj.options[i] = optionM2;
    obj.options[i].value = "0";
  
  if(bool_change_first_option)
    change_first_option();
}

function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects 
		for(var item in arr) {
			var value = arr[item];
			
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}

/** renders course detail in a div and preselect the course in div */
/*
function render_course_detail(course,course_div,select_box_id){
	$("body").addClass("opaqueBody");
	$.getJSON("/select/ajax/populate",{input: course, ajax_key: 'course_detail'},
		function(data){
			_update_course_div(data,course_div)
			//set select option
			$("#"+select_box_id).children().each(function(i){
				if($(this).val() == data.name)
				{
					$(this).attr('selected','selected');
				}
			});
	$("body").removeClass("opaqueBody");
	});
}*/

function render_course_onload(course_name,institute_name,course_div,select_box_id){
	//$("body").addClass("opaqueBody");
	//toggleBody(0);
	if(_isempty(course_name) || _isempty(institute_name)){
		_clean_course_div();
	}else{
		$.getJSON("/select/ajax/populate",{input: course_name+","+institute_name, ajax_key: 'course_detail_by_name'},
			function(data){
			_update_course_div(data,course_div);
				//set select option
				$("#"+select_box_id).children().each(function(i){
					if($(this).val() == data.name)
					{
						$(this).attr('selected','selected');
					}
				});
		//$("body").removeClass("opaqueBody");
		//toggleBody(1);
		});
	}

}
function render_course_detail(course_name,institute_name,course_div){
	//$("body").addClass("opaqueBody");
	//toggleBody(0);
	//alert(course_name +' - '+institute_name);
	if(_isempty(course_name) || _isempty(institute_name)){
		_clean_course_div();
	}else{
    $("#"+course_div).html($('<img>').attr("src","../common/images/ajax-loader.gif"));
		$.getJSON("/select/ajax/populate",{input: course_name+","+institute_name, ajax_key: 'course_detail_by_name'},
			function(data){
			_update_course_div(data,course_div);
			//toggleBody(1);
			//$("body").removeClass("opaqueBody");
		});
	}
}
/* renders course listing for institute */
function render_course_list(institute,external_category,link_prefix,div_id){
  $("#"+div_id).html($('<img>').attr("src","../common/images/ajax-loader.gif"));
	HTTPGet('/get_ajax_course_list_by_criteria?criteria=institute_external_category&institute='
      +encodeURIComponent(institute)+'&external_category='+encodeURIComponent(external_category),function(data){
		var dataObj = !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(data.replace(/"(\\.|[^"\\])*"/g, ''))) && eval('(' + data + ')');
		//alert(dump(dataObj));
   var category_course = {};
    for (var key in dataObj){
      cat = dataObj[key]["external_category"];
      course_id = dataObj[key]["course_id"];
      var course = {};
      course["name"] = dataObj[key]["name"];
      course["course_id"] = dataObj[key]["course_id"];
      course["level"] = dataObj[key]["level"];
      
      if(!category_course[cat])
        category_course[cat] = {};
      category_course[cat][course_id] = course; 
    }
    //alert(dump(category_course));
    $("#"+div_id).empty();
    i=0;
    for(cat in category_course){
      _update_course_list_div(cat,category_course[cat],i++,link_prefix,div_id);
    }
	});
}
/* allow only alphabetical numbers */
function alphaonly(myField,e,dec)
{
  var key;
  var keychar;
  regExp = /^[A-Za-z- ]$/;

  if (window.event)
     key = window.event.keyCode;
  else if (e)
     key = e.which;
  else
    return true;
  keychar = String.fromCharCode(key);
  // control keys
  if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
     return true;
  else if (keychar.match(regExp))
  {
    return true;
  }
  return false;
}

/*numric value only*/
function numbersonly(myfield, e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;

// decimal point jump
else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return false;
   }
else
   return false;
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function setCountry(hostip){
	$.getJSON("/get_user_country", function(j){
		dump(j);
	});
}
/* ---------------- helper functions -------------------------*/
function _isempty(param){
	return (typeof param == 'undefined' || param == '' || param == 'none' || param == '-1' );
}
function _clean_course_div(course_div){
	$("#"+course_div).empty();
}
function _update_course_div(data,course_div){
	//alert(dump(data));
	$("#"+course_div).empty();
	if(data){
		if(!_isempty(data.name))
			$("#"+course_div).append($('<h2>').html(data.name));
		if(!_isempty(data.description))
			$("#"+course_div).append($('<div>').addClass("detail").html(data.description));
		if(!_isempty(data.accreditation))
			$("#"+course_div).append($('<h3>').html("Accreditation")).append($('<div>').addClass("detail").html(data.accreditation));
		if(!_isempty(data.exam_scores))
			$("#"+course_div).append($('<h3>').html("Eligibility")).append($('<div>').addClass("detail").html(data.exam_scores));
		if(!_isempty(data.scholarships))
			$("#"+course_div).append($('<h3>').html("Scholarship")).append($('<div>').addClass("detail").html(data.scholarships));
		if(!_isempty(data.admission_process))
			$("#"+course_div).append($('<h3>').html("Admission Process")).append($('<div>').addClass("detail").html(data.admission_process));
		if(!_isempty(data.duration))
			$("#"+course_div).append($('<h3>').html("Course Duration")).append($('<div>').addClass("detail").html(data.duration));
		if(!_isempty(data.fees))
			$("#"+course_div).append($('<h3>').html("Fees")).append($('<div>').addClass("detail").html(data.fees));
	}
}

function _update_course_list_div(category,courses,index,link_prefix,div_id){
  if(!_isempty(category)){
    $("#"+div_id).append($('<h2>').html(category));
    uldiv = div_id+"_ul_"+index;
    $("#"+div_id).append($('<ul>').attr("id",uldiv));
    for(var course in courses){
      if(course){
        name = courses[course]["name"];
        ahref = ($('<a>').attr("href",link_prefix+course)).html(name);
        $("#"+uldiv).append($('<li>').append(ahref));
      }
    }
  }
}

function relaySuccessURLQueryString(defaultDestination){
  var queryString = '';
  
  var fwd = getParamValue('fwd');
  if(!fwd || fwd=='') {
    var successURL = getParamValue('successURL');
    if(successURL && successURL!='') {
      queryString = decodeURIComponent(successURL);
    }    
  }
  else {
    queryString = decodeURIComponent(fwd);
  }
  
  if(defaultDestination && defaultDestination!='' && queryString=='')
    queryString = defaultDestination;
  
  if(queryString!='') {
    //queryString = 'fwd='+encodeURIComponent(queryString);
	  //addSuccessURLQueryString(queryString)
    if($("#successURLQueryString").length==0) {
      $("#lead_version_id").parent().append($('<input type="hidden" id="successURLQueryString" name="successURLQueryString" value="">'));
    }	  
	  var oldQueryString = $("#successURLQueryString").val();
	  var newQueryString = updateURLQueryStringParam(oldQueryString, 'fwd', queryString);
	  $("#successURLQueryString").val(newQueryString);
  }
  return true;
}

function redirectSuccessPage(defaultDestination){
  var fwd = getParamValue('fwd');
  if(fwd && fwd!='') {
    fwd = decodeURIComponent(fwd);
  }
  if( (!fwd || fwd=='') && (defaultDestination && defaultDestination!='')) {
    fwd = defaultDestination;  
  }
  if(fwd && fwd!='') {
    var url = fwd;
    var userId = getParamValue('userId');
    if(userId && userId!='') {
      url = url + ((url.indexOf('?')==-1)?'?':'&') + 'userId=' + userId;
    }
    var leadId = getParamValue('leadId');
    if(leadId && leadId!='') {
      url = url + ((url.indexOf('?')==-1)?'?':'&') + 'leadId=' + leadId;
    }
    //alert(url);
    window.location.replace(url);
  }
}

function addSuccessURLQueryString(queryString) {
    var oldQueryString = $("#successURLQueryString").val();
    if(!oldQueryString || oldQueryString=='') {
      $("#successURLQueryString").val(queryString);
    }
    else {
      $("#successURLQueryString").val(oldQueryString+'&'+queryString);
    }
}

function updateURLQueryStringParam(queryString, paramName, value) {
    value = encodeURIComponent(value);
    if(!queryString || queryString=='') {
      queryString =  paramName+'='+value;      
    }
    else {
  		var params = queryString.split("&");
  		var data = new Array();
  		for(var i = 0 ; i < params.length ; i++) {
  			var pairArray = params[i].split("=");
  			if(pairArray[0] == paramName) {
  				pairArray[1] = value;
  			}
  			data.push(pairArray.join("="));
  		}
  		queryString = data.join("&");
    }
    return queryString;
}

function update_url_parameter_val(url, paramName, value) {
  value = encodeURIComponent(value);
	if( (index = url.indexOf('?')) != -1 && url.indexOf(paramName+'=') != -1) {
		var queryStr = url.substring(index+1);
		var params = queryStr.split("&");
		var data = new Array();
		for(var i = 0 ; i < params.length ; i++) {
			var pairArray = params[i].split("=");
			if(pairArray[0] == paramName) {
				pairArray[1] = value;
			}
			data.push(pairArray);
		}
		url = url.substring(0,index)+'?';
		for(var i = 0 ; i < data.length ; i++) {
			if(i!=0)
				url = url+'&'+data[i][0]+'='+data[i][1];
			else
				url = url+data[i][0]+'='+data[i][1];		
		}
	}
	else {
    if( (index = url.indexOf('?')) == -1) {
      url = url+'?'+paramName+'='+value;
		}
		else {
      var queryStr = url.substring(index+1);
      url = url.substring(0,index)+'?';
      url = url+paramName+'='+value+'&'+queryStr;
		}
	}
	return url;
}

function verify_mobile_launch(defaultVal){
  var url = "/sms/verify_start";
  var opts = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=400,height=300";
  var mobile = $("#mobile").val();
  if(mobile != '' && mobile != defaultVal){
    mywin = window.open(url+"?mobile="+mobile+"&pop=true",'mywin','height=300,width=400');
    //mywin.moveTo(0,0);
    if (window.focus) {mywin.focus()}
    return false;
  }else{
    alert('Please enter a valid mobile number and click verify');
  }
}

function verify_mobile_click(){
  alert('clicked');
  //sms/verify?pop=true;
}

function verify_mobile_callback(){
  $("#mobile_status").val("1");
  $("#mobile_verification").removeClass('smsValidationOff');
  $("#mobile_verification").addClass('smsValidationOn');
  $("#mobile_unverified_text").hide();
  $("#mobile_verified_text").show();
  append_verified_mobile($("#mobile").val());
}
	
function unverify_mobile_callback(){
  $("#mobile_status").val("0");
  $("#mobile_verification").addClass('smsValidationOff');
  $("#mobile_verification").removeClass('smsValidationOn');
  $("#mobile_unverified_text").show();
  $("#mobile_verified_text").hide();
}

function append_verified_mobile(mobile) {
  if($("#verified_mobiles_list").length==0) {
    $("#mobile_verification").append($('<input type="hidden" id="verified_mobiles_list" name="verified_mobiles_list" value="">'));
  }
  var mobiles_list = $("#verified_mobiles_list").val();
  var mobiles_arr = new Array();
  if(mobiles_list != '' && mobiles_list != ',')
    mobiles_arr = mobiles_list.split(',');
  var bool = false;
  for(i=0;i<mobiles_arr.length;i++) {
    if(mobiles_arr[i] == mobile) {
      bool = true;
      break;
    }
  }
  if(!bool) {
    mobiles_arr.push(mobile);  
  }
  $("#verified_mobiles_list").val(mobiles_arr.join(','));  
}

function already_verified_mobile(mobile) {
  if(mobile!='' && $("#verified_mobiles_list").length>0) {
    var mobiles_list = $("#verified_mobiles_list").val();
    var mobiles_arr = mobiles_list.split(',');
    var bool = false;
    for(i=0;i<mobiles_arr.length;i++) {
      if(mobiles_arr[i] == mobile) {
        bool = true;
        break;
      }
    }
    if(bool) {
      return true;
    }
  }
  return false;  
}

function update_mobile_vefication_status() {
  if(already_verified_mobile($("#mobile").val())) {
    verify_mobile_callback();
  }
  else {
    unverify_mobile_callback();
  }  
}

function pref_phone_elem_clicked(elemValue) {
	if(elemValue == 'mobile') {
	  $("#mobile_status").removeAttr('disabled');
	  update_mobile_vefication_status();
	  $("#mobile_verification").show();
	}
	else {
	  $("#mobile_verification").hide();
	  $("#mobile_status").val(1);
	  $("#mobile_status").attr('disabled', 'disabled');	  
	}
}
	

if(typeof jQuery != 'undefined') {
  $(document).ready(function() {
    if( $("#mobile").length>0 && $("#mobile_status").length>0 && $("#mobile_verification").length>0 ) {

      update_mobile_vefication_status();
      $("#mobile").keyup(function() {
        if($('input[name=pref_phone]').length>0) {
          if($('input[name=pref_phone]:checked').val()=='mobile') {
            update_mobile_vefication_status();
          }
        }
        else {
          update_mobile_vefication_status();
        }        
      });
      
      if($('input[name=pref_phone]').length>0) {
		
		    pref_phone_elem_clicked($('input[name=pref_phone]:checked').val());
        $("input[name=pref_phone]").each( function(i){
            $(this).bind("click", function(){
                pref_phone_elem_clicked(this.value);
            });
        });

      }                
    }       
  });
}

/**
 * Function makes the admessage div visible in the page
 * It also sets the content from the url
 * @param elem
 * @param param
 * @return
 */
function replaceAdMessage(elem,param){
	var utm_h;
	var utm_s;
	var utm_adm;
	
	//parse query string and replace utm_adm param value to elemId
	//var params = getParameters(window.location.href);
	var params = ['utm_adm','utm_h','utm_s'];
	//var value = '';
  	for(var i in params) {
		var key = params[i];
		var value = getParamValue(key);
		if(value && value != '') {
			value = decodeURIComponent(value);
			switch(key) {
				case 'utm_adm':
					utm_adm = value;
				break;
				case 'utm_h':
					utm_h = value;
				break;
				case 'utm_s':
					utm_s = value;
				break;
			}
		}
  	}
	if($("#admessage")){
		if(utm_adm != '')
			$("#admessage").html(utm_adm);
		$("#admessage").css('visibility','visible');
	}
	if($("#utm_h")){
		if(utm_h != '')
			$("#utm_h").html(utm_h);
		$("#utm_h").css('visibility','visible');
	}
	if($("#utm_s")){
		if(utm_s != '')
			$("#utm_s").html(utm_s);
		$("#utm_s").css('visibility','visible');
	}
}

if(typeof jQuery != 'undefined') {
  $(function() {
    replaceAdMessage();
  });
}

if(typeof jQuery != 'undefined' && typeof jQuery.fn != 'undefined' && typeof jQuery.fn.pngFix != 'undefined') {
	$(document).ready(function(){
		$(document).pngFix();
	});
}
var isd = new Object();
isd["1"]="61";isd["2"]="1";isd["3"]="44";isd["4"]="91";isd["5"]="64";isd["6"]="1";isd["7"]="65";isd["9"]="353";isd["11"]="971";isd["12"]="41";isd["13"]="31";isd["15"]="673";isd["22"]="33";isd["23"]="43";isd["24"]="32";isd["25"]="86";isd["26"]="45";isd["27"]="358";isd["28"]="49";isd["29"]="852";isd["30"]="972";isd["31"]="39";isd["32"]="81";isd["33"]="60";isd["34"]="52";isd["35"]="47";isd["36"]="7";isd["37"]="82";isd["38"]="34";isd["39"]="46";isd["40"]="886";isd["41"]="66";isd["42"]="357";isd["43"]="94";isd["44"]="966";isd["45"]="964";isd["46"]="965";isd["47"]="973";isd["48"]="968";isd["49"]="974";isd["50"]="967";isd["51"]="962";isd["52"]="963";isd["53"]="961";isd["54"]="374";isd["55"]="993";isd["56"]="98";isd["57"]="92";isd["58"]="880";isd["60"]="977";isd["61"]="960";isd["62"]="975";isd["64"]="84";isd["65"]="421";isd["66"]="1";isd["67"]="1";isd["68"]="1";isd["70"]="30";isd["71"]="234";isd["72"]="351";isd["73"]="27";isd["74"]="994";isd["75"]="7";isd["76"]="996";isd["78"]="856";isd["79"]="95";isd["80"]="855";isd["81"]="992";isd["82"]="670";isd["83"]="976";isd["84"]="90";isd["85"]="62";isd["86"]="850";isd["87"]="998";isd["89"]="212";isd["90"]="230";isd["91"]="1";isd["92"]="36";isd["93"]="352";isd["94"]="995";isd["95"]="20";isd["96"]="63";

function fillCountryISDCode(country,elem_array,lock){
  if(typeof isd[country] != "undefined") {
    for(var i=0;i<elem_array.length;i++){
      _fillISDCode(elem_array[i],isd[country],lock);
    }
  }
}
function _fillISDCode(elem,code,lock){
  if($("#"+elem)){
    $("#"+elem).val(code);
    if(lock){
      $("#"+elem).attr("readonly","readonly");
    }
  }
}

function array_contains(a, obj) {
  var i = a.length;
  while (i--) {
    if (a[i] === obj) {
      return true;
    }
  }
  return false;
}
