// JavaScript Document

<!--
// Ticker startup
var $id = function (el)
{
	return document.getElementById(el);	
}
function startTicker()
{
	// Define run time values
	theCurrentStory     = -1;
	theCurrentLength    = 0;
	// Locate base objects
	if (document.getElementById) {	
		    theAnchorObject     = document.getElementById("tickerAnchor");
			runTheTicker();   	
		 }
	else {
            document.write("<style>.ticki{display:none;}.ticko{border:0px; padding:0px;}</style>");
            return true;
	}
}
// Ticker main run loop
function runTheTicker()
{
	var myTimeout;  
	// Go for the next story data block
	if(theCurrentLength == 0)
	{
		theCurrentStory++;
		theCurrentStory      = theCurrentStory % theItemCount;
		theStorySummary      = theSummaries[theCurrentStory].replace(/&quot;/g,'"');		
		theTargetLink        = theSiteLinks[theCurrentStory];
		theAnchorObject.href = theTargetLink;
		thePrefix 	     = "<span class=\"tickls\">" + theLeadString + "</span>";
	}
	// Stuff the current ticker text into the anchor
	theAnchorObject.innerHTML = thePrefix + 
	theStorySummary.substring(0,theCurrentLength) + whatWidget();
	// Modify the length for the substring and define the timer
	if(theCurrentLength != theStorySummary.length)
	{
		theCurrentLength++;
		myTimeout = theCharacterTimeout;
	}
	else
	{
		theCurrentLength = 0;
		myTimeout = theStoryTimeout;
	}
	// Call up the next cycle of the ticker
	setTimeout("runTheTicker()", myTimeout);
}
// Widget generator
function whatWidget()
{
	if(theCurrentLength == theStorySummary.length)
	{
		return theWidgetNone;
	}

	if((theCurrentLength % 2) == 1)
	{
		return theWidgetOne;
	}
	else
	{
		return theWidgetTwo;
	}
}

function send_form(formname){
document.formname.submit();
//alert(formname);
}
	
function openCenterWindow(URL,winName,w,h,features) {

  // if screen.dimension is true (available), 
  // then calculate the position using that value, else use a fixed value
  xPos = (screen.width) ? (screen.width-w)/2 : 50;
  yPos = (screen.height) ? (screen.height-h)/2 : 50;
  
  // assemble all window settings from calculations and parameters
  settings = 'height='+h+',width='+w+',top='+yPos+',left='+xPos+','+features
  
  // open the window
  window.open(URL,winName,settings);
}
	
	
function calculate_total(){
list_total = document.edit.user_quote_prod_orig_price.value * document.edit.user_quote_prod_qty.value;
ext_price = (1-(document.edit.user_quote_prod_discount.value * .01))*list_total;
//$compare_array = $user_quote->getProdCompArr($item->product_id, $cart->cart_id);
for(i=0;i<num;i++){
total +=ext_price;
}
return total;
}

function calculate_total_vb(){
list_total = document.edit.qi_prod_orig_price.value * document.edit.qi_prod_qty.value;
ext_price = (1-(document.edit.qi_prod_discount.value * .01))*list_total;
//$compare_array = $user_quote->getProdCompArr($item->product_id, $cart->cart_id);
for(i=0;i<num;i++){
total +=ext_price;
}
return total;
}

function replaceText(buttonId, text)
{
  if (document.getElementById)
  {
    var button=document.getElementById(buttonId);
    if (button)
    {
      if (button.childNodes[0])
      {
        button.childNodes[0].nodeValue=text;
      } 
	  else if (button.value)
      {
		//alert('no');
        button.value=text;
      }
      else// if (button.innerHTML)
      {
		//alert('go');
        button.innerHTML=text;
      }
	  
    }
  }
}

function show_promo(pc){
//alert(pc);

var ajaxRequest;  // The variable that makes Ajax possible!
		try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	
	} catch (e){
		
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			
			} catch (e){
				alert('no');
	
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		
		if(ajaxRequest.readyState == 4){	
		
		//var theArray = ajaxRequest.responseText;
			//eval(theArray);
	document.getElementById("promo_text").innerHTML = ajaxRequest.responseText;
	//document.getElementById("promo_text").value = "go";
	
		}
	}
	//if(pc_id>0){
	ajaxRequest.open("GET", "/includes/promo.php?pc="+pc, true);
	//}
	//else{
	//var opt_id = document.additem.option.value;
	//ajaxRequest.open("GET", "includes/options.php?opt_id="+opt_id, true);
	//}
	ajaxRequest.send(null); 
	
}


