function Rcertify() {
popupWin = window.open('http://www.bbbonline.org/cks.asp?id=673000052', 'Participant','height=400,width=450,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no');
}

function getExpDate(days,hours,minutes){
    var expDate=new Date();
    if(typeof days=="number"&&typeof hours=="number"&&typeof hours=="number"){
        expDate.setDate(expDate.getDate()+parseInt(days));
        expDate.setHours(expDate.getHours()+parseInt(hours));
        expDate.setMinutes(expDate.getMinutes()+parseInt(minutes));
        return expDate.toGMTString();
    } else { 
        return "";
    }
}

function trim(s) {
while (s.substring(0,1) == ' ') {
  s = s.substring(1,s.length);
}
while (s.substring(s.length-1,s.length) == ' ') {
  s = s.substring(0,s.length-1);
}
return s;
}

function isEmpty(inputStr) {
 if (inputStr == null || trim(inputStr) == "") {
    return true;
 }
 return false;
}

// Let onKeyUp() call for numbers only
function NumbersOnly(Input) {
   var control="0123456789";
   var newInput="";
   for(i=0;i<Input.value.length;i++) {
       chck=Input.value.charAt(i);
       if(control.indexOf(chck,0)!=-1) {
            newInput+=chck;
       }
   }
   Input.value = newInput;
}

function TimeOnly(Input) {
   var control="0123456789:";
   var newInput="";
   for(i=0;i<Input.value.length;i++) {
       chck=Input.value.charAt(i);
       if(control.indexOf(chck,0)!=-1) {
            newInput+=chck;
       }
   }
   Input.value = newInput;
}

function toggle_display(id) {
  var e = document.getElementById(id);
  if(e.style.display == 'block'){
      e.style.display = 'none';
  }else{
  e.style.display = 'block';
  }
}

function findPosX(obj) {
   var curleft = 0;
   if(obj.offsetParent)
       while(1)
       {
         curleft += obj.offsetLeft;
         if(!obj.offsetParent)
           break;
         obj = obj.offsetParent;
       }
   else if(obj.x)
       curleft += obj.x;
   return curleft;
}

function findPosY(obj) {
   var curtop = 0;
   if(obj.offsetParent)
       while(1)
       {
         curtop += obj.offsetTop;
         if(!obj.offsetParent)
           break;
         obj = obj.offsetParent;
       }
   else if(obj.y)
       curtop += obj.y;
   return curtop;
}


var disappeardelay=250  //menu disappear speed onMouseout (in miliseconds)
var enableanchorlink=0 //Enable or disable the anchor link when clicked on? (1=e, 0=d)
var hidemenu_onclick=1 //hide menu when user clicks within menu? (1=yes, 0=no)

