//this file requires that "Lib_Validations.js" also be included on the including page
function btnLimitByRegion_onclick() {

	var i;
	var j;
	var intCID = document.getElementById("cboRegion").value;
	
	//remove everything in the list
	removeAllCountry();
	
	
	var intSelectedCount = document.getElementById("cboCountry").options.length;
	
	//alert(intSelectedCount);
		
	//add new countries based on given region ID
	
	
	if(intCID=='' || intCID =='-1')
	{
		for (i=0; i<document.getElementById("cboCountryFull").options.length; i++) 
		{     
			document.getElementById("cboCountry").options[intSelectedCount] = new Option(document.getElementById("cboCountryFull").options[i].text,document.getElementById("cboCountryFull").options[i].value);
			intSelectedCount++;		
			
		}
	
	}
	else
	{
	
		for (i=0; i<document.getElementById("cboCountryFull").options.length; i++) 
		{    
			//alert(document.getElementById("cboCountryFull").options[i].getAttribute("Region_ID"));
			//alert(intCID);
			if (document.getElementById("cboCountryFull").options[i].getAttribute("Region_ID") == intCID)
			{
		    	document.getElementById("cboCountry").options[intSelectedCount] = new Option(document.getElementById("cboCountryFull").options[i].text,document.getElementById("cboCountryFull").options[i].value);
				intSelectedCount++;		
			}
		}
	}
		
	//document.getElementById("cboCountry").options[0] = null;
	//document.getElementById("cboCountry").options[intSelectedCount-1] = new Option("Please select Country","-1");
	
	return true;
}

function btnLimitByCountry_onclick() {

	var i;
	var j;
	var intCID = document.getElementById("cboCountry").value;
	
	//remove everything in the list
	removeAll();
	
	var intSelectedCount = document.getElementById("cboState").options.length;
	//alert(intSelectedCount);
	//add new states based on given country ID	
	for (i=0; i<document.getElementById("cboStateFull").options.length; i++) 
	{     
		if (document.getElementById("cboStateFull").options[i].getAttribute("Country_ID") == intCID)
		{
        	document.getElementById("cboState").options[intSelectedCount] = new Option(document.getElementById("cboStateFull").options[i].text,document.getElementById("cboStateFull").options[i].value);
			intSelectedCount++;		
		}
	}
	
	
	document.getElementById("cboState").options[0] = null;
	document.getElementById("cboState").options[intSelectedCount-1] = new Option("Other - Please specify in address line 3","-1");
	
	return true;
}

function btnLimitByRegionForSearch_onclick() {

	var i;
	var j;
	var intCID = document.getElementById("cboRegion").value;
	
	//remove everything in the list
	removeAllCountry();
	
	var intSelectedCount = document.getElementById("cboCountry").options.length;
	
	//alert(intSelectedCount);
			
	//add new countries based on given Region ID	
	
	if(intCID=='' || intCID =='-1')
	{
		for (i=0; i<document.getElementById("cboCountryFull").options.length; i++) 
		{     
			document.getElementById("cboCountry").options[intSelectedCount] = new Option(document.getElementById("cboCountryFull").options[i].text,document.getElementById("cboCountryFull").options[i].value);
			intSelectedCount++;		
			
		}
	
	}
	else
	{
		for (i=0; i<document.getElementById("cboCountryFull").options.length; i++) 
		{     
			if (document.getElementById("cboCountryFull").options[i].Region_ID == intCID)
			{
		    	document.getElementById("cboCountry").options[intSelectedCount] = new Option(document.getElementById("cboCountryFull").options[i].text,document.getElementById("cboCountryFull").options[i].value);
				intSelectedCount++;		
			}
		}
	}
	document.getElementById("cboCountry").options[0] = new Option('','');
	document.getElementById("cboCountry").options[intSelectedCount] = new Option("Other","-1");
	document.getElementById("cboCountry").options[0].selected = true;
	return true;
}


function btnLimitByCountryForSearch_onclick() {

	var i;
	var j;
	var intCID = document.getElementById("cboCountry").value;
	
	//remove everything in the list
	removeAll();
	
	var intSelectedCount = document.getElementById("cboState").options.length;
	
	//alert(intSelectedCount);
			
	//add new states based on given country ID	
	for (i=0; i<document.getElementById("cboStateFull").options.length; i++) 
	{     
		if (document.getElementById("cboStateFull").options[i].Country_ID == intCID)
		{
        	document.getElementById("cboState").options[intSelectedCount] = new Option(document.getElementById("cboStateFull").options[i].text,document.getElementById("cboStateFull").options[i].value);
			intSelectedCount++;		
		}
	}
	document.getElementById("cboState").options[0] = new Option('','');
	document.getElementById("cboState").options[intSelectedCount] = new Option("Other","-1");
	document.getElementById("cboState").options[0].selected = true;
	return true;
}

function removeAllCountry() 
{
	var i;
    
	for (i = document.getElementById("cboCountry").length; i > 0; i--)
	{
		if (document.getElementById("cboCountry").options[i-1].value!='-1'){
			document.getElementById("cboCountry").options[i-1] = null
		}
	}
   
  	return true;
}


function removeAll() 
{
	var i;
    
	for (i = document.getElementById("cboState").length; i > 0; i--)
	{
		if (document.getElementById("cboState").options[i-1].value!='-1'){
			document.getElementById("cboState").options[i-1] = null
		}
	}
   
  	return true;
}


