//
// clean and check a field for only numbers
//
function doCheck(which) {

  // strip out these common characters "$ ,"
  var origStr = eval("document.forms.rfqForm['" + which + "'].value;");
  var newStr = origStr.replace(/\$/g, "");
  newStr = newStr.replace(/ /g, "");
  newStr = newStr.replace(/,/g, "");

  // check if only numbers were entered
  var checkOK = "0123456789";
  var checkStr = newStr;
  var allValid = true;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++) {
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkOK.length;  j++)
	  if (ch == checkOK.charAt(j))
		break;
	if (j == checkOK.length) {
	  allValid = false;
	  break;
	}
	if (ch != ",")
	  allNum += ch;
  }	  
  
  if (!allValid) {
	// show an alert message if non-valid characters were found
	alert("Please enter only numbers (0-9) in this field.\n" + 
		  "Non-numeric characters are not allowed.\n\n" +
		  "For example:\n" + 
		  "     5000 instead of $5,000\n" +
		  "     6000 instead of $5,000 - $7,000\n" + 
		  "     7000 instead of ~$7K");
	
	eval("document.forms.rfqForm[" + which + "].value=''"); // clear the bad field
	eval("document.forms.rfqForm[" + which + "].focus()");  // refocus the cursor in the bad field

  } else if (newStr != origStr) {	
	eval("document.forms.rfqForm[" + which + "].value=newStr"); // update the field w the cleaned up string
	
	// show an alert message if you cleaned up the field
	alert("Spaces, commas and dollar signs are not allowed and\n" + 
		  "have been removed. Please review the information and\n" +
		  "verify that it is correct.\n");	  
  }
}

function checkParent(which,num) {
  eval("document.forms.rfqForm." + which + "[" + num + "].checked=true");
}

function winopen(theurl) {
  window.open(theurl, 'outside', 'resizable,scrollbars,width=700,height=500');
}

function winopen2(theurl) {
  window.open(theurl, 'outside', 'resizable,width=500,height=400');
}

function pop() {
  hwin=window.open('', '_hwin', 'resizable=1,width=350,height=215,scrollbars=yes');
  hwin.forward;
  hwin.focus();
  hwin.rwin=top;
  hwin.rwin.helpwin=1;
}

function pop2() {
  hwin=window.open('', '_hwin', 'resizable=1,width=350,height=400,scrollbars=yes');
  hwin.forward;
  hwin.focus();
  hwin.rwin=top;
  hwin.rwin.helpwin=1;
}

function pop3() {
  hwin=window.open('', '_hwin', 'resizable=1,width=700,height=500,scrollbars=yes');
  hwin.forward;
  hwin.focus();
  hwin.rwin=top;
  hwin.rwin.helpwin=1;
}

function pop4() {
  hwin=window.open('', '_hwin', 'resizable=1,width=640,height=400,scrollbars=yes');
  hwin.forward;
  hwin.focus();
  hwin.rwin=top;
  hwin.rwin.helpwin=1;	
}

function popsample() {
  hwin=window.open('', '_hwin', 'resizable=1,width=535,height=850,scrollbars=yes');
  hwin.forward;
  hwin.focus();
  hwin.rwin=top;
  hwin.rwin.helpwin=1;
}
function popsubmit() {
  hwin=window.open('', '_hwin', 'resizable=1,width=450,height=500,scrollbars=yes');
  hwin.forward;
  hwin.focus();
  hwin.rwin=top;
  hwin.rwin.helpwin=1;
}

function poptips() {
  hwin=window.open('', '_hwin', 'resizable=1,width=680,height=680,scrollbars=yes');
  hwin.forward;
  hwin.focus();
  hwin.rwin=top;
  hwin.rwin.helpwin=1;
}

// Form Help Popup
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function P7_autoLayers() { //v1.5 by PVII
 var g,b,k,f,u,k,j,args=P7_autoLayers.arguments,a=parseInt(args[0]);if(isNaN(a))a=0;
 if(!document.p7setc){p7c=new Array();document.p7setc=true;for(u=0;u<10;u++){
 p7c[u]=new Array();}}for(k=0;k<p7c[a].length;k++){if((g=MM_findObj(p7c[a][k]))!=null){
 b=(document.layers)?g:g.style;b.visibility="hidden";}}for(k=1;k<args.length;k++){
 if((g=MM_findObj(args[k]))!=null){b=(document.layers)?g:g.style;b.visibility="visible";f=false;
 for(j=0;j<p7c[a].length;j++){if(args[k]==p7c[a][j]) {f=true;}}
 if(!f){p7c[a][p7c[a].length++]=args[k];}}}
}

// ***** Please leave this courtesy note in *****
// *
// * downloaded for free from http://www.summerholiday.org/freecode/
// *
// ***** Thank you *****
// Modified by Mark Lackey for BuyerZone.com July 12, 2002

rhrn = new Date();
rhrnt1 = rhrn.getTime();
rhrns1 = rhrn.getSeconds();
rhrnm1 = rhrn.getMinutes();
rhrnh1 = rhrn.getHours();

