var sessiontoken	= "/s/";
/* 
	var secureprefix 	= "http://192.168.1.213";
	var regularprefix 	= "http://192.168.1.213";
	var secure128prefix = "http://192.168.1.213";
	var archiveprefix   = "http://192.168.1.213";
	var sessiontoken	= "/s/";
 */
/* Production settings */
	var secureprefix 	= "https://www.navicpmart.com";
	var regularprefix 	= "http://www.navicpmart.com";
	var secure128prefix = "https://secure.navicpmart.com";
	var archiveprefix   = "http://archive.navicpmart.com";
	var sessiontoken	= "/s/";
/**/

	function open_window(url) 
	{
		if (((new String(url)).indexOf("http") == -1) && ((new String(url)).indexOf("http") == -1))
			url = "http://" + url;
		
		window.open(url,"win",'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=500,height=500,top='+((screen.height - 500)/2)+',left='+((screen.width - 500)/2));
	}

	
	function trim(txtObj)
	{
		// trim leading spaces
		while(''+txtObj.value.charAt(0)==' ')
			txtObj.value=txtObj.value.substring(1,txtObj.value.length);		
			
		// trim trailing spaces
		while(''+txtObj.value.charAt(txtObj.value.length-1)==' ')
			txtObj.value=txtObj.value.substring(0,txtObj.value.length-1);
			
		return 	txtObj.value;
	}

	function emailCheck (emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
//	alert("Email address seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
//    alert("The username doesn't seem to be valid.")
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
//	        alert("Destination IP address is invalid!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
//	alert("The domain name doesn't seem to be valid.")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   //alert("The address must end in a three-letter domain, or two letter country.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
//   alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}



	
	var secPages = new Array();	
	secPages[0] = "personaltmp.cfm";
	secPages[1] = "shippingtmp.cfm";
	secPages[2] = "billingtmp.cfm";
	secPages[3] = "shipdtl.cfm";
	secPages[4] = "payinfo.cfm";
	secPages[5] = "paydtl.cfm";
	secPages[6] = "orderverify.cfm";
	secPages[7] = "reqconfirm.cfm";
	secPages[8] = "loginvalidate.cfm";
	secPages[9] = "registration.cfm";
	secPages[10] = "regconfirm.cfm";
	secPages[11] = "login.cfm";	
	secPages[12] = "shippingmethod.cfm";
	secPages[13] = "creditcard.cfm";
	secPages[14] = "purchaseorder.cfm";
	secPages[15] = "shippinginfo.cfm";
	secPages[16] = "reqcreditaccount.cfm";
	secPages[17] = "otherpayment.cfm";
	secPages[18] = "notices.cfm";
	secPages[19] = "noticestmp.cfm";
	secPages[20] = "myprofile.cfm";
	secPages[21] = "personal.cfm";
	secPages[22] = "shipbill.cfm";	
	secPages[23] = "reqlist.cfm";	
	secPages[24] = "browsertest.cfm";	
	secPages[25] = "selectvalidate.cfm";

	function isSecured(actionTxt,targetPageStr)
	{		
		for (var i=0; i < secPages.length ; i++)
			if (((new String(actionTxt)).indexOf(secPages[i]) > -1) || ((new String(targetPageStr)).indexOf(secPages[i]) > -1))
				return true;
				
		return false;
	}

	function linkSubmitForm0(actionTxt,targetPageStr,paramValue1,paramValue2,paramValue3,paramValue4,paramValue5)
	{
		var str = navigator.userAgent; 
		if (navigator.appName != 'Microsoft Internet Explorer')
		{ 
				document.forms[0].targetPage.value = targetPageStr;	
				document.forms[0].param1.value = paramValue1;
				document.forms[0].param2.value = paramValue2;
				document.forms[0].param3.value = paramValue3;
				document.forms[0].param4.value = paramValue4;
				document.forms[0].param5.value = paramValue5;
		}
		else 
		{
			document.forms[0].targetPage.value = targetPageStr;			
			document.forms[0].param1.value = paramValue1;
			document.forms[0].param2.value = paramValue2;
			document.forms[0].param3.value = paramValue3;
			document.forms[0].param4.value = paramValue4;
			document.forms[0].param5.value = paramValue5;
		}
			
		if (actionTxt == "")
			actionTxt = document.forms[0].pageName.value;

		if (isSecured(actionTxt,targetPageStr))
			document.forms[0].action = secureprefix + actionTxt;
		else
			document.forms[0].action = regularprefix + actionTxt;
			
		document.forms[0].submit();
	}


	function linkSubmitForm(actionTxt,targetPageStr,paramValue1,paramValue2,paramValue3,paramValue4,paramValue5)
	{
		document.forms[1].targetPage.value = targetPageStr;			
		document.forms[1].param1.value = paramValue1;
		document.forms[1].param2.value = paramValue2;
		document.forms[1].param3.value = paramValue3;
		document.forms[1].param4.value = paramValue4;
		document.forms[1].param5.value = paramValue5;
			
		if (actionTxt == "")
			actionTxt = document.forms[1].pageName.value;

		if (isSecured(actionTxt,targetPageStr))
			document.forms[1].action = secureprefix + actionTxt;
		else
			document.forms[1].action = regularprefix + actionTxt;
			
		document.forms[1].submit();
	}

function navicpimg()
{
	if (arguments.length > 0)
		showProdDesc(arguments[0]);
	else
		showProdDesc();
}

function gsaimg()
{
	if (arguments.length > 0)
		showProdDesc(arguments[0]);
	else
		showProdDesc();
}
	
function l4img()
{
	if (arguments.length > 0)
		showProdDesc(arguments[0]);
	else
		showProdDesc();
}
	

function recimg()
{
	if (arguments.length > 0)
		showProdDesc(arguments[0]);
	else
		showProdDesc();
}


function displaySavings()
{
showGovSavDesc();
}
	
var prodpopup;

function showProdDesc(){

	if (prodpopup != null){
		prodpopup.focus();
	}
	else{
	
	var wtop  = ( screen.height - 500)/2;
	var wleft = ( screen.width - 400)/2 ;
	if (arguments.length > 0)
		pordpopup = window.open(regularprefix+"/redir.cfm" + sessiontoken+document.forms[1].sessionID.value + '/include/proddesc.cfm#' + arguments[0],'prodkey','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=400,height=500,top='+wtop+',left='+wleft);
	else
		pordpopup = window.open(regularprefix+"/redir.cfm" + sessiontoken+document.forms[1].sessionID.value + '/include/proddesc.cfm','prodkey','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=400,height=500,top='+wtop+',left='+wleft);	
	pordpopup.focus();
	}

}

function showCatPopup(){

	if (prodpopup != null){
		prodpopup.focus();
	}
	else{
	
	var wtop  = ( screen.height - 500)/2;
	var wleft = ( screen.width - 400)/2 ;
	pordpopup = window.open(regularprefix+"/redir.cfm" + sessiontoken+document.forms[1].sessionID.value + '/include/popup.cfm','prodkey','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=400,height=500,top='+wtop+',left='+wleft);
	pordpopup.focus();
	}

}

function validateEqpReqForm(fromPage){

		
	request = trim(document.forms[1].equiprequest);
	i = request.length - 1;
	for (i = request.length -1; (request.charAt(i) == '\n' || request.charAt(i) == '\r'); i--);

	if (request.charAt(i) == ':')
	{
			alert("Please enter request");
			return;
	}	
	
	if(trim(document.forms[1].name) == "")
		{
			alert("Please enter Name");
			document.forms[1].name.focus();
			return;
		}
	else
	if(trim(document.forms[1].email) == "") 
	{
			alert("Please enter E-mail");
			document.forms[1].email.focus();
			return;
	}
	else
	 if(trim(document.forms[1].phone) == "")
	{
			alert("Please enter phone");
			document.forms[1].phone.focus();
			return;
	}
	else
	if(trim(document.forms[1].equiprequest) == "")
		{
			alert("Please enter request");
			document.forms[1].equiprequest.focus();
			return;
		}
	else
	if((request.length < 40) && (request.charAt(request.length) == ":"))
	{
		alert("Please enter request");
		document.forms[1].equiprequest.focus();
		return;
		
	}
	else
	{
			if (!emailCheck(document.forms[1].email.value)){
				alert("Please enter a valid e-mail address");
				return;
			}
		linkSubmitForm('/customerservice/customerservicetmp.cfm','../customerservice/equiprequest.cfm','fromsubmit',fromPage,'');
	}	
}

function vldCat1(){
  flag = false;
  usertype = document.forms[1].usertype;
  for (i=0;i<usertype.length;i++){
  	if(usertype[i].checked){
		flag = true;
		break;
	}
  }
  
  if (!flag){
    alert("Please select your role");
	return;
  }
  
  email = trim(document.forms[1].catalogemail);
  if (email == ""){
  	alert("Please enter email address");
	document.forms[1].catalogemail.focus();
	return;
  }
  
  if (!emailCheck(email)){
  	alert("Please enter a valid email address");
	document.forms[1].catalogemail.focus();
	return;
  }
  
  linkSubmitForm('/estore/productstmp.cfm','../advice/cdromreqform.cfm','','','','','');

}

function vldSendQuote(){
	name = trim(document.forms[1].ftr_name);
	email = trim(document.forms[1].ftr_email);
	phone = trim(document.forms[1].ftr_phone);

	if (name == ""){
		alert("Please enter name");
		document.forms[1].ftr_name.focus();
		return;
	}
	if (email == ""){
		alert("Please enter e-mail");
		document.forms[1].ftr_email.focus();
		return;
	}
	if (!emailCheck(email)){
		alert("Please enter a valid e-mail");
		document.forms[1].ftr_email.focus();
		return;
	}
	
	linkSubmitForm('/estore/productstmp.cfm','../help/quoteform.cfm','','','','');
}