var ie5a=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function showhide(obj, e, visible, hidden){
if (ie5a||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie5a && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=ie5a && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie5a && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
}

function dropdownmenu(obj, e, dropmenuID){
if (window.event) event.cancelBubble=true
 else if (e.stopPropagation) e.stopPropagation()
//hide previous menu
if (typeof dropmenuobj!="undefined") dropmenuobj.style.visibility="hidden"
// product_menus_off();
if (typeof clearhidemenu!="undefined") { clearhidemenu(); } else { return; }
if (ie5a||ns6){
  obj.onmouseout=delayhidemenu
  dropmenuobj=document.getElementById(dropmenuID)
  if (hidemenu_onclick) dropmenuobj.onclick=function(){dropmenuobj.style.visibility='hidden'}
  dropmenuobj.onmouseover=clearhidemenu
  dropmenuobj.onmouseout=ie5a? function(){ dynamichide(event)} : function(event){ dynamichide(event)}
  showhide(dropmenuobj.style, e, "visible", "hidden")
  dropmenuobj.x=getposOffset(obj, "left")
  dropmenuobj.y=getposOffset(obj, "top")
  dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
  dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}
return clickreturnvalue()
}

function clickreturnvalue(){
if ((ie5a||ns6) && !enableanchorlink) return false
else return true
}

function contains_ns6(a, b) {
 if(b!=null) {
  while (b.parentNode)
   if ((b = b.parentNode) == a) return true;
 }
return false;
}

function dynamichide(e){
if (ie5a&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function delayhidemenu(){
 if (typeof dropmenuobj!="undefined") {
   delayhide=setTimeout("dropmenuobj.style.visibility='hidden';",disappeardelay)
   // delayhide=setTimeout("dropmenuobj.style.visibility='hidden';product_menus_off(); ",disappeardelay)
 }
}

function clearhidemenu(){
 if (typeof delayhide!="undefined")
  clearTimeout(delayhide)
}


/**
*
*  Secure Hash Algorithm (SHA1)
*  http://www.webtoolkit.info/
*
**/

function SHA1(msg) {

	function rotate_left(n,s) {
		var t4 = ( n<<s ) | (n>>>(32-s));
		return t4;
	};

	function lsb_hex(val) {
		var str="";
		var i;
		var vh;
		var vl;

		for( i=0; i<=6; i+=2 ) {
			vh = (val>>>(i*4+4))&0x0f;
			vl = (val>>>(i*4))&0x0f;
			str += vh.toString(16) + vl.toString(16);
		}
		return str;
	};

	function cvt_hex(val) {
		var str="";
		var i;
		var v;

		for( i=7; i>=0; i-- ) {
			v = (val>>>(i*4))&0x0f;
			str += v.toString(16);
		}
		return str;
	};


	function Utf8Encode(string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	};

	var blockstart;
	var i, j;
	var W = new Array(80);
	var H0 = 0x67452301;
	var H1 = 0xEFCDAB89;
	var H2 = 0x98BADCFE;
	var H3 = 0x10325476;
	var H4 = 0xC3D2E1F0;
	var A, B, C, D, E;
	var temp;

	msg = Utf8Encode(msg);

	var msg_len = msg.length;

	var word_array = new Array();
	for( i=0; i<msg_len-3; i+=4 ) {
		j = msg.charCodeAt(i)<<24 | msg.charCodeAt(i+1)<<16 |
		msg.charCodeAt(i+2)<<8 | msg.charCodeAt(i+3);
		word_array.push( j );
	}

	switch( msg_len % 4 ) {
		case 0:
			i = 0x080000000;
		break;
		case 1:
			i = msg.charCodeAt(msg_len-1)<<24 | 0x0800000;
		break;

		case 2:
			i = msg.charCodeAt(msg_len-2)<<24 | msg.charCodeAt(msg_len-1)<<16 | 0x08000;
		break;

		case 3:
			i = msg.charCodeAt(msg_len-3)<<24 | msg.charCodeAt(msg_len-2)<<16 | msg.charCodeAt(msg_len-1)<<8	| 0x80;
		break;
	}

	word_array.push( i );

	while( (word_array.length % 16) != 14 ) word_array.push( 0 );

	word_array.push( msg_len>>>29 );
	word_array.push( (msg_len<<3)&0x0ffffffff );


	for ( blockstart=0; blockstart<word_array.length; blockstart+=16 ) {

		for( i=0; i<16; i++ ) W[i] = word_array[blockstart+i];
		for( i=16; i<=79; i++ ) W[i] = rotate_left(W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16], 1);

		A = H0;
		B = H1;
		C = H2;
		D = H3;
		E = H4;

		for( i= 0; i<=19; i++ ) {
			temp = (rotate_left(A,5) + ((B&C) | (~B&D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;
			E = D;
			D = C;
			C = rotate_left(B,30);
			B = A;
			A = temp;
		}

		for( i=20; i<=39; i++ ) {
			temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;
			E = D;
			D = C;
			C = rotate_left(B,30);
			B = A;
			A = temp;
		}

		for( i=40; i<=59; i++ ) {
			temp = (rotate_left(A,5) + ((B&C) | (B&D) | (C&D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;
			E = D;
			D = C;
			C = rotate_left(B,30);
			B = A;
			A = temp;
		}

		for( i=60; i<=79; i++ ) {
			temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;
			E = D;
			D = C;
			C = rotate_left(B,30);
			B = A;
			A = temp;
		}

		H0 = (H0 + A) & 0x0ffffffff;
		H1 = (H1 + B) & 0x0ffffffff;
		H2 = (H2 + C) & 0x0ffffffff;
		H3 = (H3 + D) & 0x0ffffffff;
		H4 = (H4 + E) & 0x0ffffffff;

	}

	var temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);

	return temp.toLowerCase();

}

/* END SHA1 ENCRYPTION */

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
} 

// Request Call functions - responseText
function ajaxDiv(divId) {
  if(httpDivActive==0) {
    httpDivActive=1;
    httpDiv.open("GET", "/ajaxDiv.html?divid=" + divId,true);
    httpDiv.onreadystatechange = function () {
      if (httpDiv.readyState == NORMAL_STATE) {
        document.getElementById(divId).innerHTML=httpDiv.responseText;
        httpDivActive=0;
      };
    };   
    httpDiv.send(null);
  }
}

// Request Call functions
function handleajaxReqCall() {
  if (httpajaxReqCall.readyState == NORMAL_STATE) {
    document.getElementById('divReqCall').style.display="none";
    alert("Thank you.  You should expect a call soon between 8-5 EST.");
  }
}
function ajaxReqCall () {
  if(!isEmpty(document.formReqCall.call_name.value)) {
    var call_name = document.formReqCall.call_name.value;
    var call_phone = document.formReqCall.call_phone.value;
    var rep_email = document.formReqCall.rep_email.value;
    httpajaxReqCall.open("GET", "/ajaxReqCall.html?call_name="+escape(call_name)+"&call_phone="+escape(call_phone)+"&rep_email="+escape(rep_email),true);
    httpajaxReqCall.onreadystatechange = handleajaxReqCall;
    httpajaxReqCall.send(null);
  }
}


// Fast Login functions
// getSeed method:  gets a seed from the server for this transaction
function getSeed() 
{ // only get a seed if we're not logged in and we don't already have one
	if (attemptLogin) return;
	if (!attemptLogin && !loggedIn) hasSeed = false;
	if (!loggedIn && !hasSeed) {
                attemptLogin = true;
		ihttp.open('GET', LOGIN_PREFIX + 'task=getseed', true);
		ihttp.onreadystatechange = handleHttpGetSeed;
		ihttp.send(null);
	}
}
function handleHttpGetSeed()
{	// if there hasn't been any errors
	if (ihttp.readyState == NORMAL_STATE) {
		// split by the | delimiter
		results = ihttp.responseText.split('|');
		seed_id = results[0]; // alert("SeedID:"+seed_id);
		seed = results[1]; // alert("Seed:"+seed);
		// now we have the seed
		hasSeed = true; attemptLogin = false;
	}
}

// validateLogin method: validates a login request
function validateLogin()
{
	// ignore request if we are already logged in
	if (loggedIn || attemptLogin) { return; }
	document.getElementById('cart').style.visibility = 'hidden'
	document.getElementById('login').style.visibility = ''
	username = document.getElementById('username');
	password = document.getElementById('password');

	username.readOnly=false; password.readOnly=false;
	username.className='cartfrw'; password.className='cartfrw';
	username.disabled=null; password.disabled=null;
	if(!hasSeed) { getSeed(); return; }
	if(isEmpty(username.value) || isEmpty(password.value)) {
		username.focus();
		return;
	}

	// compute the hash of the hash of the password and the seed
	// hash = hex_md5(hex_md5(password.value) + seed);
        hash = SHA1(SHA1(password.value.toLowerCase()) + seed);
        attemptLogin=true;
	// open the http connection
	ihttp.open('GET', LOGIN_PREFIX + 'task=checklogin&username='+username.value+'&id='+seed_id+'&hash='+hash, true);
	ihttp.onreadystatechange = handleHttpValidateLogin;
	ihttp.send(null);
}

// handleHttpValidateLogin method: called when the validation results are returned from the server
function handleHttpValidateLogin()
{
	// did the connection work?
	if ((ihttp.readyState == NORMAL_STATE) && (attemptLogin)) {
		// split by the pipe
		results = ihttp.responseText.split('|');
		if (results[0].substring(0,4) == "true")
		{
			hasSeed = false;
			loggedIn = true;
			fullname = results[1];
			message = results[2];
			optmessages = '';
		} else {
			loggedIn = false;
			password = document.getElementById('password') ;
			password.value = '';
		 	optmessages = results[1];
		}
		showLogin();
                attemptLogin = false;
	}
}

// Clear Message Line
function clearMessageElement()
{
       try {
               if (messageElement != false)
               {
                       document.getElementById('cartloginopt').removeChild(messageElement);
               }
       }
       catch (e)
       { }
}

// focusField method: called when username or password gain focus
function focusField()
{
	try {
		if (messageElement != false)
		{
			document.getElementById('cartloginopt').removeChild(messageElement);
		}
		getSeed();
	}
	catch (e)
	{ }
}

// blurField method: called when username or password are blurred
function blurField()
{
	try {
		validateLogin();
	}
	catch (e)
	{ }
}

// showLogin method: displays if necessary that we are logged in
function showLogin() {
	if (messageElement != false)
	{
		try {
			document.getElementById('cartloginopt').removeChild(messageElement);
		}
		catch (e) { }
	}
	if (loggedIn)
	{
		showingLoggedIn = true;
		
		// loginPanel = document.getElementById('login');
                // <p><Logged in as <strong>FULLNAME</strong> [<a href="javascript: logout();">logout</a>]</p>
		p = document.createElement('p');
		pre = document.createTextNode('Logged in as ');
		strong = document.createElement('strong');
		strong_text = document.createTextNode(fullname);
		strong.appendChild(strong_text);
		mid = document.createTextNode(' [');
		a = document.createElement('a');
		a.href='javascript:logout();';
		a_text = document.createTextNode('logout');
		a.appendChild(a_text);
		post = document.createTextNode(']');
		
		p.appendChild(pre);
		p.appendChild(strong);
		p.appendChild(mid);
		p.appendChild(a);
		p.appendChild(post);
		
		messageElement = p;

                // Save a copy of messageP for later showing at logout time
		messageP = document.getElementById('cartloginopt');
		// loginPanel.removeChild(messageP);
		document.getElementById('cartloginopt').appendChild(messageElement);
		clearMessageElement();
		document.getElementById('username').readOnly = 'readOnly';
		document.getElementById('password').readOnly = 'readOnly';
		document.getElementById('username').className = 'cartfro';
		document.getElementById('password').className = 'cartfro';
		document.getElementById('username').disabled = true;
		document.getElementById('password').disabled = true;
		document.getElementById('cartname').innerHTML="Welcome, "+fullname;
		document.getElementById('cartopt').innerHTML = 
"<a href='/account.html'>My Account</a>"+
"<font style='color: #F9CD46'>&nbsp;&nbsp;|&nbsp;&nbsp;</font><a href='/cart.html'>My Cart</a>"+
"<font style='color: #F9CD46'>&nbsp;&nbsp;|&nbsp;&nbsp;</font><a href='javascript: logout();'>Log-out</a>";

		document.getElementById('login').style.visibility = 'hidden';
		document.getElementById('cart').style.visibility = '';
		if(document.location.href=='https://www.interplas.com/log-in.html') {
                  document.location.href = 'https://www.interplas.com/account.html';
                } else { 
                  document.location.href = document.location.href;
                }
                // window.location.reload(false);
                // if(message.length>0) {
 		//  alert("Now Logged Into InterPlas.com\n"+message);
		// }
	}
	else
	{
		messageElement = document.createElement('strong');
		messageElement.appendChild(document.createTextNode(' [' + optmessages+']'));
		messageElement.style.color = '#ee0000';
		document.getElementById('cartloginopt').appendChild(messageElement);
	}
}

// logout method: prepares for a new login
function logout()
{
	loggedIn = false;
        hasSeed = false;
	getSeed();
	hasSeed = false;
	username = document.getElementById('username');
	password = document.getElementById('password');
	// loginPanel = document.getElementById('login');
	// username.value = '';
	// password.value = '';
	username.readOnly = 'readOnly';
	password.readOnly = 'readOnly';
	username.className = 'cartfro';
	password.className = 'cartfro';
	username.disabled = true;
	password.disabled = true;
	document.getElementById('cartname').innerHTML="Welcome, <span class='blu14' onmouseover='javascript: validateLogin(); return false;'>Fast Login Here!</span>";
	document.getElementById('cartopt').innerHTML="<a href='https://www.interplas.com/log-in.html'>Log-In</a><font style='color: #F9CD46'>&nbsp;&nbsp;|&nbsp;&nbsp;</font><a href='https://www.interplas.com/cart.html'>My Cart</a>"; 
	
        document.getElementById('cart').style.visibility = ''; 
	document.getElementById('login').style.visibility = 'hidden';
	// loginPanel.removeChild(messageElement);
	// loginPanel.appendChild(messageP);
	
	messageElement = false;
	showingLoggedIn = false;
	attemptLogin = false;	
	// username.focus();
        document.location.href = 'https://www.interplas.com/log-in.html';
}

// setupLogin method: to be called on page load, sets up the login script
function setupLogin()
{
	username = document.getElementById('username');
	password = document.getElementById('password');
	iaddEvent(username, 'focus', focusField);
	// iaddEvent(username, 'blur', blurField);
	iaddEvent(password, 'focus', focusField);
	// iaddEvent(password, 'blur', blurField);
        // attach events to accordions
	if (document.getElementById('auto-accordion')) {
		new Accordian('auto-accordion',3,'accordion_highlight',0);
	}
	if (document.getElementById('click-accordion')) {
		new Accordian('click-accordion',3,'accordion_highlight',1);
	}

	if(document.getElementById('prodline_body')) {
		var ancor=window.location.href;
		var temp = new Array();
		temp = ancor.split("#");
		if(document.getElementById(temp[1])) {
			document.getElementById(temp[1]).className="item_anchor";
		}
	}
}


// function to add events to the page in a cross-browser manner
function iaddEvent(objObject, strEventName, fnHandler) { 
	// DOM-compliant way to add an event listener 
 	if (objObject.addEventListener) {
		objObject.addEventListener(strEventName, fnHandler, false); 
	}
	// IE/windows way to add an event listener 
	else if (objObject.attachEvent) {
		objObject.attachEvent('on' + strEventName, fnHandler); 
	}
}

// constants
var NORMAL_STATE = 4;
var LOGIN_PREFIX = '/ajax_auth_seed.php?';

// variables
// Note: In case of a page reload, these variable must be re-assigned
// from with session variable decision
var httpajaxReqCall = getHTTPObject();
var ihttp = getHTTPObject(); 
var httpDiv = getHTTPObject();
var httpDivActive = 0;
var hasSeed = false;
var loggedIn = false;
var attemptLogin = false;
var seed_id = 0;
var seed = 0;
var fullname = '';
var message = '';
var optmessages = '';
var showingLoggedIn = false;
var messageElement = false;
var messageP = false;

iaddEvent(window,'load',setupLogin);
