var http_request;
var http_request1;
var advanceGiftName;
/*
	logic to call if the half filled if browser is directly closed 
	
*/
var isTab1Filled = false;


function getContactDetailstab(){

document.getElementById('tab1').style.display ="none";
document.getElementById('tab3').style.display ="none";
document.getElementById('tab2').style.display="block";
document.getElementById('tt2').focus(); //adding for the focus of the page

document.getElementById('tt1').removeClass("on");
document.getElementById('tt2').addClass("on");


}

function getBankDetailstab(){

document.getElementById('tab1').style.display ="none";
document.getElementById('tab2').style.display="none";
document.getElementById('tab3').style.display ="block";
document.getElementById('tt3').focus();  //adding for the focus of the page

document.getElementById('tt2').removeClass("on");
document.getElementById('tt3').addClass("on");

}

function testfortab()
{
//alert("testfortab");
}

//method for autopopulate stdcode
function populateStdcode(id){
	var cityName = new Array();
	var stdCodes = new Array();
	cityName[0] = "Ahmedabad";stdCodes[0] = "79";
	cityName[1] = "Bangalore";stdCodes[1] = "80";
	cityName[2] = "Chandigarh";stdCodes[2] = "172";
	cityName[3] = "Chennai";stdCodes[3] = "44";
	cityName[4] = "Delhi";stdCodes[4] = "11";
	cityName[5] = "Faridabad";stdCodes[5] = "129";
	cityName[6] = "Ghaziabad";stdCodes[6] = "120";
	cityName[7] = "Hyderabad";stdCodes[7] = "40";
	cityName[8] = "Kolkatta";stdCodes[8] = "33";
	cityName[9] = "Mumbai";stdCodes[9] = "22";
	cityName[10] = "Navi Mumbai";stdCodes[10] = "215";
	cityName[11] = "Noida";stdCodes[11] = "1185";
	cityName[12] = "Pune";stdCodes[12] = "20";
	cityName[13] = "Secundrabad";stdCodes[13] = "40";
	cityName[14] = "Thane";stdCodes[14] = "22";
	cityName[15] = "Gurgaon";stdCodes[15] = "124";
	var city= id.value;
	for(var i=0;i<cityName.length;i++){
		if(city == cityName[i]){
			if(id.id =="City1"){
				document.personal_info.stdno.value = stdCodes[i];
				document.personal_info.stdno.readOnly=true;
			}else{
				document.personal_info.Perm_stdcode.value = stdCodes[i];
				document.personal_info.Perm_stdcode.readOnly=true;				
			}
		}else if(city == "Others" || city == ""){
			if(id.id =="City1"){
				document.personal_info.stdno.value = "";
				document.personal_info.stdno.readOnly=false;
			}else{
				document.personal_info.Perm_stdcode.value = "";				
				document.personal_info.Perm_stdcode.readOnly=false;
			}
		}
	}
}
//on mouse down function 

function onMousedownRestrict(event){
				try
				{
					var message="Right Click is restricted";
					if (window.XMLHttpRequest) 
					{		
						if (event.which==2||event.which==3){
                            alert(message);
                            return false;
                         }		
					}
					else if (window.ActiveXObject) 
					{
						if (event.button==2){
                             alert(message);
                             return false;
                        }
					}
				}
				catch(Exception)
				{
					throw new Error('Error : Error while initializing ajax for application');
				}
	
}

/*
	logic to call if the half filled if window/browser is directly closed 
	
*/

function onCloseSaveExit(){
	//alert(document.personal_info.whichbuttonPress.value);
	if(document.personal_info.whichbuttonPress.value=="windowClose"){
	if (personalInfo() == false){
	    //added line for save / Exit
          /*if(exitOption()==true){
                              
              disbaleButton(); // logic to disable Button
              document.personal_info.exitAction.value="yes";
              document.personal_info.submit();        
               return false;
             } */         
               
     
		return false;
	}else{
		if(exitOptionNew()==true){
                              
              disbaleButton(); // logic to disable Button
              document.personal_info.exitAction.value="yes";
              document.personal_info.submit();        
              return false;
             }else{
             	return false;
             }
		//disbaleButton();
	}
  }
}



function getRequestObject()
      {
    
       if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }
        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        return http_request;
      }

