// JavaScript Document

function MemberRegistration(){
	//alert("I am here");
	var email = document.getElementById('email').value
	var pwd = document.getElementById('pwd').value
	var cpwd = document.getElementById('cpwd').value
	var fname = document.getElementById('fname').value
	var	lname = document.getElementById('lname').value
	var add1 = document.getElementById('add1').value
	var city = document.getElementById('city').value
	
	var shipfname = document.getElementById('shipfname').value
	var	shiplname = document.getElementById('shiplname').value
	var shipadd1 = document.getElementById('shipadd1').value
	var shipcity = document.getElementById('shipcity').value
	var country = document.getElementById('country').value
	
	if(email=="")
		{
			alert("Please enter the email");
			document.getElementById('email').focus();
			return false;
		}
	
	
	var str = email;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (!filter.test(str))
		{
		alert('Please input a valid email address!')
		document.getElementById('email').focus();;
		return false;
		}
	
	
	if(pwd=="")
		{
			alert("Please enter the password");
			document.getElementById('pwd').focus();
			return false;
		}
	
	if(cpwd!=pwd)
		{
			alert("Confirmation password doesn't match");
			document.getElementById('cpwd').focus();
			return false;
		}
		
	if(fname=="")
		{
			alert("Please enter the first name");
			document.getElementById('fname').focus();
			return false;
		}
		
	if(lname=="")
		{
			alert("Please enter the last name");
			document.getElementById('lname').focus();
			return false;
		}
		
	if(add1=="")
		{
			alert("Please enter the address1");
			document.getElementById('add1').focus();
			return false;
		}
		
	
	if(city=="")
		{
			alert("Please enter the city");
			document.getElementById('city').focus();
			return false;
		}
		
	
	
	if(country==0)
		{
			alert("Please select the country");
			document.getElementById('country').focus();
			return false;
		}
	
	if(shipfname=="")
		{
			alert("Please enter the receiver's first name");
			document.getElementById('shipfname').focus();
			return false;
		}
		
	if(shiplname=="")
		{
			alert("Please enter the receiver's last name");
			document.getElementById('shiplname').focus();
			return false;
		}
	
	if(shipadd1=="")
		{
			alert("Please enter the delivery address1");
			document.getElementById('shipadd1').focus();
			return false;
		}
		
		if(shipcity=="")
		{
			alert("Please enter the delivery city");
			document.getElementById('shipcity').focus();
			return false;
		}	
		
	submit();
	
}


//#####################################################################################

function SelectState(id)
	{
		//alert(id);
		//return false;
		//var email= document.getElementById('email1').value;
		
	var ajaxRequest; 	
	try
		{
		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;
				}
			}
		}
	ajaxRequest.onreadystatechange = function()
		{
		var display_id='showstate';
					
		if(ajaxRequest.readyState == 4)
			{			
			document.getElementById(display_id).innerHTML = ajaxRequest.responseText;
			}
		}
	var queryString = "&id=" + id ;
	ajaxRequest.open("GET", "action_ajax.php?option=1&include=showstate" + queryString, true);
	ajaxRequest.send(null); 
	}
	

//##############################################################################################

function CheckEmail()
	{
		//var testresults
	var str=document.getElementById('email').value
	//alert(str);
	//return false;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (!filter.test(str))
		{
		alert('Please input a valid email address!')
		document.getElementById('email').focus();
		return false;
		}
	
	//return false;
	var ajaxRequest; 	
	try
		{
		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;
				}
			}
		}
	ajaxRequest.onreadystatechange = function()
		{
		var display_id='emailavialable';
					
		if(ajaxRequest.readyState == 4)
			{			
			document.getElementById(display_id).innerHTML = ajaxRequest.responseText;
			}
		}
	var queryString = "&email=" + str ;
	ajaxRequest.open("GET", "action_ajax.php?option=1&include=checkemail_avialable" + queryString, true);
	ajaxRequest.send(null); 
	}
	
/**********************************************************/

function copybilling()
{
	//alert(document.getElementById('chkcopy').checked);
	if(document.getElementById('chkcopy').checked == true){
		document.getElementById('shipfname').value = document.getElementById('fname').value
		document.getElementById('shipmname').value = document.getElementById('mname').value
		document.getElementById('shiplname').value = document.getElementById('lname').value
		document.getElementById('shipadd1').value = document.getElementById('add1').value
		document.getElementById('shipadd2').value = document.getElementById('add2').value
		document.getElementById('shipcity').value = document.getElementById('city').value
		document.getElementById('shipstate').value = document.getElementById('state').value
		document.getElementById('shipcountry').value = document.getElementById('country').value
		document.getElementById('shipzip').value = document.getElementById('zip').value
		document.getElementById('shiptel').value = document.getElementById('tel').value
		document.getElementById('shipmobile').value = document.getElementById('mobile').value
	} else {
		document.getElementById('shipfname').value = ''
		document.getElementById('shipmname').value = ''
		document.getElementById('shiplname').value = ''
		document.getElementById('shipadd1').value = ''
		document.getElementById('shipadd2').value = ''
		document.getElementById('shipcity').value = 'Kathmandu'
		document.getElementById('shipzip').value = ''
		document.getElementById('shiptel').value = ''
		document.getElementById('shipmobile').value = ''
	}

}
	