var badmail=0;
var oldbuttonvalue="Join Now!";

//V3.01.A - http://www.openjs.com/scripts/jx/
jx = {
	//Create a xmlHttpRequest object - this is the constructor. 
	getHTTPObject : function() {
		var http = false;
		//Use IE's ActiveX items to load the file.
		if(typeof ActiveXObject != 'undefined') {
			try {http = new ActiveXObject("Msxml2.XMLHTTP");}
			catch (e) {
				try {http = new ActiveXObject("Microsoft.XMLHTTP");}
				catch (E) {http = false;}
			}
		//If ActiveX is not available, use the XMLHttpRequest of Firefox/Mozilla etc. to load the document.
		} else if (window.XMLHttpRequest) {
			try {http = new XMLHttpRequest();}
			catch (e) {http = false;}
		}
		return http;
	},
	// This function is called from the user's script. 
	//Arguments - 
	//	url	- The url of the serverside script that is to be called. Append all the arguments to 
	//			this url - eg. 'get_data.php?id=5&car=benz'
	//	callback - Function that must be called once the data is ready.
	//	format - The return type for this function. Could be 'xml','json' or 'text'. If it is json, 
	//			the string will be 'eval'ed before returning it. Default:'text'
	load : function (url,callback,format) {
		var http = this.init(); //The XMLHttpRequest object is recreated at every call - to defeat Cache problem in IE
		if(!http||!url) return;
		if (http.overrideMimeType) http.overrideMimeType('text/xml');

		if(!format) var format = "text";//Default return type is 'text'
		format = format.toLowerCase();
		
		//Kill the Cache problem in IE.
		var now = "uid=" + new Date().getTime();
		url += (url.indexOf("?")+1) ? "&" : "?";
		url += now;

		http.open("GET", url, true);

		http.onreadystatechange = function () {//Call a function when the state changes.
			if (http.readyState == 4) {//Ready State will be 4 when the document is loaded.
				if(http.status == 200) {
					var result = "";
					if(http.responseText) result = http.responseText;
					
					//If the return is in JSON format, eval the result before returning it.
					if(format.charAt(0) == "j") {
						//\n's in JSON string, when evaluated will create errors in IE
						result = result.replace(/[\n\r]/g,"");
						result = eval('('+result+')'); 
					}
	
					//Give the data to the callback function.
					if(callback) callback(result);
				} else { //An error occured
					if(error) error(http.status);
				}
			}
		}
		http.send(null);
	},
	init : function() {return this.getHTTPObject();}
}


function countryChange() {
	if (document.getElementById('country').value == 'US') {
		document.getElementById('spZip').innerHTML = '<span class="style2b">Zip:</span>';
		document.getElementById('trState').style.display = '';
		try{
			document.getElementById('trState0').style.display = '';
			}catch(err){}
	} else {
		document.getElementById('spZip').innerHTML = '<span class="style2b">Postal Code:</span>';
		document.getElementById('trState').style.display = 'none';
		try{
		document.getElementById('trState0').style.display = 'none';
		}catch(err){}
	}
}

function hidecountry()
{
	document.getElementById('trCountry').style.display='none';
	document.getElementById('trZip').style.display='none';
	document.getElementById('trState').style.display='none';
	document.getElementById('trCity').style.display='none';
	
	try
	{
	document.getElementById('trCountry0').style.display='none';
	document.getElementById('trZip0').style.display='none';
	document.getElementById('trState0').style.display='none';
	document.getElementById('trCity0').style.display='none';
		
	}catch(err){}
	
	
	}	
	
	function doblur()
{
var email1=document.getElementById('email').value;
jx.load('vemail.php?mail=' + email1,function(data){

var email=document.getElementById('email').value + "2";
		if(data ==email)
		{
		badmail=1;
		alert("Your Email Address Appears To Be Invalid, Please Correct It And Try Again.");document.getElementById('email').focus();
		var btype=getsubmitbutton().type;
				
				if(btype=='image')
				{
				getsubmitbutton().src="images/sign_up.png";
				}else
				{
				getsubmitbutton().value=oldbuttonvalue;
				}
		
		
		return false;
		
				
		
		}else
		{
		document.form1.submit();return true;	
		//return true;
		}
	});
}
	
	
	function getsubmitbutton() {
	var inputs = document.getElementsByTagName('input');
	for (var i = 0; i < inputs.length; i ++) {
		if (String(inputs[i].onclick).indexOf("validate_data")>0) {
			return inputs[i];
			
		}
	}
	return false;
}
	
	function fill_default()
	{
		
		
		
		if (typeof _dayxx=="undefined")
		{
			return false;
		}
	
		
		 
		document.getElementById('month').value=_month;
	//	alert(_year);
		document.getElementById('year').value=_year;
		
		//alert(_dayxx);
		if(_dayxx<10)_dayxx= "0" + _dayxx;
		//alert(_dayxx);
		document.getElementById('day').value=_dayxx;
		
		
		
		if(_countryxx=="US")
		{
			showcountry();
			}
			
		
		document.getElementById('country').value=_countryxx;
		//alert(_countryxx);
		
		if (typeof _statexx!="undefined")
		{
		document.getElementById('state').value=_statexx;
		}
     
		
	//alert(_statexx);

		if (typeof _badmail !="undefined")
		{
			if(_badmail==1)
			{
								document.getElementById('email_check').innerHTML = '*Invalid Email Address / Email Taken!!';
								document.getElementById('email_check').style.color='#f60';
								document.getElementById('email_check').style.display='block';
								
								document.getElementById('email').focus();
			}		
		}
		
		if (typeof _baduser !="undefined")
		{
			if(_baduser==1)
			{
				document.getElementById('username').focus();
			}		
		}
		
		
		
		
	}
	