//adding function for checking confirm
function exitOptionNew(){
	var confirmExit = window.confirm("Are you sure you want to exit?");
		if(confirmExit){
			return true;
		}else{
			return false;
		}
}
function getRequestObject1()
      {
   
       if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request1 = new XMLHttpRequest();
            if (http_request1.overrideMimeType) {
                http_request1.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request1 = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request1 = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }
        if (!http_request1) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        return http_request1;
      }


	 


 function savePersonalDetails() 
{
//alert("inside savePersonalDetails111 ");
//var cardType = document.personal_info.cardType.value;/
//var goodiesVal = document.personal_info.goodiesVal.value;
//var goodiesName = document.personal_info.goodiesName.value;

//alert("goodiesVal "+goodiesVal);
//alert("goodiesName "+goodiesName);


var FirstName= document.personal_info.FirstName.value;
var SecondName= document.personal_info.SecondName.value;
var LastName= document.personal_info.LastName.value;
var EmailId = document.personal_info.EmailId.value;
//var NameOnCard= document.personal_info.NameOnCard.value;
//var MotherName= document.personal_info.MothersName.value;
var DOB= document.personal_info.DOB.value;
var MM= document.personal_info.MM.value;
var YY= document.personal_info.YY.value;
//var MotherName= document.personal_info.MotherName.value;

//var advanceGiftVal = document.personal_info.advanceGiftVal.value; //added for advance joining gift

var genderVal= document.personal_info.gender.value;
//var MartialVal= document.personal_info.MartialVal.value;
//var Education= document.personal_info.Education.value;
//var otherEducation = "";
var PAN_Number= document.personal_info.PAN_Number.value;
//var Vehicle= document.personal_info.Vehicle.value;
var Occupation= document.personal_info.occupation.value;
//var CheckContent = document.personal_info.CheckContent.value;
///var WorkExperince = "";//
///var NumberOfDependents= document.personal_info.NumberOfDependents.value/;
//var WorkExperince= document.personal_info.WorkExperince.value;
var Mobile = document.personal_info.Mobile.value;
var Mobileno = document.personal_info.Mobileno.value;

var ResidentialStatus = document.personal_info.ResidentialStatus.value;
var Address = document.personal_info.Address.value;
var Address1 = document.personal_info.Address1.value;
var Address2 = document.personal_info.Address2.value;
var City1 = document.personal_info.City1.value;
var OtherCity1 = document.personal_info.OtherCity1.value;
var Pincode = document.personal_info.Pincode.value;
var TelLandline = document.personal_info.TelLandline.value;
var stdno = document.personal_info.stdno.value;
var phoneno = document.personal_info.phoneno.value


var Permanent_Address = document.personal_info.Permanent_Address.value;
var Permanent_Address1 = document.personal_info.Permanent_Address1.value;
var Permanent_Address2 = document.personal_info.Permanent_Address2.value;
var City2 = document.personal_info.City2.value;
var OtherCity2 = document.personal_info.OtherCity2.value;
var pincode1 = document.personal_info.pincode1.value;
var Permanent_Tel_Landline = document.personal_info.Permanent_Tel_Landline.value;
var Perm_stdcode = document.personal_info.Perm_stdcode.value;
var Perm_phoneno = document.personal_info.Perm_phoneno.value;




var companyName = document.personal_info.CompanyName.value;
var industrySection = document.personal_info.IndustrySection.value;
var monthlySalary = document.personal_info.NetSalary.value;
var creditBankName = document.personal_info.BankName.value;
var creditCardNum1 = document.personal_info.card_number1.value;
var creditCardNum2 = document.personal_info.card_number2.value;
var creditCardNum3 = document.personal_info.card_number3.value;
var creditCardNum4 = document.personal_info.card_number4.value;;
var creditMembersince =document.personal_info.MemberSince.value;
var creditMembersince1 =document.personal_info.MemberSince1.value;
var creditLimit = document.personal_info.Credit_limit.value;
var requestString = "";

//requestString+= "cardType="+cardType+"&FirstName="+FirstName+"&SecondName="+SecondName+"&LastName="+LastName+"&NameOnCard="+NameOnCard+"&genderVal="+genderVal+"&MartialVal="+MartialVal+"&Education="+Education+"&PAN_Number="+PAN_Number+"&Vehicle="+Vehicle+"&Occupation="+Occupation+"&DOB="+DOB+"&MM="+MM+"&YY="+YY+"&MotherName="+MotherName+"&NumberOfDependents="+NumberOfDependents+"&WorkExperince="+WorkExperince+"&EmailId="+EmailId+"&Mobile="+Mobile+"&Mobileno="+Mobileno;

requestString+= "FirstName="+FirstName+"&SecondName="+SecondName+"&LastName="+LastName+"&gender="+genderVal+"&PAN_Number="+PAN_Number+"&occupation="+Occupation+"&DOB="+DOB+"&MM="+MM+"&YY="+YY+"&EmailId="+EmailId+"&Mobile="+Mobile+"&Mobileno="+Mobileno;

requestString+= "&CompanyName="+companyName+"&IndustrySection="+industrySection+"&NetSalary="+monthlySalary;
requestString+= "&BankName="+creditBankName+"&card_number1="+creditCardNum1+"&card_number2="+creditCardNum2+"&card_number3="+creditCardNum3+"&card_number4="+creditCardNum4+"&MemberSince="+creditMembersince+"&MemberSince1="+creditMembersince1+"&Credit_limit="+creditLimit;
requestString+= "&ResidentialStatus="+ResidentialStatus+"&Address="+Address+"&Address1="+Address1+"&Address2="+Address2+"&City1="+City1+"&OtherCity1="+OtherCity1+"&Pincode="+Pincode+"&TelLandline="+TelLandline+"&stdno="+stdno+"&phoneno="+phoneno;
requestString+= "&Permanent_Address="+Permanent_Address+"&Permanent_Address1="+Permanent_Address1+"&Permanent_Address2="+Permanent_Address2+"&City2="+City2+"&pincode1="+pincode1+"&Permanent_Tel_Landline="+Permanent_Tel_Landline+"&Perm_stdcode="+Perm_stdcode+"&Perm_phoneno="+Perm_phoneno;

//alert("going to call post method ajax");

http_request=getRequestObject();
          
http_request.onreadystatechange = getResponseForPersonalDetails; 
var url="savePersonalDetails.do";

//alert(requestString);
	        
	        http_request.open("POST",url ,true)
			http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			
			http_request.send(requestString);
		
}        

    function getResponseForPersonalDetails() 
    {	
		
    	//alert("http_request.readyState" +http_request.readyState);
        if (http_request.readyState == 4) 
        {
            if (http_request.status == 200) 
            {
   		    	var XML_Result=http_request.responseText;
				var noRegEx = /^([0-9])*$/
				if(noRegEx.test(XML_Result)==true)
			   {
				  alert("Your personal details have been saved successfully");
				  //added for GA tracking code
				  pageTracker._trackPageview("/ContactDetails");
				  //added for GA tracking code
				  document.personal_info.CheckContent.value=XML_Result;
   				  document.Contact_details.CheckContent.value=XML_Result;
				  getContactDetailstab();

			  
			  
			   }else{
				alert(XML_Result);
			   
			   }
				
				
            }
            else
            {
               alert('There was a problem with the request.');
            }
        }

		//return false;
    }	


 function getResponseForContactDetails() 
    {	
	
    	//alert("http_request1.readyState" +http_request.readyState);
        if (http_request1.readyState == 4) 
        {
            if (http_request1.status == 200) 
            {
   		    	var XML_Result=http_request1.responseText;
	   
			
				document.Bank_details.CheckContent.value=XML_Result;
				alert("Your contact details have been saved successfully");
				//added for GA tracking code
				pageTracker._trackPageview("/BankDetails");
				//added for GA tracking code
				getBankDetailstab();
            }
            else
            {
               alert('There was a problem with the request.');
            }
        }

		//return false;
    }	


	


