var lfRoot;
var lfSSLRoot;
var onForm;
var contextOpen = false;
var proofPrice 	= new Array(0,40,45,70,75);
var hasCoupon 	= false;

function lfWindowHeight()
{
   var myWidth = 0, myHeight = 0;
   if( typeof( window.innerWidth ) == 'number' )
   { //Non-IE
      myHeight = window.innerHeight;
   }
   else
   {
      if ( document.documentElement && ( document.documentElement.clientWidth ||    document.documentElement.clientHeight ) )
   { //IE 6+ in 'standards compliant mode'
      myHeight = document.documentElement.clientHeight;
   }
   else
   {
      if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
      { //IE 4 compatible
         myHeight = document.body.clientHeight;
      }
   }
}
   return myHeight;
}



function lfWindowWidth()
{
   var myWidth = 0, myWidth = 0;
   if( typeof( window.innerWidth ) == 'number' )
   { //Non-IE
      myWidth = window.innerWidth;
   }
   else
   {
      if ( document.documentElement && ( document.documentElement.clientWidth ||    document.documentElement.clientWidth ) )
   { //IE 6+ in 'standards compliant mode'
      myWidth = document.documentElement.clientWidth;
   }
   else
   {
      if ( document.body && ( document.body.clientWidth || document.body.clientWidth ) )
      { //IE 4 compatible
         myWidth = document.body.clientWidth;
      }
   }
}
   return myWidth;
}


function setLfRoot(rootStr,sslRootStr){
	lfRoot 		= rootStr;
	lfSSLRoot 	= sslRootStr;
}

function showLayer(layer,x,y){
	document.getElementById(layer).style.left = x;
	document.getElementById(layer).style.top = y;
	document.getElementById(layer).style.visibility = "visible";

}

function hideLayer(layer){
	document.getElementById(layer).style.visibility = "hidden";

}


function round()
{
  var xyz = window.document.xyzFORM.RAW_NUMBER.value;
  var dollarVal = dollarValue(xyz);
  window.document.xyzFORM.ROUNDED_NUMBER.value = "$  " + dollarVal;
}

function dollarValue(n)
{
  var Bstr = "";
  var b = n * 100;
  var c = Math.round(b);
  var Astr = c.toString();
  var Alength = Astr.length;
  if (Alength <= 2) Bstr = Bstr + ".";
  var dot = Alength - 3;
  var counter = 0;
    while (counter < Alength )
    {
      Bstr = Bstr + Astr.charAt(counter);
      if (counter == dot) Bstr = Bstr + ".";
      counter = counter + 1;
    }
  var d = Bstr;
  return d;
}

function noenter() {
  	return !(window.event && window.event.keyCode == 13); 
}


function lfCheckZip(object_value) {
	if (object_value.length == 0)
	return true;

	if (object_value.length != 5 && object_value.length != 10)
	return false;

	// make sure first 5 digits are a valid integer
	if (object_value.charAt(0) == "-" || object_value.charAt(0) == "+")
	return false;

	if (!lfCheckInt(object_value.substring(0,5)))
		return false;

	if (object_value.length == 5)
		return true;

	// make sure

	// check if separator is either a'-' or ' '
	if (object_value.charAt(5) != "-" && object_value.charAt(5) != " ")
	return false;

	// check if last 4 digits are a valid integer
	if (object_value.charAt(6) == "-" || object_value.charAt(6) == "+")
	return false;

	return (lfCheckInt(object_value.substring(6,10)));
}



function lfCheckSSN(object_value) {
	var white_space = " -+.";
	var ssc_string="";
	var check_char;

	if (object_value.length == 0 || object_value == "--")
	return true;
	
	if (object_value.length != 11)
	return false;

	// make sure white space is valid
	if (object_value.charAt(3) != "-" && object_value.charAt(3) != " ")
	return false;

	if (object_value.charAt(6) != "-" && object_value.charAt(6) != " ")
	return false;


	// squish out the white space
	for (var i = 0; i < object_value.length; i++)
	{
		check_char = white_space.indexOf(object_value.charAt(i))
		if (check_char < 0)
			ssc_string += object_value.substring(i, (i + 1));
	}	

	// make sure number is a valid integer
	if (!lfCheckInt(ssc_string))
		return false;

	return true;
}