trackCookie = GetCookie('tracker_id');

if(trackCookie==null || trackCookie.indexOf('http') < 0){

	cookievar1 = window.location + "||" + document.referrer;

	SetCookie ('tracker_id', cookievar1);

	if (GetCookie('tracker_id') != cookievar1)
	{
		//cookiePop();
	}

}

function GetCookie(cookieName){
	var theCookie=""+document.cookie;
	var ind=theCookie.indexOf(cookieName);
	if (ind==-1 || cookieName=="") return null;
	var ind1=theCookie.indexOf(';',ind);
	if (ind1==-1) ind1=theCookie.length;
	return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

function SetCookie(cookieName,cookieValue){
	//document.cookie = cookieName + "=" +escape(cookieValue) + ";"
	path="/";
        var curCookie = cookieName + "=" + escape(cookieValue) + ((path) ? "; path=" + path : "");
	document.cookie = curCookie;
}

function SetCookieWithExpiration(cookieName,cookieValue){
	//document.cookie = cookieName + "=" +escape(cookieValue) + ";"
	var days = 60;
	var path = "/";
	var date = new Date();
	date.setTime(date.getTime()+(days*24*60*60*1000));
	var expiration = date.toGMTString();
    var curCookie = cookieName + "=" + escape(cookieValue) + ((expiration) ? "; expires=" + expiration : "") + ((path) ? "; path=" + path : "");
	document.cookie = curCookie;
}

function DeleteCookie(cookieName,cookieValue){
	var path="/";
	var date = new Date();
	date.setTime(date.getTime()+(-1*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	var curCookie = cookieName + "=" + escape(cookieValue) + ((path) ? "; path=" + path : "") + expires;
	document.cookie = curCookie;	
}

function cookiePop() {
  hwin=window.open('../../services/quotezone/cookies.html', '_hwin', 'status=yes,toolbar=no,resizable=1,width=350,height=400,scrollbars=yes');
  hwin.forward;
  hwin.rwin=top;
  hwin.rwin.helpwin=1;
  hwin.focus();
}

function Rcertify() {
popupWin = window.open('http://www.bbbonline.org/cks.asp?id=1030620151733161', 'Participant','location=yes,scrollbars=yes,width=450,height=300'); 
window.name = 'opener';
} 

// Label Hack (Jason Moens)
function doIt(name){
	//alert(name);
	var DHTML = (document.getElementById || document.all || document.layers);
	if(DHTML){
		element = document.getElementById(name);
		var divs = document.getElementsByTagName('*');
		  for (var i = 0; i < divs.length; i++) {
			var div = divs[i];
			if (div == element) {
			  //alert('found at ' + i);
			  var gotIt = divs[i-1];
			  if(gotIt.checked == true){
			    gotIt.checked = false;
			  }else {
			    gotIt.checked = true;
			  }
			}
		  }
		
	}
}

/***********************************************
* Cool DHTML tooltip script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetxpoint=-60 //Customize x offset of tooltip
var offsetypoint=20 //Customize y offset of tooltip
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thecolor, thewidth){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth)
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
else if (curX<leftedge)
tipobj.style.left="5px"
else
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetxpoint+"px"

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight)
tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
else
tipobj.style.top=curY+offsetypoint+"px"
tipobj.style.visibility="visible"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

document.onmousemove=positiontip

// NEW (Modified) DESIGN: Interstitial page/external links popup
// Added by Amy 8/2006, edited 11/2006
window.onload = prepareLinks;

function prepareLinks() {
  if (!document.getElementsByTagName) return false;
  var links = document.getElementsByTagName("a");
  for (var i=0; i<links.length; i++) {
    if (links[i].className == "external") {
      links[i].onclick = function() {
	  	document.linkForm.hiddenField.value = this.getAttribute("href");
		var url = "/show-external-links.jhtml?linkurl=" + this.getAttribute("href");
        popUp(url);
        return false;
      }
    }
  }
}

function popUp(winURL) {
  window.open(winURL,"popup","width=600,height=300,toolbar=1,scrollbars=1,location=1,status=1,menubar=1,resizable=1");
}

// added by Karen Lawes - Nov 2006 - drop down for links
function getsupport ( selectedtype ){
document.supportform.supporttype.value = selectedtype ;
document.supportform.submit() ;
}
// added by Karen Lawes - Nov 2006 - pop up window
var newwindow;
function poptastic(url){
	newwindow=window.open(url,'name','height=115,width=250,left=0,top=200,toolbar=no,scrollbars=no,menubar=no,dependent=yes');
	if (window.focus) {newwindow.focus()}
}

// added by Karen Lawes - Nov 2006 - Star rater
function go(){
	window.location=document.guideform.guidelinks.options[document.guideform.guidelinks.selectedIndex].value
}

var numarray = new Array( "", "poor", "okay", "good", "great", "excellent" );

function showTxt(num,question){
	document.getElementById( question ).innerHTML = numarray[num];
}

function getUrl2Params(){
	var _retval = new Array();
	var qString = parent.location.href; 	
	if( qString.indexOf("question1=") > 0 ){
		var first = qString.split("question1=")[1].split("&question2")[0];
		var second = qString.split("question2=")[1]
		if( second.indexOf("#") != null ){
			second = second.split("#")[0];
		}
		if( second.indexOf("&") != null ){
			second = second.split("&")[0];	
		}
		_retval[0] = first;
		_retval[1] = second;		
	}else{
		_retval[0] = "-";
		_retval[1] = "-";	
	}
	return _retval;
}
function getUrl1Param(){
	var _retval = new Array();
	var qString = parent.location.href;  
	if( qString.indexOf("question1=") > 0 ){
		var first = qString.split("question1=")[1];
		if( first.indexOf("#") != null ){
			first = first.split("#")[0];
		}
		if( first.indexOf("&") != null ){
			first = first.split("&")[0];	
		}
		_retval[0] = first;		
	}else{
		_retval[0] = "-";	
	}
	return _retval;
}

/***********************************************
* Drop Down/ Overlapping Content- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function getposOffset(overlay, offsettype){
var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
var parentEl=overlay.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function overlay(curobj, subobjstr, opt_position){
if (document.getElementById){
var subobj=document.getElementById(subobjstr)
subobj.style.display=(subobj.style.display!="block")? "block" : "none"
var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0) 
var ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0)
subobj.style.left=xpos+"px"
subobj.style.top=ypos+"px"
return false
}
else
return true
}

function overlayclose(subobj){
document.getElementById(subobj).style.display="none"
}

/* variable to tell if the rfi popup should occur */
var isRFQ = 0;

if( (document.referrer).indexOf(".co.uk") > -1 && GetCookie("popUK") != "true" ){
	//myRef = window.open('/uk/popup.html','mywin','left=20,top=20,width=530,height=330');
	showUKHtmlPopup();
	SetCookieWithExpiration("popUK","true");
}

function getDimensions(){
	var dimensions = {width: 0, height: 0};
    if (window.innerWidth && window.innerHeight) {
        dimensions.width = window.innerWidth;
        dimensions.height = window.innerHeight;
    }else if (document.documentElement) {
        dimensions.width = document.documentElement.offsetWidth;
        dimensions.height = document.documentElement.offsetHeight;		
    }
	return dimensions;
}

function showUKHtmlPopup(){
	var popWidth = 500;
	var dimensions = getDimensions();
	var leftIndent = (dimensions.width - popWidth) / 2;
	var toLoad = "<div id='popup' style='left:" + leftIndent + "px; position:absolute; top:200px; width:" + popWidth + "px;'></div>";
	$(document).ready(function(){
		$(toLoad).appendTo("body");
		$("#popup").load("/uk/popup-new-uk3.html");		
	});	
}

/***********************************************
* Show Hint script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
		
var horizontal_offset="9px" //horizontal offset of hint box from anchor link

/////No further editting needed

var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
var ie=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 iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
}
else{
var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
}
return edgeoffset
}

function showhint(menucontents, obj, e, tipwidth){
if ((ie||ns6) && document.getElementById("hintbox")){
dropmenuobj=document.getElementById("hintbox")
dropmenuobj.innerHTML=menucontents
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (tipwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=tipwidth
}
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
dropmenuobj.style.visibility="visible"
obj.onmouseout=hidetip
}
}

function hidetip(e){
dropmenuobj.style.visibility="hidden"
dropmenuobj.style.left="-500px"
}

function createhintbox(){
var divblock=document.createElement("div")
divblock.setAttribute("id", "hintbox")
document.body.appendChild(divblock)
}

if (window.addEventListener)
window.addEventListener("load", createhintbox, false)
else if (window.attachEvent)
window.attachEvent("onload", createhintbox)
else if (document.getElementById)
window.onload=createhintbox

/********************************************************
*  script for keeping track of the number of characters
*  user has entered in 'Additional Requirements' text box
*  and limiting to specified value in input field.
*  claude b. - initally developped in summer 08
*  added to this file in november 08
********************************************************/

function charCounter(field, counter, maxchar) {
  if (field.value.length > maxchar)
	field.value = field.value.substring(0, maxchar);
  else
	counter.value = maxchar - field.value.length;}

/********************************************************
*  end of character tracking script
********************************************************/

/********************************************************
*  script for grabbing zipcode, if present, and
*  inserting into zip field.
********************************************************/
//$(document).ready(function(){
//	function get_cookie(Name) {
//	  var search = Name + "=";
//	  var returnvalue = "";
//	  if (document.cookie.length > 0) {
//		offset = document.cookie.indexOf(search);
//		if (offset != -1) {
//		  offset += search.length;
//		  end = document.cookie.indexOf(";", offset);
//		  if (end == -1)
//			end = document.cookie.length;
//			returnvalue = unescape(document.cookie.substring(offset, end));
//		  }
//		}
//	  return returnvalue;
//	}

//    if ((get_cookie('999999')!=null) && (get_cookie('999999')!='') ){
//		  $("#q999999").val(get_cookie('999999'));
//    }
//});	

/********************************************************
*  end of zip grabbing script
********************************************************/