function validatePersonalDetails()
{
  //alert("inside validatePersonalDetails");


// alert("b4 savePersonalDetails ");
 savePersonalDetails();
 //window.location.href="applyonline.do?tab2#";
 //downloader.open("GET","www.google.co.in",true);


}


function saveContacts(){
 var content=document.Contact_details.CheckContent.value;
if(content=="")
	{
	alert("Please fill the personal details before you proceed");
	return false;
	}
//alert("b4 Checkcontactdetails()");
if (!Checkcontactdetails()){
		return false;
	}
	if(isOtherCity){ // to check the residential city is 'other city'
					 // in this case use no ajax, but normal submit with a thank you page.	
		 document.Contact_details.submit();

	}
	else{
		saveContactDetails();
	}
 

return false;
}


function saveContactDetails() 
{

//alert("inside saveContactDetails()111111");
var ResidentialStatus = document.Contact_details.ResidentialStatus.value;
var Address = document.Contact_details.Address.value;
var Address1 = document.Contact_details.Address1.value;
var Address2 = document.Contact_details.Address2.value;
var Landmark = document.Contact_details.Landmark.value;
var City1 = document.Contact_details.City1.value;
var OtherCity1 = document.Contact_details.OtherCity1.value;


// code for kotak no service in othercity
/*
if(OtherCity1.length>2)
	{
	return false;
}

*/

//var OtherCity1 = "othercity1";
var Pincode = document.Contact_details.Pincode.value;
var TelLandline = document.Contact_details.TelLandline.value;
var stdno = document.Contact_details.stdno.value;
var phoneno = document.Contact_details.phoneno.value;

/* Mobile number field moved to Personal details page
var Mobile = document.Contact_details.Mobile.value;
var Mobileno = document.Contact_details.Mobileno.value;
*/
var Permanent_Address = document.Contact_details.Permanent_Address.value;
var Permanent_Address1 = document.Contact_details.Permanent_Address1.value;
var Permanent_Address2 = document.Contact_details.Permanent_Address2.value;
var Permanent_Landmark = document.Contact_details.Permanent_Landmark.value;
var City2 = document.Contact_details.City2.value;
var OtherCity2 = document.Contact_details.OtherCity2.value;
//var Others ="others";



var pincode1 = document.Contact_details.pincode1.value;
var Permanent_Tel_Landline = document.Contact_details.Permanent_Tel_Landline.value;
var Perm_stdcode = document.Contact_details.Perm_stdcode.value;
var Perm_phoneno = document.Contact_details.Perm_phoneno.value;
var CompanyName = document.Contact_details.CompanyName.value;
var Department = document.Contact_details.Department.value;
var Office_Address = document.Contact_details.Office_Address.value;
var Office_Address1 = document.Contact_details.Office_Address1.value;
var Office_Address2 = document.Contact_details.Office_Address2.value;
var Office_Landmark = document.Contact_details.Office_Landmark.value;
var off_location_city = document.Contact_details.off_location_city.value;
//var OtherCity3 = document.Contact_details.OtherCity3.value;
//var OtherCity2 = "othercity2";






var Off_pincode = document.Contact_details.Off_pincode.value;
/*
			 commented as on 031208 for new requirment 
			 
var Office_Telephone = document.Contact_details.Office_Telephone.value;
var Office_Telephone_std = document.Contact_details.Office_Telephone_std.value;
var Office_Telephone_phoneno = document.Contact_details.Office_Telephone_phoneno.value;
*/

var Office_Telephone_direct = document.Contact_details.Office_Telephone_direct.value;
var Office_Direct_stdno = document.Contact_details.Office_Direct_stdno.value;
var Office_Direct_telno = document.Contact_details.Office_Direct_telno.value;
var Mailing_Address = document.Contact_details.Mailing_Address.value;
var CheckContent = document.Contact_details.CheckContent.value;


http_request1=getRequestObject1();
          
http_request1.onreadystatechange = getResponseForContactDetails; 
var url="saveContactDetails.do";
	     
	http_request1.open("POST",url ,true)
	http_request1.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');


/* commented on 031208 
http_request1.send("ResidentialStatus="+ResidentialStatus+"&Address="+Address+"&Address1="+Address1+"&Landmark="+Landmark+"&City1="+City1+"&OtherCity1="+OtherCity1+"&Pincode="+Pincode+"&TelLandline="+TelLandline+"&stdno="+stdno+"&phoneno="+phoneno+"&Mobile="+Mobile+"&Mobileno="+Mobileno+"&Permanent_Address="+Permanent_Address+"&Permanent_Address1="+Permanent_Address1+"&Permanent_Landmark="+Permanent_Landmark+"&City2="+City2+"&OtherCity3="+OtherCity3+"&pincode1="+pincode1+"&Permanent_Tel_Landline="+Permanent_Tel_Landline+"&Perm_stdcode="+Perm_stdcode+"&Perm_phoneno="+Perm_phoneno+"&CompanyName="+CompanyName+"&Department="+Department+"&Office_Address="+Office_Address+"&Office_Address1="+Office_Address1+"&Office_Landmark="+Office_Landmark+"&off_location_city="+off_location_city+"&OtherCity2="+OtherCity2+"&Off_pincode="+Off_pincode+"&Office_Telephone="+Office_Telephone+"&Office_Telephone_std="+Office_Telephone_std+"&Office_Telephone_phoneno="+Office_Telephone_phoneno+"&Office_Telephone_direct="+Office_Telephone_direct+"&Office_Direct_stdno="+Office_Direct_stdno+"&Office_Direct_telno="+Office_Direct_telno+"&Mailing_Address="+Mailing_Address+"&CheckContent="+CheckContent);
	*/
/*	Mobile number field moved to Personal details page
http_request1.send("ResidentialStatus="+ResidentialStatus+"&Address="+Address+"&Address1="+Address1+"&Address2="+Address2+"&Landmark="+Landmark+"&City1="+City1+"&OtherCity1="+OtherCity1+"&Pincode="+Pincode+"&TelLandline="+TelLandline+"&stdno="+stdno+"&phoneno="+phoneno+"&Mobile="+Mobile+"&Mobileno="+Mobileno+"&Permanent_Address="+Permanent_Address+"&Permanent_Address1="+Permanent_Address1+"&Permanent_Address2="+Permanent_Address2+"&Permanent_Landmark="+Permanent_Landmark+"&City2="+City2+"&OtherCity3="+OtherCity3+"&pincode1="+pincode1+"&Permanent_Tel_Landline="+Permanent_Tel_Landline+"&Perm_stdcode="+Perm_stdcode+"&Perm_phoneno="+Perm_phoneno+"&CompanyName="+CompanyName+"&Department="+Department+"&Office_Address="+Office_Address+"&Office_Address1="+Office_Address1+"&Office_Address2="+Office_Address2+"&Office_Landmark="+Office_Landmark+"&off_location_city="+off_location_city+"&OtherCity2="+OtherCity2+"&Off_pincode="+Off_pincode+"&Office_Telephone_direct="+Office_Telephone_direct+"&Office_Direct_stdno="+Office_Direct_stdno+"&Office_Direct_telno="+Office_Direct_telno+"&Mailing_Address="+Mailing_Address+"&CheckContent="+CheckContent);	
*/
http_request1.send("ResidentialStatus="+ResidentialStatus+"&Address="+Address+"&Address1="+Address1+"&Address2="+Address2+"&Landmark="+Landmark+"&City1="+City1+"&OtherCity1="+OtherCity1+"&Pincode="+Pincode+"&TelLandline="+TelLandline+"&stdno="+stdno+"&phoneno="+phoneno+"&Permanent_Address="+Permanent_Address+"&Permanent_Address1="+Permanent_Address1+"&Permanent_Address2="+Permanent_Address2+"&Permanent_Landmark="+Permanent_Landmark+"&City2="+City2+"&pincode1="+pincode1+"&Permanent_Tel_Landline="+Permanent_Tel_Landline+"&Perm_stdcode="+Perm_stdcode+"&Perm_phoneno="+Perm_phoneno+"&CompanyName="+CompanyName+"&Department="+Department+"&Office_Address="+Office_Address+"&Office_Address1="+Office_Address1+"&Office_Address2="+Office_Address2+"&Office_Landmark="+Office_Landmark+"&off_location_city="+off_location_city+"&OtherCity2="+OtherCity2+"&Off_pincode="+Off_pincode+"&Office_Telephone_direct="+Office_Telephone_direct+"&Office_Direct_stdno="+Office_Direct_stdno+"&Office_Direct_telno="+Office_Direct_telno+"&Mailing_Address="+Mailing_Address+"&CheckContent="+CheckContent);	

}     