function lfCheckPhone(object_value) {
	var white_space = " -+.";
	var ssc_string="";
	var check_char;

	if (object_value.length == 0 || object_value == "1---" || object_value == "---")
	return true;

	if (object_value.length != 14)
	return false;

	// make sure white space is valid
	if (object_value.charAt(1) != "-" && object_value.charAt(1) != " ")
	return false;

	if (object_value.charAt(5) != "-" && object_value.charAt(5) != " ")
	return false;
	
	if (object_value.charAt(9) != "-" && object_value.charAt(9) != " ")
	return false;

	// squish out the white space
	for (var i = 0; i < object_value.length; i++)
	{
		check_char = white_space.indexOf(object_value.charAt(i))
		if (check_char < 0)
			ssc_string += object_value.substring(i, (i + 1));
	}	

	// make sure number is a valid integer
	if (!lfCheckInt(ssc_string))
		return false;

	return true;
}

function lfCheckUndef(object_value) {
	if (object_value == undefined)
		return "";
	else 
		return object_value;
}

function lfCheckInt(object_value) {
	//Returns true if value is a number or is NULL
	//otherwise returns false	

	if (object_value.length == 0)
	return true;

	//Returns true if value is an integer defined as
	//   having an optional leading + or -.
	//   otherwise containing only the characters 0-9.
	var decimal_format = ".";
	var check_char;

	//The first character can be + -  blank or a digit.
	check_char = object_value.indexOf(decimal_format)
	//Was it a decimal?
	if (check_char < 1)
	return lfCheckNum(object_value);
	else
	return false;
}



function lfCheckNum(object_value) {
	//Returns true if value is a number or is NULL
	//otherwise returns false	

	if (object_value.length == 0)
	return true;

	//Returns true if value is a number defined as
	//   having an optional leading + or -.
	//   having at most 1 decimal point.
	//   otherwise containing only the characters 0-9.
	var start_format = " .+-0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;

	//The first character can be + - .  blank or a digit.
	check_char = start_format.indexOf(object_value.charAt(0))
	//Was it a decimal?
	if (check_char == 1)
	    decimal = true;
	else if (check_char < 1)
		return false;

	//Remaining characters can be only . or a digit, but only one decimal.
	for (var i = 1; i < object_value.length; i++)
	{
		check_char = number_format.indexOf(object_value.charAt(i))
		if (check_char < 0)
			return false;
		else if (check_char == 1)
		{
			if (decimal)		// Second decimal.
				return false;
			else
				decimal = true;
		}
		else if (check_char == 0)
		{
			if (decimal || digits)	
				trailing_blank = true;
	// ignore leading blanks

		}
		else if (trailing_blank)
			return false;
		else
			digits = true;
	}	
	//All tests passed, so...
	return true
}

var w3c=(document.getElementById)?true:false;
var ie=(document.all)?true:false;
var N=-1;

function createBar(w,h,bgc,brdW,brdC,blkC,speed,blocks,count,action){
if(ie||w3c){
var t='<div id="_xpbar'+(++N)+'" style="visibility:visible; position:relative; overflow:hidden; width:'+w+'px; height:'+h+'px; background-color:'+bgc+'; border-color:'+brdC+'; border-width:'+brdW+'px; border-style:solid; font-size:1px;">';
t+='<span id="blocks'+N+'" style="left:-'+(h*2+1)+'px; position:absolute; font-size:1px">';
for(i=0;i<blocks;i++){
t+='<span style="background-color:'+blkC+'; left:-'+((h*i)+i)+'px; font-size:1px; position:absolute; width:'+h+'px; height:'+h+'px; '
t+=(ie)?'filter:alpha(opacity='+(100-i*(100/blocks))+')':'-Moz-opacity:'+((100-i*(100/blocks))/100);
t+='"></span>';
}
t+='</span></div>';
document.write(t);
var bA=(ie)?document.all['blocks'+N]:document.getElementById('blocks'+N);
bA.bar=(ie)?document.all['_xpbar'+N]:document.getElementById('_xpbar'+N);
bA.blocks=blocks;
bA.N=N;
bA.w=w;
bA.h=h;
bA.speed=speed;
bA.ctr=0;
bA.count=count;
bA.action=action;
bA.togglePause=togglePause;
bA.showBar=function(){
this.bar.style.visibility="visible";
}
bA.hideBar=function(){
this.bar.style.visibility="hidden";
}
bA.tid=setInterval('startBar('+N+')',speed);
return bA;
}}