function getQtyDiscount(prod_id){
	//alert("hello");

	var ajaxRequest;  // The variable that makes Ajax possible!
		try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	
	} catch (e){
		
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			
			} catch (e){
				alert('no');
	
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		
		if(ajaxRequest.readyState == 4){	
		
			var theArray = eval(ajaxRequest.responseText);			
			
			
			if(theArray.length>1){
				//alert(theArray[0]);
			//eval("var theArray = ("+ajaxRequest.responseText+")");
			//var theText = ajaxRequest.responseText;
			//eval(theArray);
			
			//alert(theArray[0]);
	//for (i = document.search_form.cities.options.length; i >= 0; i--) {
		//document.search_form.cities.options[i] = null; 
	//}
	
	//load proper values
	replaceText("discHeader", "Quantity Discount!");
	//replaceText("discountTextOne", "Buy "+theArray[0]+" or more and save —<br>pay only <span class=\"red\"><b>"+theArray[1]+"</b></span> per unit!");
	document.getElementById("discountTextOne").innerHTML = "Buy "+theArray[0]+" or more and save —<br>pay only <span class=\"red\"><b>"+theArray[1]+"</b></span> per unit!";
		
			
			document.getElementById("prodPrice").innerHTML = theArray[2];	
			
			
			}	
			else{
				document.getElementById("prodPrice").innerHTML = theArray[0];	
			}
			
			
			
	//replaceText("discountTextTwo", theArray[1]);
	
	//document.getElementById("discount").value = discText;
	//document.getElementById("discount").appendChild(document.createTextNode(discText));
	
	
		}
	}
	if(prod_id>0){		
	ajaxRequest.open("GET", "/includes/options.php?prod_id="+prod_id, true);
		
	}else{
	
	var opt_id = document.additem.option.value;	
	ajaxRequest.open("GET", "/includes/options.php?opt_id="+opt_id, true);
	}
	ajaxRequest.send(null); 
	
}



function getTotal(){
	//alert('go');
	
	//var state_name = document.search_form.state_id.value;


	var ajaxRequest;  // The variable that makes Ajax possible!
		try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	
	} catch (e){
		
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			
			} catch (e){
				alert('no');
	
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		
		if(ajaxRequest.readyState == 4){	
		
			var theArray = ajaxRequest.responseText;
			eval(theArray);
			//alert(ajaxRequest.readyState);
	
	
	
		}
	}
	//if($dir==true){
	//ajaxRequest.open("GET", "../includes/cities.php?state_name="+state_name, true);
	//}else{
	ajaxRequest.open("GET", "/includes/cities.php?state_name="+state_name, true);
	//}
	ajaxRequest.send(null); 
	
}

	
function refreshParent() {
  if (window.opener && !window.opener.closed) {
       window.opener.location.reload();
       self.close();
    }
}

/*
Source: Webmonkey Code Library
Author: Nadav Savio
Author Email: nadav@wired.com
*/


// This next little bit of code tests whether the user accepts cookies.

var WM_acceptsCookies = false;
if(document.cookie == '') {
    document.cookie = 'WM_acceptsCookies=yes'; // Try to set a cookie.
    if(document.cookie.indexOf('WM_acceptsCookies=yes') != -1) {
	WM_acceptsCookies = true; 
    }// If it succeeds, set variable
} else { // there was already a cookie
  WM_acceptsCookies = true;
}

function WM_setCookie (name, value, hours, path, domain, secure) {
    if (WM_acceptsCookies) { // Don't waste your time if the browser doesn't accept cookies.
	var not_NN2 = (navigator && navigator.appName 
		       && (navigator.appName == 'Netscape') 
		       && navigator.appVersion 
		       && (parseInt(navigator.appVersion) == 2))?false:true;

	if(hours && not_NN2) { // NN2 cannot handle Dates, so skip this part
	    if ( (typeof(hours) == 'string') && Date.parse(hours) ) { // already a Date string
		var numHours = hours;
	    } else if (typeof(hours) == 'number') { // calculate Date from number of hours
		var numHours = (new Date((new Date()).getTime() + hours*3600000)).toGMTString();
	    }
	}
	document.cookie = name + '=' + escape(value) + ((numHours)?(';expires=' + numHours):'') + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'') + ((secure && (secure == true))?'; secure':''); // Set the cookie, adding any parameters that were specified.
    }
} // WM_setCookie