function allowOnlyNumeric(evt){  
   try{
   var charCode = (evt.which) ? evt.which : event.keyCode;
   //alert(charCode > 31 && (charCode < 46 || charCode==47 || charCode > 57));
   if (charCode > 31 && (charCode < 46 || charCode==47 || charCode > 57))
	   {return false;}
   }catch(e){
   
   }
	return true;
}

function whichButton(e)
{
	 /*if (event.button==2)//For right click
	 {
	  alert("Right Click Not Allowed!");
	 }*/
	  var isRight = (e.button) ? (e.button == 2) : (e.which == 3);
        
        if(isRight) {
           alert('Sorry, this functionality is disabled !');
            return false;
        }/*else{
			return true;        
        }*/
        



}


function noCTRL(e)
{
	/*alert(navigator.appName);2
	 var code = (document.all) ? event.keyCode:e.which;
	 var msg = "Sorry, this functionality is disabled !";
	 if (parseInt(code)==17) // This is the Key code for CTRL key
	 {
	  alert(msg);
	  return  false;
	 }*/

	 var forbiddenKeys = new Array('c','x','v');
        var keyCode = (e.keyCode) ? e.keyCode : e.which;
        var isCtrl;

        if(window.event)
            isCtrl = e.ctrlKey
        else
            isCtrl = (window.Event) ? ((e.modifiers & Event.CTRL_MASK) == Event.CTRL_MASK) : false;
    
        if(isCtrl) {
            for(i = 0; i < forbiddenKeys.length; i++) {
                if(forbiddenKeys[i] == String.fromCharCode(keyCode).toLowerCase()) {
                    alert('You are prompted to type this twice for a reason!');
                    return false;
                }
            }
        }
        //return true;

}

