// Flash Version Detector  v1.2.1
// documentation: http://www.dithered.com/javascript/flash_detect/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)
// with VBScript code from Alastair Hamilton (now somewhat modified)
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring, strVersion;
var strCode;
var strSUP, strUL, strLI

if (checkIt('konqueror'))
{
	browser = "Konqueror";
	OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (checkIt('fire')) browser = "Fire Fox"
else if (!checkIt('compatible'))
{
	browser = "Netscape Navigator"
	version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS)
{
	if (checkIt('linux')) OS = "Linux";
	else if (checkIt('x11')) OS = "Unix";
	else if (checkIt('win')) OS = "Windows";
	else if (checkIt('312.5')) OS = "OldMac";
	else if (checkIt('mac')) OS = "Mac";
	else OS = "an unknown operating system";
}



function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

  
function docjslib_getRealLeft() {
	var WidthObject = document.getElementById("rightside");
	
	xPos = eval(WidthObject).offsetLeft;
	tempEl = eval(WidthObject).offsetParent;
  	while (tempEl != null) {
  		xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
  	}
	return xPos;
}

function isDefined(property) {
  return (typeof property != 'undefined');
}





function formCheck(strRequest, strReturn, strForm, strError)
{
	var intCount = document.forms[strForm].length;
	var i = 0;
	var bSendFlag = true;
	
	while(i != intCount)
	{
		if(document.forms[strForm].elements[i].value == "")
		{
				var strName = document.forms[strForm].elements[i].name;
				
				if(strName.indexOf("*") != -1)
				{
					var iLength = strName.length;
					strName = strName.substring(1, iLength);
					strName = strName.replace("_", " ");
					strName = strName.replace("_", " ");
					strName = strName.replace("_", " ");
					strName = strName.replace("_", " ");
					
					var obj = window.parent.document.getElementById(strError);
	
						obj.innerHTML = '<span class="error">Please fill in the ' + strName + ' field.</span>';
						
						document.forms[strForm].elements[document.forms[strForm].elements[i].name].focus();
						bSendFlag = false;
						break;
				}
				i = i+1;
		}
		else
		{
			i = i+1;
		}
		
	}

	if(bSendFlag == true)
	{
		document.forms[strForm].action = "../ASP/submit.asp?request=" + strRequest + "&return=" + strReturn;			
		document.forms[strForm].submit();
	}
}



function formCheck2(strRequest, strReturnPage, strErrorReturnPage, strForm, strError)
{
	var intCount = document.forms[strForm].length;
	var i = 0;
	var bSendFlag = true;
	
	while(i != intCount)
	{
		if(document.forms[strForm].elements[i].value == "")
		{
				var strName = document.forms[strForm].elements[i].name;
				
				if(strName.indexOf("*") != -1)
				{
					var iLength = strName.length;
					strName = strName.substring(1, iLength);
					strName = strName.replace("_", " ");
					
					var obj = document.getElementById(strError);
	
						obj.innerHTML = '<span class="error">Please fill in the <B>' + strName + '</B> field.</span>';
						
						document.forms[strForm].elements[document.forms[strForm].elements[i].name].focus();
						bSendFlag = false;
						break;
				}
				i = i+1;
		}
		else
		{
			i = i+1;
		}
		
	}


	
	if(bSendFlag == true)
	{
		
		if (strRequest == "adddetailstoorder") {
			 //alert("here is formcheck");
			 document.forms[strForm].action = "../asp/order_engine.asp?request=" + strRequest
			 document.forms[strForm].submit();
		}
		else {
			bSendFlag = CheckEmail();
			bSendFlag = CheckDate();
			
			
			
			if(bSendFlag == true)
			{
				document.forms[strForm].method = "post";
				document.forms[strForm].action = "../asp/order_engine.asp?request=" + strRequest + "&return=" + strReturnPage + "&errorreturn=" + strErrorReturnPage;			
				document.forms[strForm].submit();
			}
		}
	}
}


function CheckDate()
{
	var strDate = document.data1.elements["*Delivery_Date"].value;
	var bFlag = true;
	
	if(isNumber(strDate.charAt(0)) == false ||  isNumber(strDate.charAt(1)) == false || isNumber(strDate.charAt(3)) == false || isNumber(strDate.charAt(4)) == false || isNumber(strDate.charAt(6)) == false || isNumber(strDate.charAt(7)) == false || strDate.charAt(2) != "/" || strDate.charAt(5) != "/")
	{
		var obj = document.getElementById("error_message");
	
		obj.innerHTML = '<span class="error">Please correct the date format (mm/dd/yy).</span>';
		document.data1.elements["*Delivery_Date"].focus();
		
		return false;	
	}
	return true;
}


function CheckEmail()
{
	var strEmail = document.data1.elements["*Email"].value;
	
	if(strEmail.indexOf('@') != -1 && strEmail.indexOf('.') != -1 )
	{
		return true;		
	}
	else
	{
		var obj = document.getElementById("error_message");
	
		obj.innerHTML = '<span class="error">Please correct the email address.</span>';
		document.data1.elements["*Email"].focus();
		
		return false;		
	}
	
}

function printContent()
{
	if (document.getElementById!= null) 
	{ 
		var html = '<HTML>\n<HEAD>\n'; 

		if (document.getElementsByTagName!= null) 
		{ 
			var headTags = document.getElementsByTagName("head"); 
			
			if (headTags.length > 0) 
			html += headTags[0].innerHTML; 
		} 

		html += '\n</HE' + 'AD>\n<BODY>\n'; 


		html += '<table="width="800"><TR  background="#FFFFFF"><TD><img src="../images/nav/topnav_logo_print.gif" width="799" height="63"></TD></TR></table>'
		//html += '<div id="content" class="print-content-div" style="height:485px;">'
		html += '<div id="printmain" style="width:800px; height:auto;background-color:#FFFFFF;"><div id="content" style="position:relative:top:0px;left:0px;width:490px;height:auto;padding-top:0px;">'
		var printPageElem = document.getElementById("content"); 

		if (printPageElem!= null) 
		{ 
			html += printPageElem.innerHTML; 
		} 
		else 
		{ 
			return; 
		} 
		html += '<br>';
		html += '<span class="regular-text">© Copyright 2005-2008 Oldcastle Precast, Inc. All rights reserved.<br /><br /></span>';
		html += '</div><br /><img src="../images/global/clear.gif" width="799" height="1"></div>'
		html += '\n</BO' + 'DY>\n</HT' + 'ML>'; 

	var printWin = window.open("","printFriendly"); 
		printWin.document.open(); 
		printWin.document.write(html); 
		printWin.print();
		printWin.document.close(); 
	
	} 
	else 
	{ 
		alert("Sorry, the printer friendly feature works\nonly in javascript enabled browsers."); 
	} 
} 

function printContent2() //prints without the copyright info
{
	if (document.getElementById!= null) 
	{ 
		var html = '<HTML>\n<HEAD>\n'; 

		if (document.getElementsByTagName!= null) 
		{ 
			var headTags = document.getElementsByTagName("head"); 
			
			if (headTags.length > 0) 
			html += headTags[0].innerHTML; 
		} 

		html += '\n</HE' + 'AD>\n<BODY>\n'; 


		html += '<table="width="800"><TR  background="#FFFFFF"><TD><img src="../images/nav/topnav_logo_print.gif" width="799" height="63"></TD></TR></table>'
		//html += '<div id="main_content_div" class="print-content-div" style="height:485px;">'
		html += '<div id="printmain" style="width:800px; height:auto;background-color:#FFFFFF;"><div id="content" style="position:relative:top:0px;left:0px;width:490px;height:auto;padding-top:0px;">'
		var printPageElem = document.getElementById("main_content_div"); 

		if (printPageElem!= null) 
		{ 
			html += printPageElem.innerHTML; 
		} 
		else 
		{ 
			return; 
		} 
		html += '<br>';
		html += '<br /><br /></div><br /><img src="../images/global/clear.gif" width="799" height="1"></div>'
		html += '\n</BO' + 'DY>\n</HT' + 'ML>'; 

	var printWin = window.open("","printFriendly"); 
		printWin.document.open(); 
		printWin.document.write(html); 
		printWin.print();
		printWin.document.close(); 
	
	} 
	else 
	{ 
		alert("Sorry, the printer friendly feature works\nonly in javascript enabled browsers."); 
	} 
} 

function LaunchVaultInstall()
{
	
	
	if(browser == "Internet Explorer")
	{
		window.open("../knowledge/guide.asp", "Guide", "height=600, width=790, toolbar=no, menubar=no, titlebar=no");
	}
	else
	{

		window.open("../knowledge/guide.asp", "Guide", "height=600, width=790, toolbar=no");
	}
	
	
	
}

function login()
{
	window.open("login/login.asp", "login", "height=257, width=320, toolbars=0");
}

function LaunchCatalog()
{
	window.open("../../flash/catalog/Utility_vault_catalog.swf", "catalog","height=620, width=800, toolbar=no");
}

function LaunchCatalogHome()
{
	window.open("flash/catalog/Utility_vault_catalog.swf", "catalog","height=620, width=800, toolbar=no");
}
	
function OpenPopup(strPopupName)
{
	document.getElementById(strPopupName).style.visibility = "visible";
}	
	
function ClosePopup(strPopupName)
{
	document.getElementById(strPopupName).style.visibility = "hidden";
}
	
function AddProduct(strElementName, intMID, strElementName2, strElementName3, strElementName4)
{
		
		var val = document.getElementById(strElementName).value;
		
	    var bFlag = CheckForInt(val, strElementName)
		
		if(bFlag == true)
		{
			var obj = document.getElementById(strElementName);
			var obj2 = document.getElementById(strElementName2);
			var obj3 = document.getElementById(strElementName3);
			var obj4 = document.getElementById(strElementName4);
			
			if(obj.value == "")
			{
				document.getElementById("empty_qty").style.visibility = "visible";
			}
			else
			{
				if (obj3.value == "1") { alert('This product requires input of desired dimensions');}
				document.data1.action = "../ASP/order_engine.asp?request=addtoorder&return=../orders/order_step2.asp";
				document.data1.midnum.value = intMID;
				document.data1.qtynum.value = obj.value;
				document.data1.descript.value = escape(obj2.value);
				document.data1.detailsreqd.value = obj3.value;
				document.data1.utvid.value = obj4.value;
				//alert(obj3.value + "\n\n" + escape(obj3.value));
				document.data1.submit();
			}
		}
		
}

function ShowHide(intNum, strName, strName2)
{	
	var obj = document.getElementById(strName);
	var obj2 = document.getElementById(strName2);
	var obj3 = document.getElementById("bot_red_box");
	
	if(intNum == 1)
	{
		obj.style.display = "block";
		obj2.style.height = "140px"
		obj3.style.top = "200px";
	}
	else
	{
		obj.style.display = "none";
		obj2.style.height = "50px"
		obj3.style.top = "40px";
	}
}


function CollapseExpand(intNum, strName)
{	
//alert(strName);

	var obj = document.getElementById(strName);
	
	if(intNum == 1)
	{
		obj.style.display = "block";
	}
	else
	{
		obj.style.display = "none";
	}
}

function Description(strDescript)
{
	//alert(strDescript);
	
	strDescript = unescape(strDescript);
	
	//alert(strDescript);
	
	document.write(strDescript);
}

function AddEnteredToOrder()
{
	var bEmptyFlag = true;
	var bSpecialProduct = false;
	var strMID = "";
 	
	if(document.getElementById("new_mid_1").value != "" && document.getElementById("new_qty_1").value != "")
	{
	   
	   bEmptyFlag = false;
	   strMID = document.getElementById("new_mid_1").value;
	  // alert(strMID);
	   bSpecialProduct = CheckForDetails(strMID);
	   
	   document.data1.newmidnum1.value = document.getElementById("new_mid_1").value;
	   document.data1.newqtynum1.value = document.getElementById("new_qty_1").value;
	}
	if(document.getElementById("new_mid_2").value != "" && document.getElementById("new_qty_2").value != "")
	{
	   bEmptyFlag = false;
	    strMID = document.getElementById("new_mid_2").value;
	    bSpecialProduct = CheckForDetails(strMID);
	  
	   document.data1.newmidnum2.value = document.getElementById("new_mid_2").value;
	   document.data1.newqtynum2.value = document.getElementById("new_qty_2").value;
	}
	if(document.getElementById("new_mid_3").value != "" && document.getElementById("new_qty_3").value != "")
	{
	   bEmptyFlag = false;
	   strMID = document.getElementById("new_mid_3").value;
	    bSpecialProduct = CheckForDetails(strMID);
	
	   document.data1.newmidnum3.value = document.getElementById("new_mid_3").value;
	   document.data1.newqtynum3.value = document.getElementById("new_qty_3").value;
	}
	if(document.getElementById("new_mid_4").value != "" && document.getElementById("new_qty_4").value != "")
	{
	   bEmptyFlag = false;
	   strMID = document.getElementById("new_mid_4").value;
	   bSpecialProduct = CheckForDetails(strMID); 
	   document.data1.newmidnum4.value = document.getElementById("new_mid_4").value;
	   document.data1.newqtynum4.value = document.getElementById("new_qty_4").value;
	}
	if(document.getElementById("new_mid_5").value != "" && document.getElementById("new_qty_5").value != "")
	{
	   bEmptyFlag = false;
	   strMID = document.getElementById("new_mid_5").value;
	   bSpecialProduct = CheckForDetails(strMID);
	  
	   document.data1.newmidnum5.value = document.getElementById("new_mid_5").value;
	   document.data1.newqtynum5.value = document.getElementById("new_qty_5").value;
	}
	
	
	if(bEmptyFlag == false)
	{
		if (bSpecialProduct == true) {alert('This product requires input of desired dimensions');}
		document.data1.action = "../ASP/order_engine.asp?request=addentered&return=../orders/order_step2.asp";
		document.data1.submit();
	}
	else
	{
		document.getElementById("empty_qty").style.visibility = "visible";
	}
}

function CheckForDetails(strMID)
{
	var arrDetailProducts = new Array("7806800","7807400","7807500","7807700","7809700", "9997374","9997371","7809600","9997372");
    var bProductFound = false;
	for (var i = 0; i < arrDetailProducts.length; i++) {
	   if (strMID == arrDetailProducts[i]) {bProductFound = true;}
	}
	
	return bProductFound;	 
}

function DeleteItem(intNum)
{
	document.data1.deleteitem.value = intNum;
	document.data1.action = "../ASP/order_engine.asp?request=deleteitem&return=../orders/confirm.asp";
	document.data1.submit();
}



function isNumber(sText)
{
   var ValidChars = "-0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }


function CheckForInt(val, strName)
{
	if(!isNumber(val))
	{
		document.getElementById(strName).value = "";
		document.getElementById("not_numeric").style.visibility = "visible";
		return false;
	}
	else
	{
		return true;	
	}
}


function SetOrder()
{
	if (document.getElementById!= null) 
	{ 
		var html = '<HTML>\n<HEAD>\n'; 

		if (document.getElementsByTagName!= null) 
		{ 
			var headTags = document.getElementsByTagName("head"); 
			
			if (headTags.length > 0) 
			html += headTags[0].innerHTML; 
		} 
		//html+= "<base href=http://207.115.68.215/>"
		html+= GetStyles();

		
		html += '\n</HE' + 'AD>\n<BODY>\n'; 


		html += '<table="width="800"><TR  background="#00386b"><TD><img src="../images/nav/top_nav_print.gif" width="799" height="63"></TD></TR></table><BR><BR>'
		html += '<div id="print" style="width:800px; height:auto;background-color:#FFFFFF;"><div id="content" style="position:relative:top:0px;left:0px;width:490px;height:auto;padding-top:0px;">'
		var printPageElem = document.getElementById("main_content_div_email"); 

		if (printPageElem!= null) 
		{ 
			html += printPageElem.innerHTML; 
		} 
		else 
		{ 
			return; 
		} 
		html += '<br>';
		html += '</div></div>'
		html += '\n</BO' + 'DY>\n</HT' + 'ML>'; 
	
	
		//document.data1.emailcontent.value = html;
		//document.data1.submit();
		//document.data1.action = "../ASP/order_engine.asp?request=addordertodb";
		document.data1.submit();
	}
	
}

function ParseForButtons(strHTML)
{
	alert(strHTML);
}


function GetStyles()
{

	var strHTMLStyles;
	
		strHTMLStyles = "<style>"
		strHTMLStyles = strHTMLStyles + ".no-left-margin {margin-left:-14px;}";
		strHTMLStyles = strHTMLStyles + ".product-titles{font-family: Arial, Helvetica, sans-serif;	font-size:12px;	color:#FFFFFF;	font-weight:bold;}";
		strHTMLStyles = strHTMLStyles + "p.regular-text {margin-bottom: 12px; margin-top: 0px;}";
		strHTMLStyles = strHTMLStyles + ".regular-text {font-family: Verdana, Arial, Helvetica, sans-serif;	line-height:16px; font-size:11px; color:#000000;}";
		strHTMLStyles = strHTMLStyles + ".regular-text a:link {	font-family: Verdana, Arial, Helvetica, sans-serif;	line-height:16px; font-size:11px; color:#000000; text-decoration:underline;}";
		strHTMLStyles = strHTMLStyles + ".regular-text a:visited {font-family: Verdana, Arial, Helvetica, sans-serif; line-height:16px;	font-size:11px;	color:#000000; text-decoration:underline;}";
		strHTMLStyles = strHTMLStyles + ".regular-text a:hover {font-family: Verdana, Arial, Helvetica, sans-serif;	line-height:16px; font-size:11px; color:#C7032F; text-decoration:underline;}";
		strHTMLStyles = strHTMLStyles + ".regular-text a:active { font-family: Verdana, Arial, Helvetica, sans-serif; font-size:11px; color:#000000; text-decoration:underline; }";
		strHTMLStyles = strHTMLStyles + ".regular-text-client-list {font-family: Verdana, Arial, Helvetica, sans-serif;	font-size:11px;	color:#666666; line-height:.8em; }";
		strHTMLStyles = strHTMLStyles + ".regular-text-form { font-family: Verdana, Arial, Helvetica, sans-serif; line-height:16px;	font-size:11px;	color:#000000; letter-spacing:-1px;}";
		strHTMLStyles = strHTMLStyles + ".red-text{font-family: Verdana, Arial, Helvetica, sans-serif;font-size:10px;color:#CC0000;}";
		strHTMLStyles = strHTMLStyles + ".product-titles2{ font-family: Arial, Helvetica, sans-serif; font-size:11px; color:#FFFFFF; font-weight:bold;}";
		strHTMLStyles = strHTMLStyles + ".print-content-div {position:absolute;	left:20px; top:61px; width:490px;	height:424px; z-index:11;}";
		strHTMLStyles = strHTMLStyles + ".bottomnav-text{ font-family: Verdana, Arial, Helvetica, sans-serif; font-size:9px; color:#444141;	padding-top:0px 0px 5px 0px; text-decoration:none;}";
		strHTMLStyles = strHTMLStyles + ".bottomnav-text a:link{font-family: Verdana, Arial, Helvetica, sans-serif;	font-size:10px;	color:#444141; padding-top:0px 0px 5px 0px; text-decoration:none; }";
		strHTMLStyles = strHTMLStyles + ".bottomnav-text a:visited{font-family: Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#444141; padding-top:0px 0px 5px 0px; text-decoration:none;}";
		strHTMLStyles = strHTMLStyles + ".bottomnav-text a:hover{font-family: Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#C7032f; padding-top:0px 0px 5px 0px; text-decoration:underline;}";
		strHTMLStyles = strHTMLStyles + ".bottomnav-text a:active{font-family: Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#C7032f; padding-top:0px 0px 5px 0px; text-decoration:underline;}";
		strHTMLStyles = strHTMLStyles + ".cr-text{font-family: Verdana, Arial, Helvetica, sans-serif;font-size:9px;	color:#444141;padding-top:0px 0px 5px 0px;text-decoration:none;}";
		strHTMLStyles = strHTMLStyles + "</style>";

	return strHTMLStyles;
}


function PopulateFields()
{
		document.data1.elements["*Purchase_Order"].value = "xxxxxx";
		document.data1.elements["*Delivery_Time"].value = "2pm";
		document.data1.elements["*Delivery_Date"].value = "10/27/06";
		document.data1.elements["*Job_Site_Phone_Number"].value = "1112223333";
 		document.data1.elements["*Job_Site_Contact"].value = "Test Contact";
		document.data1.elements["*Delivery_Address"].value = "123 Elm";
		document.data1.elements["*Delivery_City"].value = "AnyTown";
		document.data1.elements["*Job_Storeroom"].value = "A12";
		document.data1.elements["*First_Name"].value = "Admin";
 		document.data1.elements["*Last_Name"].value = "admin";
		document.data1.elements["*Email"].value = "info@channelready.com";
		document.data1.elements["*Phone_Number"].value = "1112223333";
}

function checkEnter(e, strAction)
{ //e is event object passed from function invocation
	var characterCode //literal character code will be stored in this variable

	
	if(e && e.which)
	{ //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	}
	else
	{
		e = event;
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}

	if(characterCode == 13)
	{ //if generated character code is equal to ascii 13 (if enter key)
	
		if(strAction == "login")
		{
			formCheck('login', '../orders/order_step1.asp', 'data1', 'error_message'); //submit the form
			return;
		}
		if(strAction == "startpo")
		{
			formCheck2('startpo', '../orders/order_step2.asp', '', 'data1', 'error_message');
			return;
		}
		if(strAction == "search")
		{
			if(document.data1.keyword.value == "" || document.data1.keyword.value == null)
			{
				OpenPopup("no_keyword");
			}
			else {
			ShowResults();
			return;
			}
		}
	}
	else
	{
		return true;
	}
}

function checkSearchValue()
{
	if(document.data1.keyword.value == "")
	return false;
}


function PullSubCats(strName)
{
	//alert(document.getElementById(strName).value);
	
	if(document.getElementById(strName).value != 0)
	{
		document.data1.catid.value = document.getElementById(strName).value;
		document.data1.action = "html/catalog/results.asp";
		document.data1.submit();
	}
	else
	{
		OpenPopup("select_cat");
	}
}

function PullSubCatsFromLeftMenu(intCatID)
{
	document.data1.catid.value = intCatID;
	document.data1.action = "html/catalog/results.asp";
	document.data1.submit();
		
}

function ShowResults()
{
		//alert('keyword is ' + document.data1.keyword.value);
		var blnCheckSearchKeyword = CheckSearchKeyword();
		if (blnCheckSearchKeyword)
		{
		//document.data1.searchterm.value = document.data1.keyword.value;
		document.data1.action ="../catalog/search_results.asp";
		document.data1.submit();
		}
}


function ShowLargeCad(strImagePathName)
{
	
	if(strImagePathName != ";")
	{
		document.getElementById('image_largepop').style.visibility = "visible";
		document.images['cadlarge'].src = strImagePathName;
	}

}

function SetID(intID)
{
		//document.data1.prodid.value = intID;
		document.data1.action = "../catalog/product_details.asp?prodid=" + intID;
		document.data1.submit();
}

function CheckSearchKeyword()
{
	if(document.data1.keyword.value == "" || document.data1.keyword.value == null)
	{
		OpenPopup("no_keyword");
		return false;
	}
	else {
		return true;
	}
}