function WM_readCookie(name) {
    if(document.cookie == '') { // there's no cookie, so go no further
	return ''; 
    } else { // there is a cookie
	var firstChar, lastChar;
	var theBigCookie = document.cookie;
	firstChar = theBigCookie.indexOf(name);	// find the start of 'name'
	var NN2Hack = firstChar + name.length;
	if((firstChar != -1) && (theBigCookie.charAt(NN2Hack) == '=')) { // if you found the cookie
	    firstChar += name.length + 1; // skip 'name' and '='
	    lastChar = theBigCookie.indexOf(';', firstChar); // Find the end of the value string (i.e. the next ';').
	    if(lastChar == -1) lastChar = theBigCookie.length;
	    return unescape(theBigCookie.substring(firstChar, lastChar));
	} else { // If there was no cookie of that name, return false.
	    return '';
	}
    }	
} // WM_readCookie

function WM_killCookie(name, path, domain) {
  var theValue = WM_readCookie(name); // We need the value to kill the cookie
  if(theValue) {
      document.cookie = name + '=' + theValue + '; expires=Fri, 13-Apr-1970 00:00:00 GMT' + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:''); // set an already-expired cookie
  }
} // WM_killCookie

//qString = '?pfprompt='+WM_readCookie('pfprompt')+'&unique='+(Math.floor(100000*Math.random()));

var refURL = WM_readCookie('ref');
	if (refURL.length==0){
		//alert("Old is "+document.referrer);
		WM_setCookie ('ref', document.referrer, 720);
}

var recent_refURL = WM_readCookie('recent_ref');
	if (recent_refURL.length==0){
		//alert("New is "+document.referrer);
		WM_setCookie ('recent_ref', document.referrer, 1);
}

var landing_pgURL = WM_readCookie('landing_pg');
	if (landing_pgURL.length==0){
		WM_setCookie ('landing_pg', document.location, 720);
}

var recent_pgURL = WM_readCookie('recent_pg');
	if (recent_pgURL.length==0){
		WM_setCookie ('recent_pg', document.location, 1);
}

function useShipping(frm) { 
	 if (frm.address_type.click){
	//	 alert("same");
		  document.form1.$bill_fname.value=document.form1.$ship_fname.value;
		  document.form1.$bill_lname.value=document.form1.$ship_lname.value;
		  document.form1.$bill_addr1.value=document.form1.$ship_addr1.value;
		  document.form1.$bill_addr2.value=document.form1.$ship_addr2.value;
		  document.form1.$bill_city.value=document.form1.$ship_city.value;
		  document.form1.$bill_state.value=document.$ship_state.value;
		  document.form1.$bill_zip.value=document.form1.$ship_zip.value;
		  document.form1.$bill_phone.value=document.form1.$ship_phone.value;
		  document.form1.$bill_company.value=document.form1.$ship_company.value;
		  } 
	}
function useBilling(frm) { 
	 if (frm.address_type.click){
	//	 alert("same");
		  document.form1.$ship_fname.value=document.form1.$bill_fname.value;
		  document.form1.$ship_lname.value=document.form1.$bill_lname.value;
		  document.form1.$ship_addr1.value=document.form1.$bill_addr1.value;
		  document.form1.$ship_addr2.value=document.form1.$bill_addr2.value;
		  document.form1.$ship_city.value=document.form1.$bill_city.value;
		  document.form1.$ship_state.value=document.$bill_state.value;
		  document.form1.$ship_zip.value=document.form1.$bill_zip.value;
		  document.form1.$ship_phone.value=document.form1.$bill_phone.value;
		  document.form1.$ship_company.value=document.form1.$bill_company.value;
		  } 
	}
//--><!]]>

function showHide(name, val){
	//alert(name);
	//if(document.getElementById(name).style.display=='none'){
	//alert(name);
	document.getElementById(name).style.display=val;
	//}else{
	//document.getElementById(name).style.display="none";
	//}
}

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

