// JavaScript Document
var xmlHttp = null;
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
	// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
	//Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function checkuserexists(ids)
{
	//var username1 = ids;
	var value = ids.split("/");
	//alert(value[0]);
	//alert(ids.split("/"));
	var username1 = value[1];
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
		var url="checkuser.php"+"?value="+value[0];
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		xmlHttp.onreadystatechange=function()
		{
		if(xmlHttp.readyState==4)
		{
			//alert(xmlHttp.responseText);
			if(xmlHttp.responseText!=0)
			{
				document.getElementById('sCmnErr3').style.display='block';
				//document.getElementById('sCmnErr3').innerHTML='Username '+value[0]+' not available. Try another.<br><span style="color:#000000">A unique username is mandatory to register successfully.</span>';
				document.getElementById('sCmnErr3').style.color='#FF0000';
				checkuser = checkname('notavailable');
				document.getElementById('sCmnErr3').innerHTML= checkuser.replace('%username%',value[0]);
				document.getElementById('green').style.display = "none";
				document.getElementById('username_img').style.display = "none";
			}
			else
			{
				document.getElementById('green').style.display='block';
				document.getElementById('username_img').style.display='';
				//document.getElementById('green').innerHTML='<br>Username '+value[0]+' available.';
				//document.getElementById('green').innerHTML=fnAlphabetUN('username1','username1_msg','TD','register_username_available');
				document.getElementById('green').style.color='#04B404';
				checkuser = checkname('available');
				document.getElementById('green').innerHTML=checkuser.replace('%username%',value[0]);;
				document.getElementById('sCmnErr3').style.display = "none";
			}
		}
	
	}
}

function checkemailexists(usermail)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
		var url="checkuser.php"+"?email="+usermail;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		xmlHttp.onreadystatechange=function()
	{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.responseText!=0)
		{	
			document.getElementById('sCmnErr4').style.display='block';
			document.getElementById('email_availability').style.display='none';
			//document.getElementById('sCmnErr4').innerHTML='Email '+usermail+' not available. Try another.<br><span style="color:#000000">A unique usermail is mandatory to register successfully.</span>';
			document.getElementById('sCmnErr4').style.color='#FF0000';
			checkmailavailability = checkmail('notavailable');
			document.getElementById('sCmnErr4').innerHTML=checkmailavailability;
		}
		else
		{
			//document.getElementById('email_availability').style.display='block';
			document.getElementById('sCmnErr4').style.display='none';
			//document.getElementById('email_availability').innerHTML='<br>Email '+usermail+' available';
			//document.getElementById('email_availability').style.color='#04B404';
			checkmailavailability = checkmail('available');
			//document.getElementById('email_availability').innerHTML=checkmailavailability;
		}
	}
	
	}
}

function checkphone(phoneno)
{
	//var x=document.getElementById("serivceType").value;
	//alert(document.registration.serivceType.value);	
	var val = phoneno.split(' ').join('');
	var val = val.replace(/[^0-9 ] +.-/g,'');
	val = val.replace('(','');
	val = val.replace(')','');
	val = val.replace('-','');
	val = val.replace('+','');
	val = val.replace('.','');
	val = val.replace(' ','');
	//if(val.substr(0,1) == 9)
	//alert(val);
	if(val.length == 10)
		var newval = '('+ val.substr(0,3) + ') ' + val.substr(3,3) + '-' + val.substr(6,11);
	else
		var newval = val;
	document.getElementById('phone').value = newval;
}