// 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();
	}
}
/***************************Printing page **********************************/

function disprushjobradio(val)
{
  document.getElementById('hidquantity').value = val;
  if(val=='OPTION_CHOOSE')
  {  document.getElementById('rad_rushjob').style.display ='none';}
  else
  { document.getElementById('rad_rushjob').style.display ='';  }
}
function disp_color_quantity(value)
{
  if(value==-1)
  {
	  document.getElementById('dispcolor1').style.display ='none';
	  document.getElementById('dispcolor').style.display ='';

	  document.getElementById('dispquentity1').style.display ='none';
	  document.getElementById('dispquentity').style.display ='';

  }
  else
  {
   document.getElementById('dispcolor1').style.display ='';
   document.getElementById('dispcolor').style.display ='none';

	document.getElementById('dispquentity').style.display ='none';
	document.getElementById('dispquentity1').style.display ='';

  }
}
function disp_quentity(val)
{
   document.getElementById('hidcolor').value = val;
  if(val==-1)
  {
      document.getElementById('dispquentity1').style.display ='none';
	  document.getElementById('dispquentity').style.display ='';
  }
  else
  {
     document.getElementById('dispquentity').style.display ='none';
	 document.getElementById('dispquentity1').style.display ='';

  }

}
function showQuentity(strval)
{
    xmlhttp=GetXmlHttpObject();
	 if (xmlhttp==null)
	  {
	  alert ("Your browser does not support XMLHTTP!");
	  return;
	  }
	 if((strval=='F') || (strval=='FB') || (strval=='BS') )
	 {
	   var radvalstand =   document.getElementById("standard").checked;
		   var radvalrush =   document.getElementById("rushjob").checked;
		   if(radvalstand==true)
		   {
		      var turntimeval = 'S';
		   }
		   else if(radvalrush == true)
		   {
		        var turntimeval = 'R';
		   }

		  var roundcor = document.getElementById("round_corners").checked;
	      if(roundcor==true)
		  {
		     roundcorval = 'RC';
		  }
		  else if(roundcor==false)
		  {
		    roundcorval = '';
		  }

		    var sel = document.getElementById("printQue");
			var  queval = sel.options[sel.selectedIndex].value;
		     var url="printing.ajax.php";
		     url=url+"?strvalue="+queval+"&turntimeval="+turntimeval+"&roundcorner="+roundcorval+"&colortype="+strval;
	 }
   else if(strval =='round_corners')
	 {

	      var radvalstand =   document.getElementById("standard").checked;
		   var radvalrush =   document.getElementById("rushjob").checked;
		   if(radvalstand==true)
		   {
		      var turntimeval = 'S';
		   }
		   else if(radvalrush == true)
		   {
		        var turntimeval = 'R';
		   }

		  var roundcor = document.getElementById("round_corners").checked;
	      if(roundcor==true)
		  {
		     roundcorval = 'RC';
		  }
		  else if(roundcor==false)
		  {
		    roundcorval = '';
		  }

		    var sel = document.getElementById("printQue");
			var  queval = sel.options[sel.selectedIndex].value;

		   var selcolor = document.getElementById("printcolor");
		   var  colortype = selcolor.options[selcolor.selectedIndex].value;


				var url="printing.ajax.php";
				url=url+"?strvalue="+queval+"&turntimeval="+turntimeval+"&roundcorner="+roundcorval+"&colortype="+colortype;

	 }
	 else
	 {
	   var roundcor = document.getElementById("round_corners").checked;
	      if(roundcor==true)
		  {
		     roundcorval = 'RC';
		  }
		  else if(roundcor==false)
          { roundcorval = ''; }

       if(strval=='R')
	   {
			var sel = document.getElementById("printQue");
			var  queval = sel.options[sel.selectedIndex].value;

			var selcolor = document.getElementById("printcolor");
		   var  colortype = selcolor.options[selcolor.selectedIndex].value;


			  var roundcor = document.getElementById("round_corners").checked;

			  if(roundcor==true)
			  {
				 roundcorval = 'RC';
			  }
			  else if(roundcor==false)
			  { roundcorval = ''; }

			 var url="printing.ajax.php";
			url=url+"?strvalue="+queval+"&turntimeval="+strval+"&roundcorner="+roundcorval+"&colortype="+colortype;
	   }
	   else if (strval=='S')
	   {
	        var sel = document.getElementById("printQue");
			var  queval = sel.options[sel.selectedIndex].value;

			var selcolor = document.getElementById("printcolor");
		   var  colortype = selcolor.options[selcolor.selectedIndex].value;

			 var roundcor = document.getElementById("round_corners").checked;
			  if(roundcor==true)
			  {
				 roundcorval = 'RC';
			  }
			  else if(roundcor==false)
			  { roundcorval = ''; }



			var url="printing.ajax.php";
			url=url+"?strvalue="+queval+"&turntimeval="+strval+"&roundcorner="+roundcorval+"&colortype="+colortype;
	   }

	   else if( roundcorval == 'RC')
	   {

		   var radvalstand =   document.getElementById("standard").checked;
		   var radvalrush =   document.getElementById("rushjob").checked;
		   if(radvalstand==true)
		   {
		      var turntimeval = 'S';
		   }
		   else if(radvalrush == true)
		   {
		        var turntimeval = 'R';
		   }

		    var sel = document.getElementById("printQue");
			var  queval = sel.options[sel.selectedIndex].value;

		   var selcolor = document.getElementById("printcolor");
		   var  colortype = selcolor.options[selcolor.selectedIndex].value;
		   var url="printing.ajax.php";
			url=url+"?strvalue="+queval+"&turntimeval="+turntimeval+"&roundcorner="+roundcorval+"&colortype="+colortype;
	  }
	   else
	   {
	       var radvalstand =   document.getElementById("standard").checked;
		   var radvalrush =   document.getElementById("rushjob").checked;
		   if(radvalstand==true)
		   {
		      var turntimeval = 'S';
		   }
		   else if(radvalrush == true)
		   {
		        var turntimeval = 'R';
		   }

		  var roundcor = document.getElementById("round_corners").checked;
	      if(roundcor==true)
		  {
		     roundcorval = 'RC';
		  }
		  else if(roundcor==false)
		  {
		    roundcorval = '';
		  }

		    var sel = document.getElementById("printQue");
			var  queval = sel.options[sel.selectedIndex].value;

			var selcolor = document.getElementById("printcolor");
		   var  colortype = selcolor.options[selcolor.selectedIndex].value;


				var url="printing.ajax.php";
				url=url+"?strvalue="+strval+"&turntimeval="+turntimeval+"&roundcorner="+roundcorval+"&colortype="+colortype;
	   }

	}
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
return true;
}