function prepopulate(){
/*
	updating the code of card type Since it is displayed as Royale Signature Card , but where as in table Enum table stored as Royale Card,
		so converting Royale Card to Royale Signature Card 
*/
	
	
//start


	/*for(var i=1;i<document.personal_info.cardType.options.length;i++){

		if(document.personal_info.cardType.options[i].value== cardType){
			document.personal_info.cardType.options.selectedIndex = i;
			displayinfo();

			//added for Left Nav CardType Image-start
			displayCardInfo();
			detectchange(desNameOnCard);
			//added for Left Nav CardType Image-end

			//if(cardType == "League Card" || cardType == "Royale Signature Card"){
			


				var goodYId;
				var subgoodYId;

			if(cardType =="League Card"){
				goodYId = "goodiesleague";
				subgoodYId = "leaguesubgoody";
				}

			if(cardType =="Trump Card"){
				goodYId = "goodiestrump";
				subgoodYId = "trumpsubgoody";
				}

			if(cardType =="Royale Signature Card"){
				goodYId = "goodiesroyale";
				subgoodYId = "royalesubgoody";
				}
				
			if(cardType =="Fortune Card"){
				goodYId = "goodiesfortune";
				subgoodYId = "fortunesubgoody";
				}

			if(goodyId.length>0){
				//alert("document.personal_info.goodies.length"+document.personal_info.goodies.length);
				if(document.personal_info.goodies.length){ //multiple goody amounts
				
					for(var j=0;j < document.personal_info.goodies.length;j++){ 						
							
						if(document.personal_info.goodies[j].value == goodyId ){						
							
							document.personal_info.goodies[j].checked = true;
							
							
								if(cardType=="League Card"){
									displayWatchLeague('league',goodyId);
								}
								else if(cardType=="Fortune Card"){
									displayWatchFortune('fortune',goodyId);
								}
								else if(cardType=="Royale Signature Card"){
									displayWatchRoyal('royale',goodyId);
								}
								else if(cardType=="Trump Card"){							
									displayWatchTrump('trump',goodyId);
								}


							if(goodyName.length>0){	

							if(document.personal_info.subgoody.length){
								for(var k=0;k<document.personal_info.subgoody.length;k++){
								
									if(document.personal_info.subgoody[k].value == goodyName){
										document.personal_info.subgoody[k].checked = true;
									//if(cardType == "League Card")
									//{
									//alert("aaa"+goodyId);
									//displayWatchLeague('league',goodyId);
									//}
									break;
									}
							
								}//end of for   
							}// end of if
							else{
							// populate for single goodyesName
								if(document.personal_info.subgoody.value !=null && document.personal_info.subgoody.value !="")
								{
									if(document.personal_info.subgoody.id == subgoodYId ){
										document.personal_info.subgoody.checked = true;
									}	
								}
							}//end of else
							
							}//end of if for goodyName.length
											
						break;
					}
				
				}
			}else{
				
					//only one goody amount is present across all card types.

					if(document.personal_info.goodies.value == goodyId){
					
								document.personal_info.goodies.checked = true;
								
								if(cardType=="League Card"){

									displayWatchLeague('league',goodyId);

								}
								else if(cardType=="Fortune Card"){

									displayWatchFortune('fortune',goodyId);

								}
								else if(cardType=="Royale Signature Card"){

									displayWatchRoyal('royale',goodyId);

								}
								else if(cardType=="Trump Card"){
									
									displayWatchTrump('trump',goodyId);

								}



								
									if(goodyName.length>0)
									{	

									if(document.personal_info.subgoody.length)
									{
									for(var k=0;k<document.personal_info.subgoody.length;k++){
										
									
										if(document.personal_info.subgoody[k].value == goodyName){
										
											document.personal_info.subgoody[k].checked = true;
											//if(cardType == "League Card")
											//{
											//alert("aaa"+goodyId);
											//displayWatchLeague('league',goodyId);
											//}
											break;

										}
									
									}//end of for   
									}// end of if
									else{
									// populate for single goodyesName
										if(document.personal_info.subgoody.value !=null && document.personal_info.subgoody.value !="")
										{
											
											if(document.personal_info.subgoody.id == subgoodYId ){
												document.personal_info.subgoody.checked = true;
											}	
										}
									}//end of else
									
									

									}//end of if for goodyName.length
													
							
							}

				
				}


			}// end of outer if
			//}
			
		//	break;
		
		}	
	}


	


	for(var i=0;i<document.personal_info.Education.options.length;i++){
		if(document.personal_info.Education.options[i].value== education){		
			document.personal_info.Education.options.selectedIndex = i;
			break;
		
		}	
	}


		
	for(var i=0;i<document.personal_info.Vehicle.options.length;i++){

		if(document.personal_info.Vehicle.options[i].value==vehicleType){		
			document.personal_info.Vehicle.options.selectedIndex = i;
			break;
		
		}	
	}
*/
		for(var i=0;i<document.personal_info.DOB.options.length;i++){

	//alert("Integer.parseInt(document.personal_info.DOB.options[i].value)"+Integer.parseInt(document.personal_info.DOB.options[i].value));
//alert("aaaaaaaaa"+parseInt(dobDay,10));
		if(document.personal_info.DOB.options[i].value==dobDay){		
			document.personal_info.DOB.options.selectedIndex = i;
			break;
		
		}	
	}

		for(var i=0;i<document.personal_info.MM.options.length;i++){

		if(document.personal_info.MM.options[i].value==dobMonth){		
			document.personal_info.MM.options.selectedIndex = i;
			break;
		
		}	
	}

	for(var i=0;i<document.personal_info.YY.options.length;i++){

		if(document.personal_info.YY.options[i].value==dobYear){		
			document.personal_info.YY.options.selectedIndex = i;
			break;
		
		}	
	}

   
   for(var i=0;i<document.personal_info.MemberSince.options.length;i++){

		if(document.personal_info.MemberSince.options[i].value==creditmonth){		
			document.personal_info.MemberSince.options.selectedIndex = i;
			break;
		
		}	
	}

	for(var i=0;i<document.personal_info.MemberSince1.options.length;i++){

		if(document.personal_info.MemberSince1.options[i].value==credityear){		
			document.personal_info.MemberSince1.options.selectedIndex = i;
			break;
		
		}	
	}
   



// for no of dependent
/*
for(var i=0;i<document.personal_info.NumberOfDependents.options.length;i++){

		if(document.personal_info.NumberOfDependents.options[i].value==NumberOfDep){		
			document.personal_info.NumberOfDependents.options.selectedIndex = i;
			break;
		
		}	
	}

// checking for advance joining gift
if(advanceGiftVal != ""){
       for(var p= 0; p< document.personal_info.advanceGiftName.length;p++){
         
      if(document.personal_info.advanceGiftName[p].value == advanceGiftVal){
              document.personal_info.advanceGiftName[p].checked = true;
              break;
           } //End of inner if for advanceGiftVal
       }// End of for
} // End of outer if for advanceGiftVal

*/
//  End checking for advance joining gift

if(genderType != ""){
if(document.personal_info.gender[0].value ==genderType ){
		document.personal_info.gender[0].checked = true;
 }
 else{
	 document.personal_info.gender[1].checked = true;
 }
}else{

			document.personal_info.gender[0].checked = true;
}

/*if(maritalStatusType != ""){
if(document.personal_info.Martial_Status[0].value ==maritalStatusType ){
		document.personal_info.Martial_Status[0].checked = true;
 }
 
 else{
	 document.personal_info.Martial_Status[1].checked = true;
 }
}else{

	document.personal_info.Martial_Status[0].checked = true;
}
*/
	/*
		updating the code for occupationType = salaried, Since in Enum table its stored as salaried where
		where in xhtml its Salaried,	
*/
   		if(occupationType == "salaried"){
   			occupationType = "Salaried";
   		}
   			
	for(var i=0;i<document.personal_info.occupation.length;i++){
			
		if(document.personal_info.occupation[i].value==occupationType){	
		
			document.personal_info.occupation[i].checked = true;
			break;
		
		}	
	}
	
	
	
	
	for(var i=0;i<document.personal_info.IndustrySection.options.length;i++){

		if(document.personal_info.IndustrySection.options[i].value==department){		
			document.personal_info.IndustrySection.options.selectedIndex = i;
			break;
		
		}	
	}
	
	
	/*
 displayOccupation();
*/

/*
 if(occupationType =="Salaried"){

		document.personal_info.Designation.value = designation;
		document.personal_info.WorkExperince.value = workexperience;

}
else if(occupationType =="Self-employed Business"){

	
	for(var i=0;i<document.personal_info.Ownership.options.length;i++){

		if(document.personal_info.Ownership.options[i].value==designation){		
			document.personal_info.Ownership.options.selectedIndex = i;
			break;
		
		}	
	}
	
//document.personal_info.durationInBuisness.value = workexperience;
}*/

prepopulateContactDetails();
}

