function makeReq(elem, action, div) 
{
	el = document.getElementById(elem).value;
	dl = document.getElementById(div);

	var http_request = false;
	if (window.XMLHttpRequest) 
	{ 
		// Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) 
		{
			http_request.overrideMimeType('text/xml');
		}
	} 
	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('An unexpected error seems to have occured.');
		return false;
	}

	http_request.onreadystatechange = function() { alertContents(http_request, div); };

	var check_old_email = "";
	if(document.getElementById('check_old'))
		check_old_email = document.getElementById('check_old').value;

	var url="/z/registration/reg-check.php?action=" + escape(action) + "&val=" + escape(el) + "&z_get_valid_mail="+escape(check_old_email);
	
	switch(action) {
		case "checkemail":
			
			var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (!filter.test(el))  
			{
				dl.innerHTML = "<div style='width: 26px; float: left;'><img src='/zones-ssi/js-css-images/error.gif' width='18' height='16' border='0' hspace='4'><br></div><div style='width: 220px; float: left;' class='small red'>Please specify a valid Email Address</div><br clear='all'>";

				dl.style.display="block";
				return;
			} else 
			{
				dl.style.display="none";
			}
			//alert(http_request);
			//alert(url);
			http_request.open('GET', url, true);
			http_request.send(null);
			break;
		case "checknewemail":
			var old_email = "";
			
			if(document.getElementById('old_email'))
				old_email = document.getElementById('old_email').value;

			var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (!filter.test(el))  
			{
				dl.innerHTML = "<div style='width: 26px; float: left;'><img src='/zones-ssi/js-css-images/error.gif' width='18' height='16' border='0' hspace='4'><br></div><div style='width: 300px; float: left;' class='small red'>Please specify a valid Email Address.</div><br clear='all'>";

				dl.style.display="block";
				return;
			}
			else if(check_old_email != "N")
			{
				if(old_email == el)
				{
					dl.innerHTML = "<div style='width: 26px; float: left;'><img src='/zones-ssi/js-css-images/error.gif' width='18' height='16' border='0' hspace='4'><br></div><div style='width: 300px; float: left;' class='small red'>You have entered the same Email address again. Please try another Email address.</div><br clear='all'>";

					dl.style.display="block";
					return;
				}
			}
			else
			{
				dl.style.display="none";
			}
			http_request.open('GET', url, true);
			http_request.send(null);
			break;
		case "checkusername":
			//alert(el);
			if(el.length < 4) 
			{
				dl.innerHTML = "<div style='width: 26px; float: left;'><img src='/zones-ssi/js-css-images/error.gif' width='18' height='16' border='0' hspace='4'><br></div><div style='width: 220px; float: left;' class='small red'>Zone Name must be greater than 4 characters.</div><br clear='all'>";
				
				dl.style.display="block";
				return;
			}	
			if(el.length > 20) 
			{
				dl.innerHTML = "<div style='width: 26px; float: left;'><img src='/zones-ssi/js-css-images/error.gif' width='18' height='16' border='0' hspace='4'><br></div><div style='width: 220px; float: left;' class='small red'>Zone Name must be less than 20 characters.</div><br clear='all'>";

				dl.style.display="block";
				return;
			}	
			if(get_no_of_digit(el) > 4)
			{
				dl.innerHTML = "<div style='width: 26px; float: left;'><img src='/zones-ssi/js-css-images/error.gif' width='18' height='16' border='0' hspace='4'><br></div><div style='width: 220px; float: left;' class='small red'>Zone name cannot contain more than 4 digits.</div><br clear='all'>";

				dl.style.display="block";
				return;
			}
			var filter  = /^[a-zA-Z0-9_\-]{4,20}$/;
			if (!filter.test(el))  
			{
				dl.innerHTML = "<div style='width: 26px; float: left;'><img src='/zones-ssi/js-css-images/error.gif' width='18' height='16' border='0' hspace='4'><br></div><div style='width: 220px; float: left;' class='small red'>Zone name cannot contain spaces or special characters <br>like [ $ @ * % & ]</div><br clear='all'>";

				dl.style.display="block";
				return;
			}	
			len = el.length;
			if ((el.indexOf("-") == 0)||(el.indexOf("-") == len-1)||(el.indexOf("_") == 0)||(el.indexOf("_") == len-1))
			{
				dl.innerHTML = "<div style='width: 26px; float: left;'><img src='/zones-ssi/js-css-images/error.gif' width='18' height='16' border='0' hspace='4'><br></div><div style='width: 220px; float: left;' class='small red'>Zonename cannot start and end with \"_\" or \"-\"</div><br clear='all'>";

				dl.style.display="block";
				return;
			}
			
			email = document.getElementById('email').value;
			part1 = "";

			if(email != "") 
			{
				at = email.indexOf("@");
				if(at != -1) 
				{
					part1 = email.substring(0,at);
					if(part1 == el) 
					{
						dl.innerHTML = "<div style='width: 26px; float: left;'><img src='/zones-ssi/js-css-images/error.gif' width='18' height='16' border='0' hspace='4'><br></div><div style='width: 220px; float: left;' class='small red'>Zone Name cannot be similar to Email Address</div><br clear='all'>";
						
						dl.style.display="block";
						return;
					}
				}
			}
			
			dd		= document.getElementById('day');
			mm		= document.getElementById('month');
			yy		= document.getElementById('year');

			if (document.getElementById('day').type == "hidden")
				day     = dd.value;
			else
				day     = dd.options[dd.selectedIndex].value;
			
			if (document.getElementById('month').type == "hidden")
				month     = mm.value;
			else
				month   = mm.options[mm.selectedIndex].value;

			if (document.getElementById('year').type == "hidden")
				year     = yy.value;
			else
				year     = yy.options[yy.selectedIndex].value;
			cn      = document.getElementById('country_nm').value;
						
			url = url + "|"+escape(day)+"|"+escape(month)+"|"+escape(year)+"|"+escape(cn)+"|"+escape(part1);
						
			//alert(url);
			
			//exit;
			http_request.open('GET', url, true);
			http_request.send(null);
			break;
		case "checkpassword":
			var filter  = /^[a-zA-Z0-9_\-]{4,20}$/;
			if(el.length < 4) 
			{
				dl.innerHTML = "<div style='width: 26px; float: left;'><img src='/zones-ssi/js-css-images/error.gif' width='18' height='16' border='0' hspace='4'><br></div><div style='width: 220px; float: left;' class='small red'>Please specify Password with minimum of 4 characters.</div><br clear='all'>";

				dl.style.display="block";
				return;
			} 			
			else if (!filter.test(el))  
			{
				dl.innerHTML = "<div style='width: 26px; float: left;'><img src='/zones-ssi/js-css-images/error.gif' width='18' height='16' border='0' hspace='4'><br></div><div style='width: 220px; float: left;' class='small red'>Password cannot contain spaces or special characters <br>like [ $ @ * % & ]</div><br clear='all'>";

				dl.style.display="block";
				return;
			}	
			else 
			{
				dl.style.display="none";
			}
			
			zn = document.getElementById('zonename').value;
			
			if(el == zn) 
			{
				dl.innerHTML = "<div style='width: 26px; float: left;'><img src='/zones-ssi/js-css-images/error.gif' width='18' height='16' border='0' hspace='4'><br></div><div style='width: 220px; float: left;' class='small red'>The password is the same as your Zone Name. Please specify another password.</div><br clear='all'>";
				
				dl.style.display="block";
				return;
			}
			else 
			{
				dl.style.display="none";
			}
			break;

		case "checkconfirmpassword":
			var passwd = document.getElementById('password').value;
			
			if(el != passwd) 
			{
				dl.innerHTML = "<div style='width: 26px; float: left;'><img src='/zones-ssi/js-css-images/error.gif' width='18' height='16' border='0' hspace='4'><br></div><div style='width: 220px; float: left;' class='small red'>Re-entered Password does not match Password.</div><br clear='all'>";

				dl.style.display="block";
				return;
			} 
			else 
			{
				dl.style.display="none";
			}
			break;
		case "checkname":			
			var filter  = /^([a-zA-Z\'])+$/;
			if (!filter.test(el))  
			{
				dl.innerHTML = "<div style='width: 26px; float: left;'><img src='/zones-ssi/js-css-images/error.gif' width='18' height='16' border='0' hspace='4'><br></div><div style='width: 220px; float: left;' class='small red'>Please do not use spaces and/or special characters [ $ @ * % & ] in this field.</div><br clear='all'>";

				dl.style.display="block";
				return;
			}
			else if (el.length > 20)  
			{
				if(elem == 'fname')
					var elem_name = 'First Name';

				if(elem == 'lname')
					var elem_name = 'Last Name';

				dl.innerHTML = "<div style='width: 26px; float: left;'><img src='/zones-ssi/js-css-images/error.gif' width='18' height='16' border='0' hspace='4'><br></div><div style='width: 220px; float: left;' class='small red'>"+elem_name+" must be less than 20 characters.</div><br clear='all'>";
				
				dl.style.display="block";
				return;
			}
			else {
				dl.style.display="none";
			}
			break;
		case "fullname" :
			total_word = 0;
			word_arr = el.split(" ");
			firstname = "";
			lastname = "";
			for(i=0;i<word_arr.length;i++)
			{
				if(word_arr[i]!="")
				{
					if(firstname == "")
						firstname = word_arr[i];
					else if(lastname == "")
						lastname = word_arr[i];
					total_word++;
				}
			}
			if(total_word < 2)
			{
				dl.innerHTML = "<div style='width: 26px; float: left;'><img src='/zones-ssi/js-css-images/error.gif' width='18' height='16' border='0' hspace='4'><br></div><div style='width: 220px; float: left;' class='small red'>Please enter your full name.</div><br clear='all'>";
				
				dl.style.display="block";
				return;
			}
			else if(total_word > 2)
			{
				dl.innerHTML = "<div style='width: 26px; float: left;'><img src='/zones-ssi/js-css-images/error.gif' width='18' height='16' border='0' hspace='4'><br></div><div style='width: 220px; float: left;' class='small red'>Please enter your First Name and Last Name only.</div><br clear='all'>";
				
				dl.style.display="block";
				return;
			}
			else
			{
				var filter  = /^([a-zA-Z\'])+$/;
				if (!filter.test(firstname) || !filter.test(lastname))  
				{
					dl.innerHTML = "<div style='width: 26px; float: left;'><img src='/zones-ssi/js-css-images/error.gif' width='18' height='16' border='0' hspace='4'><br></div><div style='width: 220px; float: left;' class='small red'>Please do not use special characters[@,#,$,%,^] or numbers in this field.</div><br clear='all'>";

					dl.style.display="block";
					return;
				}
				else if (firstname.length > 20 || lastname.length > 20)  
				{
					dl.innerHTML = "<div style='width: 26px; float: left;'><img src='/zones-ssi/js-css-images/error.gif' width='18' height='16' border='0' hspace='4'><br></div><div style='width: 220px; float: left;' class='small red'>First Name and/or Last name cannot be more than 20 characters.</div><br clear='all'>";
					
					dl.style.display="block";
					return;
				}
				else {
					dl.style.display="none";
				}
			}
			break;
	}
}

function getZonenameSuggestions(http_request,div)
{
	dd		= document.getElementById('day');
	mm		= document.getElementById('month');
	yy		= document.getElementById('year');
	day		= dd.options[dd.selectedIndex].value;
	month	= mm.options[mm.selectedIndex].value;
	year	= yy.options[yy.selectedIndex].value;
	
	cn = document.getElementById('country');
	country = cn.options[cn.selectedIndex].value;
	
	//url = url + "|"+escape(day)+"|"+escape(month)+"|"+escape(year)+"|"+escape(part1)+"|"+escape(country);
}
function check_zonename() {

}

function valid_email(email) {
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(email);
}

function valid_name(name) {
	var filter  = /^([a-zA-Z\'])+$/;
	return filter.test(name);
}

function valid_date(dd,mm,yy) {

	var myDate = new Date();
	myDate.setFullYear( yy, mm, dd );
	return ( myDate.getMonth() == mm );
}

function checkform() {
	var error = "";
	email = document.getElementById('email').value;
	if(email == "") {
		error+="Please enter the Email Address.\n";
	} else {
		if(!valid_email(email)) 
			error+="Please specify a valid Email Address.\n";
	}
	
	fname = document.getElementById('fname').value;
	if(fname == "") {
		error+="Please enter the First Name.\n";
	} else {
		if(!valid_name(fname)) 
			error+="Please do not use spaces and/or special characters [$@&%&] in this field.\n";
	}
	lname = document.getElementById('lname').value;
	if(lname == "") {
		error+="Please enter the Last Name.\n";
	} else {
		if(!valid_name(lname)) 
			error+="Please do not use spaces and/or special characters [$@&%&] in this field.\n";
	}

	dd = document.getElementById('day');
	mm = document.getElementById('month');
	yy = document.getElementById('year');
	day		= dd.options[dd.selectedIndex].value;
	month	= mm.options[mm.selectedIndex].value;
	year	= yy.options[yy.selectedIndex].value;
	if(!valid_date(day,month,year)) {
		error+="Please enter a valid Birth Date\n";
	}

	rel = document.getElementById('relation');
	relation		= rel.options[rel.selectedIndex].value;
	if(rel == "") {
		error+="Please enter the Relationship Status\n";
	}

	cc = document.getElementById('country');
	country		= cc.options[cc.selectedIndex].value;
	if(country == "") {
		error+="Please enter the Country\n";
	}

	if(country = "208" || country=="89") {
		st = document.getElementById('state');
		state		= st.options[st.selectedIndex].value;
		if(state == "") {
			error+="Please enter the State\n";
		}
	}
	city = document.getElementById('city').value;
	if(city == "") {
		error+="Please enter the City\n";
	}
	
	el = document.getElementById('zonename').value;
	if(el == "") {
		error += "Please enter the Zone Name.\n";
	} else {
		if(el.length < 4) {
			error+="Zone Name must be greater than 4 characters.\n";
		} else {
			var filter  = /^[a-zA-Z0-9_\-]{4,20}$/;
			if (!filter.test(el))  
			{
				error+="Zone name cannot contain spaces or special characters like [~`!#$%^&*()+=|\\}]{[\"':;?/>.<,@]\n";
			} else {
				len = el.length;
				if ((el.indexOf("-") == 0)||(el.indexOf("-") == len-1)||(el.indexOf("_") == 0)||(el.indexOf("_") == len-1))
				{
					error+="Zonename cannot start and end with \"_\" or \"-\"\n";
				} else {
					email = document.getElementById('email').value;
					part1 = "";
					if(email != "") {
						at = email.indexOf("@");
						if(at != -1) {
							part1 = email.substring(0,at);
							if(part1 == el) {
								error+="Zone Name cannot be similar to Email Address\n";
							}
						}
					}
				}
			}
		}
	}

	password = document.getElementById('password').value;
	if(password == "") {
		error += "Please enter the Password\n";
	} else {
		if(password.length <4) {
			error+= "Please specify Password with minimum of 4 characters.\n";
		} else {
			if(password == el) {
				error += "The password is the same as your Zone Name. Please specify another password.\n";
			} else {
				// check the password confirmation
				confirm = document.getElementById('confirm').value;
				if(confirm != password) {
					error+="Re-entered Password does not match Password.\n";
				}
			}
		}
	}
	ver = document.getElementById('verifycode').value;
	if(ver == "") {
		error += "Please enter the Verification Code.\n";
	}
	if(!document.getElementById('tos').checked) {
		error+="Please read and accept the Fropper 'Terms of Use' Agreement.\n";
	}
	
	if(error !="") {
		alert(error);
		return false;
	} else {
		return true;
	}
	
}

function alertContents(http_request,div) 
{
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			if(http_request.responseText!= "") {
				document.getElementById(div).innerHTML=http_request.responseText;
				document.getElementById(div).style.display="block";
			} else {
				document.getElementById(div).style.display="none";
			}
		} else {
			document.getElementById(div).style.display="block";
			document.getElementById(div).innerHTML='An unexpected error has occured.';
		}
	} else {
		document.getElementById(div).style.display="block";
		
		document.getElementById(div).innerHTML="<div style='width: 220px; float: left;' class='small red'>Please Wait...</div><br clear='all'>";

		
	}

}

function get_no_of_digit(str)
{

	var i = 0;
	var num=0;
	for(i=0; i<str.length; i++)
	{
		if(!isNaN(str[i]))
		{
			num++;
		}
	}
	return num;
}

function resent_email(frm)
{	
	frm.submit();
}