
// Define Style Sheet
//window.onerror=errortrap;
var caution = false;
function errortrap()
{
   return true;
}
function browser()
{
browser=navigator.appName

if (browser=="Netscape") 
	document.write('<LINK REL="STYLESHEET" TYPE="text/css" HREF="css/nn.css">')
else 
	document.write('<LINK REL="STYLESHEET" TYPE="text/css" HREF="css/ie.css">');
}

function browserH()
{

browser=navigator.appName

if (browser=="Netscape") 
	document.write('<LINK REL="STYLESHEET" TYPE="text/css" HREF="../css/nn.css">')
else 
	document.write('<LINK REL="STYLESHEET" TYPE="text/css" HREF="../css/ie.css">');
}

function browserG()
{

browser=navigator.appName

if (browser=="Netscape") 
	document.write('<LINK REL="STYLESHEET" TYPE="text/css" HREF="../../css/nn.css">')
else 
	document.write('<LINK REL="STYLESHEET" TYPE="text/css" HREF="../../css/ie.css">');
}


// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value,expires,path ,domain ,  secure)
{
        var curCookie = name + '=' + escape(value) +
                ((expires) ? '; expires=' + expires.toGMTString() : '') +
                ((path) ? '; path=' + path : '') +
                ((domain) ? '; domain=' + domain : '') +
                ((secure) ? '; secure' : '')
        if (!caution || (name + '=' + escape(value)).length <= 4000)
        {
                document.cookie = curCookie;
        }
        else
                if (confirm('Cookie exceeds 4KB and will be cut!'))
                        document.cookie = curCookie
}
// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name)
 {
       var prefix = name + "="
       var cookieStartIndex = document.cookie.indexOf(prefix)
       if (cookieStartIndex == -1)
             return null

       var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
        if (cookieEndIndex == -1)
                cookieEndIndex = document.cookie.length
       return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
 }

function savecomp(gcode,glassno)
{
var largeExpDate = new Date ();
largeExpDate.setTime(largeExpDate.getTime() + (24 * 3600 * 1000));
setCookie("gcode",gcode,largeExpDate);
setCookie("glassno",glassno,largeExpDate);
}


//------------------------------------------------------
function isNumber(data)
// validate that user entered number values
{
	var str = String(data);

	var numStr="-0123456789.";

	var thisChar;
	var counter;
	counter=0;
	for (var i= 0; i<str.length; i++){
		thisChar = str.substring(i, i+1);
		if(numStr.indexOf(thisChar) != -1)
			counter++;
	}

	if (counter!=str.length)
	{
		return false;
	}

	return true;
}

function isInteger(data)
{
	var numstr="-0123456789";
	var thisChar;
	var counter = 0;

	data = trim(data);

	for (var i=0; i<data.length; i++)
	{
		thisChar = data.substring(i,i+1);
		if (numstr.indexOf(thisChar)!= -1)
			counter++;
	}

	if (counter == data.length )
		return 1;
	else return 0;
}

// delete lead and trailing white spaces
function trim(str){

        /* trim trailing white spaces */
	while (str.length > 0 && str.charAt(str.length - 1) == ' ')
	{
		str = str.slice(0, str.length - 1);
	}


	/* trim leading white spaces */
	while (str.length > 0 && str.charAt(0) == ' ')
	{
		str = str.slice(1, str.length);
	}

	return str;

}

var msg1 = "Please make sure the field is numeric.";
var msg2 = "Please make sure the max value is larger the min value.";
function checkMinMax(c1,c2){

  c1.value = trim(c1.value) ;
  c2.value = trim(c2.value) ;

  if(c1.value.length>0 && !isNumber(c1.value)){
      c1.focus();alert(msg1);return(false);
  }
  if(c2.value.length>0 && !isNumber(c2.value)){
      c2.focus();alert(msg1);return(false);
  }

  if(c1.value.length>0 && c2.value.length>0) {
  var n1 = parseFloat(c1.value);
  var n2 = parseFloat(c2.value);
   if(n1>n2){
      c1.focus();alert(msg2);return(false);
   }
  }
  return true;
}