function startBar(bn){
var t=(ie)?document.all['blocks'+bn]:document.getElementById('blocks'+bn);
if(parseInt(t.style.left)+t.h+1-(t.blocks*t.h+t.blocks)>t.w){
t.style.left=-(t.h*2+1)+'px';
t.ctr++;
if(t.ctr>=t.count){
eval(t.action);
t.ctr=0;
}}else t.style.left=(parseInt(t.style.left)+t.h+1)+'px';
}

function togglePause(){
if(this.tid==0){
this.tid=setInterval('startBar('+this.N+')',this.speed);
}else{
clearInterval(this.tid);
this.tid=0;
}}

function togglePause(){
if(this.tid==0){
this.tid=setInterval('startBar('+this.N+')',this.speed);
}else{
clearInterval(this.tid);
this.tid=0;
}}

function checkFocusNum(thisVal,num,nextEle,prevEle,e) {
	if ((e.keyCode > 47 & e.keyCode < 57) || (e.keyCode > 95 & e.keyCode < 106)) {
		if (thisVal.length == num && nextEle != null) document.getElementById(nextEle).focus();
	} else {
		if (e.keyCode == 8 || e.keyCode == 18) {
			if (thisVal.length == 0 && prevEle != null) {
				document.getElementById(prevEle).focus()
				Show_End_Of_Path(prevEle);
			}
		} else {
			e.returnValue = false;
		}
	}
}

function Show_End_Of_Path(el) {
	el = document.getElementById(el);
	tr = el.createTextRange()
	tr.collapse(false)
	tr.select();
}

function echeck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	  
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	  
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	   
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	   
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	   
	    return false
	 }

	 if (str.indexOf(" ")!=-1){
	  
	    return false
	 }
	 return true					
}

function lfEntSub(myform) {
	if (window.event && window.event.keyCode == 13)
		myform.submit();
	else
		return true;
}

function openChart(){
	chartWin = window.open(lfSSLRoot + "support/uploadChart.php","chartWin","modal=yes,toolbar=no,status=no,width=510,height=270,resizable=no");
}

function showPopup(type,cat,subItemId){
	var popup = document.getElementById("helpPopup");
	document.getElementById("helpFrame").src = lfSSLRoot + "helpPopup.php?type=" + type + "&cat=" + cat + "&subItemId=" + subItemId;
	popup.style.visibility = "visible";

}

function hidePopup(type){
	var popup = document.getElementById("helpPopup");
	document.getElementById("helpFrame").src = lfSSLRoot + "blank.html";
	popup.style.visibility = "hidden";

}

function ajaxRequest(url,func) {

	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('Giving up :( Cannot create an XMLHTTP instance');
	    return false;
	}
	http_request.onreadystatechange = function() { eval(func)(http_request); };
	http_request.open('GET', url, true);
	http_request.send(null);
	return true;
}

function getNodeValue(obj,tag)
{
	return obj.getElementsByTagName(tag)[0].firstChild.nodeValue;
}

function hiObj(obj,color){
	if (obj) obj.style.backgroundColor=color;
}

function uploadCompleted() {
	var oid = '';
	var fileType = '';
	var proofId = '';
	if (document.getElementById("uploadOrderId")) oid = document.getElementById("uploadOrderId").value;
	if (document.getElementById("fileType")) fileType = document.getElementById("fileType").value;
	if (document.getElementById("proofId")) proofId = document.getElementById("proofId").value;
	location.href='/upload/uploadDB.php?' + window.frames['uploadFrm'].document.getElementById('rup').getResponse() + '&oid=' + oid + '&fileType=' + fileType + '&proofId=' + proofId;
}
