// JavaScript Document
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		xmlHttp=new XMLHttpRequest();
	}
	catch(e)
	{
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

/************** Show ip info ****************/

/*******************************************/

function checkemail1(str)
{
	var testresults;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	
	if (filter.test(str))
		testresults=true
	else
		testresults=false

	return (testresults)
}

/*********** Ajax Loader New *************/
function ProcessLoader()
{
	document.getElementById('dvprocessing').style.display = '';
}
/****************************************/


function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function body_onkeydown(evt)
{
	//alert(evt);
	var key = (evt.which) ? evt.which : event.keyCode
	if(key==27)
	{
		styledPopupClose();
	}
}

function CalculateTop(Height)
{
	var ScrollTop=document.body.scrollTop;
	if(ScrollTop==0)
	{
		if(window.pageYOffset)
			ScrollTop=window.pageYOffset;
		else
			ScrollTop=(document.body.parentElement)?document.body.parentElement.scrollTop:0;
	}

	var BodyHeight=document.body.clientHeight;
	
	if(BodyHeight==0)
	{
		BodyHeight=window.innerHeight;
	}
	if(BodyHeight==0)
	{
		BodyHeight=document.documentElement.clientHeight
	}

	var myWidth = 0, myHeight = 0;
  	if( typeof( window.innerWidth ) == 'number' ) 
	{
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} 
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	{
    //IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
	{
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}

	var FinalTop=((myHeight-Height)/2)+ScrollTop;
	
	return FinalTop;
}

function CalculateLeft(Weight)
{
	var ScrollLeft=document.body.scrollLeft;
	
	if(ScrollLeft==0)
	{
		if(window.pageXOffset)
			ScrollLeft=window.pageXOffset;
		else
			ScrollLeft=(document.body.parentElement)?document.body.parentElement.scrollLeft:0;
	}
	
	var BodyWeight=document.documentElement.clientWidth;
	
	if(BodyWeight==0)
	{
		BodyWeight=document.body.clientWidth;
	}
	
	var FinalLeft=(BodyWeight+ScrollLeft-Weight)/2;
	
	return FinalLeft;
}

/***************** Setting the Dimmer while loading *********************/
function SetBackground()
{
	document.getElementById('dimmer').style.width=GetBodyWidth();
	document.getElementById('dimmer').style.height=GetBodyHeight();
	document.getElementById('dimmer').style.visibility="visible";
}
/***********************************************************************/
function init()
{
	isMozilla=(document.all)?0:1;
	if(isMozilla)
	{
		document.captureEvents(Event.MOUSEDOWN|Event.MOUSEMOVE|Event.MOUSEUP);
	}
}

init();

/************* Hide/unhide iframe for popups ****************/
function hideIframe()
{
	if(ie)
	{
		var theIframe=document.getElementById("fadeboxiframe")
		theIframe.style.display="none";
	}
}


function unhideIframe()
{
	if(ie)
	{
		var theIframe=document.getElementById("fadeboxiframe")
		var theDiv=document.getElementById("dvregisterfrm");
		theIframe.style.width=theDiv.offsetWidth+'px';
		theIframe.style.height=theDiv.offsetHeight+'px';
		theIframe.style.top=theDiv.offsetTop+'px';
		theIframe.style.left=theDiv.offsetLeft+'px';
		theIframe.style.display='';
	}
}
/***********************************************************/

function GetBodyWidth()
{
	var theWidth=0;
	if(document.body)
	{
		theWidth=document.body.clientWidth;
	}
	else if(document.documentElement&&document.documentElement.clientWidth)
	{
		theWidth=document.documentElement.clientWidth;
	}
	else if(window.innerWidth)
	{
		theWidth=window.innerWidth;
	}
	
	theWidth=theWidth-85;
	
	return theWidth+ "px";
}

function GetBodyHeight()
{
	var theHeight1=0;
	var theHeight2=0;
	var theHeight3=0;
	if(window.innerHeight)
	{
		theHeight1=window.innerHeight;
	}
	if(document.documentElement&&document.documentElement.clientHeight)
	{
		theHeight2=document.documentElement.clientHeight;
	}
	if(document.body)
	{
		theHeight3=document.body.clientHeight;
		if(isMozilla)
		{
			theHeight4=0;
		}
		else
		{
			theHeight4=document.body.scrollHeight;
		}
	}
	
	FinalHeight=Math.max(theHeight1,theHeight2,theHeight3,theHeight4);
	FinalHeight=FinalHeight-85;
	return FinalHeight+ "px";
}

/***************** Allow only Numeric **********************/
function KeycheckOnlyNumeric(e)
{
   var _dom = 0;
    _dom=document.all?3:(document.getElementById?1:(document.layers?2:0));
    if(document.all) e=window.event; // for IE
    var ch='';
    var KeyID = '';
    //alert(_dom);
    if(_dom==2){                     // for NN4
        //alert(e.which);
        if(e.which>0) ch='('+String.fromCharCode(e.which)+')';
        KeyID=e.which;
    }
    else
    {
        if(_dom==3){                   // for IE
            KeyID = (window.event) ? event.keyCode : e.which;
        }
        else {                       // for Mozilla
            //alert('Mozilla:' + e.charCode);
            if(e.charCode>0) ch='('+String.fromCharCode(e.charCode)+')';
            KeyID=e.charCode;
        }
    }
    
    if((KeyID >= 65 && KeyID <= 90) || (KeyID >= 97 && KeyID <= 122) || (KeyID >= 33 && KeyID <= 47) || (KeyID >= 58 && KeyID <= 64) || (KeyID >= 91 && KeyID <= 96) || (KeyID >= 123 && KeyID <= 126))	
    {
        //alert("hello");
        return false;
    }
    
    
    return true;
}
function check_email_availability()
{
    var emailid = document.getElementById('txtemail').value;
    if(checkemail1(emailid))
    {
        xmlHttp=GetXmlHttpObject()
        if(xmlHttp==null)
        {
        alert("Browser does not support HTTP Request")
        return
        }
        document.getElementById('checkemailavailability').style.display = '';
        document.getElementById('checkemailavailability').innerHTML = "<img src=\"images/throbber.gif\" border=\"0\">";//throbber.gif
        
        var url="steps.php?chkemailavail=true&email="+emailid;
        xmlHttp.onreadystatechange=stateChangedemailavailability
        xmlHttp.open("GET",url,true)
        xmlHttp.send(null)
    }
    else
    {
        alert('Please enter valid email address');
        document.getElementById('txtemail').focus();
    }
    
}

function stateChangedemailavailability()
{
	if((xmlHttp.readyState==4||xmlHttp.readyState=="complete")&&(xmlHttp.status==200))
	{
		var result = xmlHttp.responseText;
        if(result==1)
        {
            alert('You are already a user, please login.');
            location.href = 'login.php?msg=8';
        }
        else
        {
          document.getElementById('checkemailavailability').innerHTML = "<img src=\"images/right-click.png\" border=\"0\">";//throbber.gif
        }
		unhideIframe();
	}
}
/*************************************************************/

function pressescapekey(evt)
{
  var key=(window.event) ? event.keyCode : evt.which;
  if(key==27)
    {
       closeSlidePanel('formElement');
    }
	
}