function prepopulateContactDetails(){			

	for(var i=0;i<document.personal_info.ResidentialStatus.length;i++){			
		if(document.personal_info.ResidentialStatus[i].value==residentialStatus){		
			document.personal_info.ResidentialStatus[i].checked = true;
			break;
		
		}	
	}
	
	
	
	

var residingCityFlag = false;

	for(var i=0;i<document.personal_info.City1.options.length;i++){

		if(document.personal_info.City1.options[i].value==residingCity){		
			document.personal_info.City1.options.selectedIndex = i;
			residingCityFlag = true;
			break;
		
		}	
	 }
	
	if(!residingCityFlag){
	// option selected was others
	document.personal_info.City1.options.selectedIndex = i-1;
	//alert("we are here "+designation)
	showother('1');
	document.personal_info.OtherCity1.value = residingCity;
	
}

var permanentCityFlag = false;
	
	for(var i=0;i<document.personal_info.City2.options.length;i++){

		if(document.personal_info.City2.options[i].value==permanentCity){		
			document.personal_info.City2.options.selectedIndex = i;
			permanentCityFlag = true;
			break;
		
		}	
	 }
	
	if(!permanentCityFlag){
	// option selected was others
	document.personal_info.City2.options.selectedIndex = i-1;
	//alert("we are here "+designation)
	showother('2');
	document.personal_info.OtherCity2.value = permanentCity;
	
}




	/*var officialCityFlag = false;
	
	for(var i=0;i<document.personal_info.off_location_city.options.length;i++){

		if(document.personal_info.off_location_city.options[i].value==officialCity){		
			document.personal_info.off_location_city.options.selectedIndex = i;
			officialCityFlag = true;
			break;
		
		}	
	 }
	
	if(!officialCityFlag){
	// option selected was others
	document.personal_info.off_location_city.options.selectedIndex = i-1;
	//alert("we are here "+designation)
	showother('3');
	document.personal_info.OtherCity3.value = officialCity;
	
  }

for(var i=0;i<document.personal_info.Mailing_Address.options.length;i++){

		if(document.personal_info.Mailing_Address.options[i].value==Mailing_Address){		
			document.personal_info.Mailing_Address.options.selectedIndex = i;
			break;
		
		}	
	 }*/

}
 