e.style.display = 'block';
}

var add_range = 1;
function addSlot(num){
	if(num == add_range){
		var up = document.getElementById('add_slots');
		var down = document.getElementById('addnewlink');
		
		var dv = document.createElement("div");
		
		//dv.innerHTML = '<input type="file" name="upfile_' + upload_range + '" size="30" onchange="addUploadSlot('+(upload_range + 1)+')">';
		dv.innerHTML = '<table width="600" border="0" cellpadding="0" cellspacing="0"><tr class="rulebelow"><td class="color_b" style="padding-left:5px"><input name="catalog_name" type="text" size="26" maxlength="100"></td><td width="125" class="color_b"><p class="morespace">&nbsp;</p></td><td width="275" class="color_b" align="right" style="padding-right:5px"><p class="morespace">&nbsp;</p></td></tr><tr><td colspan="3" align="right"><a href="javascript:document.location=\''+ document.location +'\'"><img src="../images/cancel_btn.gif" class="cancelbtn"></a><input name="submit" type="image" value="Submit Changes" src="../images/red_submit.gif" alt="submit" align="middle" width="62" height="24" border="0" class="submitbtn"></td></tr></table>';
		
		
		down.innerHTML = "";
		up.appendChild(dv);
		down.appendChild(a);
		add_range++;
	}
}

function editSlot(name,id){
		var up = document.getElementById('add_slots');
		var cat_name = document.getElementById('catalog_name');
	
		var tdata = document.createElement("td");
		var dv = document.createElement("div");
		
		//dv.innerHTML = '<input type="file" name="upfile_' + upload_range + '" size="30" onchange="addUploadSlot('+(upload_range + 1)+')">';
		dv.innerHTML = '<table width="600" border="0" cellpadding="0" cellspacing="0"><tr><td colspan="3"><a href="javascript:document.location=\''+ document.location +'\'"><img src="../images/cancel_btn.gif" class="cancelbtn"></a><input name="submit" type="image" value="Submit Changes" src="../images/red_submit.gif" alt="submit" align="middle" width="62" height="24" border="0" class="submitbtn"></td></tr></table>';
		
		
		cat_name.innerHTML = '<input name="catalog_name_' + id + '" type="text" size="26" maxlength="100" value="' + name + '">';
		cat_name.appendChild(tdata);
		up.appendChild(dv);
		//down.appendChild(a);
		//add_range++;
	
}

var all_checked = false;
function checkAllBoxes(targetform){
var elem = eval(targetform).elements;
var btn = document.getElementById('btn_link');
var d=0;
var c=0;
  for(i = 0; i < elem.length; i++){
    if(elem[i].type == "checkbox"){
      //if(elem[i].checked == false){
	if(all_checked==false){
        elem[i].checked = true;
		if(btn){
		btn.innerHTML = 'Deselect All';
		}
		c++;
      }else{
		elem[i].checked = false;
		if(btn){
		btn.innerHTML = 'Select All';
		}
		d++;
	  }
	  
    }
  }
  if(c>0){
	all_checked = true; 
  }else{
	all_checked = false;  
  }
  btn.appendChild(a);
  return all_checked;
}


//function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
//{
  // var arVersion = navigator.appVersion.split("MSIE")
  // var version = parseFloat(arVersion[1])
  // if ((version >= 5.5) && (document.body.filters)) 
   //{
   //   for(var i=0; i<document.images.length; i++)
    //  {
      //   var img = document.images[i]
       //  var imgName = img.src.toUpperCase()
      //   if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
      ///   {
     //       var imgID = (img.id) ? "id='" + img.id + "' " : ""
        //    var imgClass = (img.className) ? "class='" + img.className + "' " : ""
        //    var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
        //    var imgStyle = "display:inline-block;" + img.style.cssText 
       //     if (img.align == "left") imgStyle = "float:left;" + imgStyle
         //   if (img.align == "right") imgStyle = "float:right;" + imgStyle
         //   if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
         //   var strNewHTML = "<span " + imgID + imgClass + imgTitle
        //    + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
       //     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         //   + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
         //   img.outerHTML = strNewHTML
        //    i = i-1
       //  }
   //   }
  // }    
//}
//window.attachEvent("onload", correctPNG);