function stateChanged()
{
   if(xmlhttp.readyState==1)
     {
       ProcessLoader();
     }

	if (xmlhttp.readyState==4)
	  {
	     document.getElementById("val_print_total").innerHTML = xmlhttp.responseText;
		 document.getElementById("val_total").value = xmlhttp.responseText;
		 document.getElementById('dvprocessing').style.display='none';
		document.getElementById('dimmer').style.width=0;
		document.getElementById('dimmer').style.height=0;
		document.getElementById('dimmer').style.visibility="hidden";
	  }
}
function ChkValid()
{
 if(document.frmprint.paper.value == "-1")
 	{
		alert(" Please Select Paper Type");
		document.frmprint.paper.focus();
		return false;
	}
	else if(document.getElementById('printcolor').value == "-1")
 	{
		 alert("Please Select Color Type");
		 document.getElementById('printcolor').focus();
		 return false;
	}
	else if(document.getElementById('printQue').value == "OPTION_CHOOSE")
 	{
		 alert("Please Select Quantity");
		 document.getElementById('printQue').focus();
		return false;
	}
   else if (document.frmprint.chkagree.checked == false)
    {
		alert("Please Accept Terms & Conditions");
		document.frmprint.chkagree.focus();
		return false;
	}
	return true;
}


function onlyNumeric(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode
	//alert(charCode);
	
	if(charCode == 40 || charCode == 41 || charCode == 45 || charCode == 32)
	{
		return true;
	}
	else if (charCode > 31 && (charCode < 48 || charCode > 57))
	{
		return false;
	}
	else
	{
		return true;
	}
}

function clearrandomcode()
{
	if(document.getElementById('txtimage_quote').value =='Enter code')
	{  
		document.getElementById('txtimage_quote').focus();
		document.getElementById('txtimage_quote').value = "";
	}
}

function ChkValid_contact()
{
 if(document.frmprint.txtname.value == "")
	{
		alert("Please Enter Name");
		document.frmprint.txtname.focus();
		return false;
	}
    else if(document.frmprint.txtphone.value == "")
	{
		alert("Please Enter Phone Number");
		document.frmprint.txtphone.focus();
		return false;
	}
   else  if (document.frmprint.txtemail.value == "")
    {
		alert("Please Enter Email Address");
		document.frmprint.txtemail.focus();
		return false;
	}
   if (!checkemail1(document.getElementById('txtemail').value))
    {
        alert("Please enter a valid email address");
        document.frmprint.txtemail.focus();
        return false;
    }
	return true;
}

function pressescapekey(evt)
{
  var key=(window.event) ? event.keyCode : evt.which;
  if(key==27)
    {
       closeSlidePanel('formElement');
    }
	
}

