function ajaxFunction(param, addDivId)
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		
		if(ajaxRequest.readyState == 4){
			
			if(addDivId != ""){
				
				arr = ajaxRequest.responseText;
				
				document.getElementById(addDivId).innerHTML = arr;
				
			
			}
			
			
		}
	}
	ajaxRequest.open("GET", param, true);
	ajaxRequest.send(null); 
}

function getSubcaste(){
	
	var caste = document.getElementById('tcaste').value;
	var alpha = document.getElementById('talphabets').value;
	
	if(alpha<1){alpha=-1;}
	param = "getsubcasteblock.php?caste="+caste+"&alpha="+alpha;
	
	ajaxFunction(param,'tdtsubcaste');

}

function checktcaste()
{
	var caste 	 = document.getElementById('tcaste').value;
	
	var alpha 	 = document.getElementById('tdtalphabets');
	var subcaste = document.getElementById('tdtsubcaste');
	
	if(caste != 0){
		getAlpha();
		getSubcaste();
		
	}
	else if(caste == 0)
	{
		/*subcaste.style.display='none';
		subcaste.style.visiblity='hidden';*/
		alpha.innerHTML	   = "<select name='talphabets' id='talphabets' OnChange='getSubcaste();' size='1'  class='select'><OPTION value=0>Not Applicable</OPTION></select>";
		subcaste.innerHTML = "<select name='tsubcaste' class='select' id='tsubcaste'><OPTION value=0>Not Applicable</OPTION></select>";
		
		

	}
	
}

function getAlpha(){
	
	param = "getalphablock.php";
	
	ajaxFunction(param,'tdtalphabets');
	
	
	}

function checktCountry()
{
	var country = document.getElementById('tcountry').value;
	var state   = document.getElementById('tdtstate');
	var city    = document.getElementById('tdtcity');
	
	if(country!='India'){
		
		state.innerHTML = "<select name='tstate'  id='tstate' class='select' onchange='checktState();' style='width:165px;'><option value='0'>Not Applicable</option></select>";
		city.innerHTML	= "<select name='tcity' id='tcity' class='select'><option value='0'>Not Applicable</option></select>";
	}
	else
	{
		
		gettState();
		
	}
	
}


function gettState(){
	
	var country = document.getElementById('tcountry').value;
	param = "getstateblock.php?country="+country;
	
	ajaxFunction(param,'tdtstate');

}

function gettCity(){
	
	var state = document.getElementById('tstate').value;
	param 	  = "getcityblock.php?state="+state;
	
	ajaxFunction(param,'tdtcity');

}
function checktState()
{
	var state   = document.getElementById('tstate').value;
	var city    = document.getElementById('tdtcity');
	
	
	if(state==0){
		
		city.innerHTML	= "<select name='tcity' id='tcity' class='select'><option value='0'>Not Applicable</option></select>";
	}
	else
	{
		gettCity();
		
	}
	
}

function getSelectedState(selectedState)
{//selectedState;
	var arroption = document.getElementById('tstate').options;
	var i		  = arroption.length;
	
	for(j=0;j<i;j++)
	{
		
		if(selectedState == arroption[j].value){
			
			arroption.selectedIndex = j;
			break;
			
		}
	}
	
	setTimeout(gettCity,100);
}

function getSelectedCity(selectedCity)
{
	var arroption = document.getElementById('tcity').options;
	var i		  = arroption.length;
		
	for(j=0;j<i;j++)
	{
	
		if(selectedCity == arroption[j].value){
			
			arroption.selectedIndex = j;
			
			break;
			
		}
	}
	
}

function getSelectedMarital(selectedMarital)
{
	var arroption = document.getElementById('tmstatus').options;
	var i		  = arroption.length;
		
	for(j=0;j<i;j++)
	{
	
		if(selectedMarital == arroption[j].value){
			
			arroption.selectedIndex = j;			
			break;
			
		}
	}
	
}

function getSelectedGender(selectedGender)
{
	var arroption = document.getElementById('tgender').options;
	var i		  = arroption.length;
		
	for(j=0;j<i;j++)
	{
	
		if(selectedGender == arroption[j].value){
			
			arroption.selectedIndex = j;			
			break;
			
		}
	}
	
}

function getSelectedReligion(selectedReligion)
{
	var arroption = document.getElementById('treligion').options;
	var i		  = arroption.length;
		
	for(j=0;j<i;j++)
	{
	
		if(selectedReligion == arroption[j].value){
			
			arroption.selectedIndex = j;			
			break;
			
		}
	}
	
}
function getSelectedCaste(selectedCaste)
{
	var arroption = document.getElementById('tcaste').options;
	var i		  = arroption.length;
		
	for(j=0;j<i;j++)
	{
	
		if(selectedCaste == arroption[j].value){
			
			arroption.selectedIndex = j;			
			break;
			
		}
	}
	
}

function getSelectedCountry(selectedCountry)
{
	var arroption = document.getElementById('tcountry').options;
	var i		  = arroption.length;
		
	for(j=0;j<i;j++)
	{
	
		if(selectedCountry == arroption[j].value){
			
			arroption.selectedIndex = j;			
			break;
			
		}
	}
	
}
function getSelectedAge1(selectedAge1)
{
	var arroption = document.getElementById('tage1').options;
	var i		  = arroption.length;
	
	for(j=0;j<i;j++)
	{
	
		if(selectedAge1 == arroption[j].value){
			
			arroption.selectedIndex = j;			
			break;
			
		}
	}
	
}
function getSelectedAge2(selectedAge2)
{
	var arroption = document.getElementById('tage2').options;
	var i		  = arroption.length;
		
	for(j=0;j<i;j++)
	{
	
		if(selectedAge2 == arroption[j].value){
			
			arroption.selectedIndex = j;			
			break;
			
		}
	}
	
}


function getSelectedHeight1(selectedHeight1)
{
	var arroption = document.getElementById('theight1').options;
	var i		  = arroption.length;
		
	for(j=0;j<i;j++)
	{
	
		if(selectedHeight1 == arroption[j].value){
			
			arroption.selectedIndex = j;			
			break;
			
		}
	}
	
}
function getSelectedHeight2(selectedHeight2)
{
	var arroption = document.getElementById('theight2').options;
	var i		  = arroption.length;
		
	for(j=0;j<i;j++)
	{
	
		if(selectedHeight2 == arroption[j].value){
			
			arroption.selectedIndex = j;			
			break;
			
		}
	}
	
}

function getSelectedPhoto(selectedPhoto)
{
	var photo = document.getElementById('tphoto');
	if(selectedPhoto == 'yes'){photo.checked = "checked";}
	else{photo.checked = "";}
}

function getSelectedAlpha(selectedAlpha)
{
	var arroption = document.getElementById('talphabets').options;
	var i		  = arroption.length;
	
	
		
	for(j=0;j<i;j++)
	{
	
		if(selectedAlpha == arroption[j].value){
			
			arroption.selectedIndex = j;			
			break;
			
		}
	}
	setTimeout(getSubcaste,100);
}

function getSelectedSub(selectedSub)
{
	var arroption = document.getElementById('tsubcaste').options;
	var i		  = arroption.length;
		
	for(j=0;j<i;j++)
	{
	
		if(selectedSub == arroption[j].value)
		{
			
			arroption.selectedIndex = j;			
			break;
			
		}
	}
	
}