function showcountry()
{
	
	document.getElementById('trCountry').style.display='';
	document.getElementById('trZip').style.display='';
	document.getElementById('trState').style.display='';
	document.getElementById('trCity').style.display='';
	//alert("dsf");
	try
	{
	document.getElementById('trCountry0').style.display='';
	document.getElementById('trZip0').style.display='';
	document.getElementById('trState0').style.display='';
	document.getElementById('trCity0').style.display='';
		
	}catch(err){}
	
	}

	
	function run_geoip()
	{
					
		_city=geoip_city();
		_postalcode=geoip_postal_code();
		_state=geoip_region();
		_country=geoip_country_code();
		
		if(_postalcode.length!=5)
			{
			return;
			}
		if(_country.length==2)
		{
					document.getElementById('country').value = _country;
					countryChange();

			}
					
			
			if(_city.length > 1)
			{
				
				document.getElementById('city').value = _city;
				}
				
				
				if(_state.length==2)
			{
				document.getElementById('state').value = _state;
				}
				
				if(_postalcode.length==5)
			{
				document.getElementById('postalcode').value = _postalcode;
				}
				
			
		
		if(_country.length==2 && _state.length==2 && _postalcode.length==5 && _city.length>1)
		{
				hidecountry();
					

			
			}else
			{
				showcountry();
				//hidecountry();
				}
		
		
		countryChange();
		
		if(_country.length==2 && _state.length==2 && _postalcode.length==5 && _city.length>1)
		{
				hidecountry();
		}
		}


function checkemail(email){
var str=email;
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
return true;
else{
return false;}
}


function validate_data()
{			//document.form1.submit();return true;	

		//	alert("b");
			var a= document.getElementById('username').value;
			
			if(a.length<5)
			{
		    alert("Username must be above 4 character length!");document.getElementById('username').focus();return false;
			}
			//	alert("c");
			
			
			
				if(checkemail(document.getElementById('email').value)==false)
				{
					alert("Your Email Address Appears To Be Invalid, Please Correct It And Try Again.");document.getElementById('email').focus();return false;					
				}			
	//	alert("d");	
		
		if (document.forms[0].year.value == "1992")
						{
						alert ("You must be at least 18 to signup.");document.forms[0].year.focus();return false;
						}			
			
	if(document.getElementById('city').value.length<2)
		{
		alert("Please write city name!");document.getElementById('city').focus();return false;				
		}
		//alert("e");						   
						if (document.getElementById('country').value == 'US')
							{
								if(document.getElementById('state').value=="")
								{
									alert("Please Select State!");document.getElementById('state').focus();return false;
								}																
							}
			//			alert("f");											
	if(document.getElementById('postalcode').value.length!=5)
	{
	alert("Invalid Postal/Zip code...");document.getElementById('postalcode').focus();return false;
	}
	
	oldbuttonvalue=getsubmitbutton().value;
	var btype=getsubmitbutton().type;
		if(btype=='image')
		{
		getsubmitbutton().src="submiting.png";
		}else
		{
		getsubmitbutton().value="Submitting..";
		}
	
	doblur();
	
	//alert("gg");	
	return false;
	//document.form1.submit();return true;	
	}

