// JavaScript Document
var openPictureWin='';
var openTellFriendWin='';
var openGenericWin='';
var openCardWin='';
function openPictureWindow(img,nm,picnm,w,h){
	window.openPictureWin=dhtmlwindow.open(picnm, "iframe", img, nm, "width=" + w + "px,height=" + h + "px,resize=1,scrolling=0,center=1", "recal")
	window.openPictureWin.onclose=function(){ 
		return true;
	}
}
function openTellFriendWindow(pg,nm,w,h){
	window.openTellFriendWin=dhtmlwindow.open('tellf', "iframe", pg, nm, "width=" + w + "px,height=" + h + "px,resize=1,scrolling=0,center=1", "recal")
	window.openTellFriendWin.onclose=function(){ 
		return true;
	}
}

function openGenericWindow(pg,nm,w,h,sc,ctr){
	if(!nm || nm == ''){
		nm = 'genw';
	}
	window.openGenericWin=dhtmlwindow.open(nm, "iframe", pg, nm, "width=" + w + "px,height=" + h + "px,resize=1,scrolling=" + sc + ",center=" + ctr, "recal")
	window.openGenericWin.onclose=function(){ 
		return true;
	}
}

function openCardWindow(pg,w,h){
	window.openCardWin=dhtmlwindow.open('card', "iframe", pg, 'Payment Method', "width=" + w + "px,height=" + h + "px,resize=1,scrolling=0,center=1", "recal")
	window.openCardWin.onclose=function(){ 
		window.location.href='payment.php';
		return true;
	}
}

function openAdminCardWindow(pg,w,h){
	window.openCardWin=dhtmlwindow.open('card', "iframe", pg, 'Payment Method', "width=" + w + "px,height=" + h + "px,resize=1,scrolling=0,center=1", "recal")
	window.openCardWin.onclose=function(){ 
		return true;
	}
}

function submitRating(iid,ca){
	if( document.getElementById('ratingvote') ){
		var vote = document.getElementById('ratingvote').options[document.getElementById('ratingvote').selectedIndex].value;
		var url = "/log_rating.php?itemID=" + iid + "&CA=" + ca + "&vote=" + vote;
		openGenericWindow(url,'Rate Product',300,150,1,1);
	}
}

function refreshParent(url){
	return true;
	window.parent.location.href=url;
}


function autoSubmit(form)
{
	window.location.href = form.shipMethod.options[form.shipMethod.selectedIndex].value;
}

button2 = new Image();
button2.src = "§/images/submitSecureButton-clicked.gif";
var theForm;
var requestSubmitted = false;
function disableButton(btn,form,buttonType) {
	if (!requestSubmitted){
		if (buttonType != null) {
			var buttonName = buttonType;
			btn.src = buttonName.src; // image swap happens here
		}
		theForm = form;
		btn.disabled = true;
		requestSubmitted = true;
		setTimeout("submitIt()", 250);
	} else {
		return false;
	}
}
function submitIt() {
	theForm.submit();
	return false;
}



// Generic function to open a window
function openAWindow( pageToLoad, winName, width, height, center, scroll) {
                        
    // if 'center' == 1, then center window, otherwise put in top left corner
    xposition=0; yposition=0;
    if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
        xposition = (screen.width - width) / 2;
        yposition = (screen.height - height) / 2;
    }

    // Window Properties
    args = "width=" + width + "," 
    + "height=" + height + "," 
    + "location=0," 
    + "menubar=0,"
    + "resizable=1,"
    + "scrollbars=" + scroll + ","
    + "status=0," 
    + "titlebar=0,"
    + "toolbar=0,"
    + "hotkeys=0,"
    + "screenx=" + xposition + ","  //NN Only
    + "screeny=" + yposition + ","  //NN Only
    + "left=" + xposition + ","     //IE Only
    + "top=" + yposition;           //IE Only

    // open and focus window
    newWin = window.open( pageToLoad,winName,args );
    newWin.focus();
}

function goback()
{
	window.history.go(-1)
}

function goback2()
{
	window.history.go(-2)
}

function checkrequired(which) {
var message = "____________________________________________\n\n";
message +="The form was not submitted due to the following error(s).\n";
message += "Please correct these errors and resubmit\n";
message += "____________________________________________\n\n";
message += "The following required fields are empty:\n";

var pass=true;
var comma = "";
if (document.images) {
	for (i=0;i<which.length;i++) {
		var tempobj=which.elements[i];
		if (tempobj.name.substring(0,8)=="required") {
			if (((tempobj.type=="text"||tempobj.type=="textarea"||tempobj.type=="password")&&
			tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
			tempobj.selectedIndex==0)||(tempobj.type=="checkbox"&&
			!tempobj.checked)) {
				shortFieldName=tempobj.name.substring(8,30);
				message += "\n" + shortFieldName.replace(/_/g," ");
				pass=false;
				comma = ", ";
         			}
     		 }
   	}
}
if (!pass) {
	alert(message);
	return false;
}
else
	return true;
}

function checkoptions(which) {
	var message = "____________________________________________\n\n";
	message += "Please select the options for the following:\n";

	var pass=true;
	var comma = "";
	if (document.images) {
		for (i=0;i<which.length;i++) {
			var tempobj=which.elements[i];
			if (tempobj.name.substring(0,9)=="reqoption") {
				if (((tempobj.type=="text"||tempobj.type=="textarea"||tempobj.type=="password")&&
				tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
				tempobj.selectedIndex==0)) {
					shortFieldName=tempobj.name.substring(9,30);
					message += "\n" + shortFieldName.replace(/_/g," ");
					pass=false;
					comma = ", ";
         			}
     			 }
			if (tempobj.name.substring(0,13)=="requnivoption") {
				if (((tempobj.type=="text"||tempobj.type=="textarea"||tempobj.type=="password")&&
				tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
				tempobj.selectedIndex==0)) {
					shortFieldName=tempobj.name.substring(13,34);
					message += "\n" + shortFieldName.replace(/_/g," ");
					pass=false;
					comma = ", ";
         			}
     			 }
			if (tempobj.name.substring(0,11)=="req_option_") {
				if (((tempobj.type=="text"||tempobj.type=="textarea"||tempobj.type=="password")&&
				tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
				tempobj.selectedIndex==0)) {
					shortFieldName=tempobj.name.substring(11,32);
					message += "\n" + shortFieldName.replace(/_/g," ");
					pass=false;
					comma = ", ";
         			}
     			 }
   		}
	}
	if (!pass) {
		alert(message);
		return false;
	}
	else
		return true;
}

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 MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function autoPriceFilterSubmit(form) {
		window.location.href = form.pfilter.options[form.pfilter.selectedIndex].value;
}

function autoMfgFilterSubmit(form) {
		window.location.href = form.mfgfilter.options[form.mfgfilter.selectedIndex].value;
}
  
function detectingFLASH() {
  var browser = navigator.userAgent.toLowerCase();
  flashVersion = 0;	
	// NS3+, Opera3+, IE5+ Mac
	if ( navigator.plugins != null && navigator.plugins.length > 0 ) {
		var flashPlugin = navigator.plugins['Shockwave Flash'];
		if ( typeof flashPlugin == 'object' ) { 
			if ( flashPlugin.description.indexOf('7.') != -1 ) flashVersion = 7;
			else if ( flashPlugin.description.indexOf('6.') != -1 ) flashVersion = 6;
			else if ( flashPlugin.description.indexOf('5.') != -1 ) flashVersion = 5;
			else if ( flashPlugin.description.indexOf('4.') != -1 ) flashVersion = 4;
			else if ( flashPlugin.description.indexOf('3.') != -1 ) flashVersion = 3;
		}
	} // IE4+ Win32 (VBscript)
	else if ( browser.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && browser.indexOf("win")!= -1 && browser.indexOf("16bit")== -1 ) {
	  document.write('<scr' + 'ipt language="VBScript"> n');
		document.write('on error resume next n');
		document.write('DIM obFlash n');
		document.write('SET obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.7") n');
		document.write('IF IsObject(obFlash) THEN n');
		document.write('flashVersion = 7 n');
		document.write('ELSE SET obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.6") END IF n');
		document.write('IF flashVersion < 7 and IsObject(obFlash) THEN n');
		document.write('flashVersion = 6 n');
		document.write('ELSE SET obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.5") END IF n');
		document.write('IF flashVersion < 6 and IsObject(obFlash) THEN n');
		document.write('flashVersion = 5 n');
		document.write('ELSE SET obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.4") END IF n');
		document.write('IF flashVersion < 5 and IsObject(obFlash) THEN n');
		document.write('flashVersion = 4 n');
		document.write('ELSE SET obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.3") END IF n');
		document.write('IF flashVersion < 4 and IsObject(obFlash) THEN n');
		document.write('flashVersion = 3 n');
		document.write('END IF');
	  document.write('</scr' + 'ipt> n');
  } // no Flash
  else {
	flashVersion = -1;
  }
return flashVersion;
}


function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}



var whichBrowser = navigator.appName;
var whichVersion = parseFloat(navigator.appVersion);
var isOld;
if(((whichBrowser=='Microsoft Internet Explorer')&(whichVersion>=4)) | ((whichBrowser=='Netscape')&(whichVersion>=5))){
	isOld = 0;
	removeOldBrowserAlert();
} else { 
	isOld = 1;
	
}      
var alreadyWarned = 0;
function getPrice(qty){
	if(isOld){
		return;
	}

	if(!qty){
		var qty = 1;
	}
	var type = "";
	var value = "";
	var baseCost = eval(price);
	var retailCost = eval(retailPrice);
	var totalCost = "";
	for(var $i=0;$i<document.addToCart.length;$i++){
		var tmp = document.addToCart.elements[$i];
		if(tmp.type == "radio" && tmp.checked){
			if(tmp.id != '00.00'){
				value = eval(tmp.id);
				baseCost = baseCost + value;
			}
		} else if (tmp.type.toString().charAt(0)=="s" 
			&& tmp[tmp.selectedIndex].value != 0 
			&& tmp[tmp.selectedIndex].value != ''
			&& tmp.name != "ItemQuantity"){
			value = eval(tmp[tmp.selectedIndex].id);
			baseCost = baseCost + value;
		} else if (tmp.type == "checkbox" && tmp.checked){
			if(tmp.id != '00.00'){
				value = eval(tmp.id);
				baseCost = baseCost + value;
			}
		}
	}
	totalCost = baseCost * qty;
	updateDisplays(baseCost,retailCost,totalCost);
}

function updateDisplays(unitCost,retailCost,totalCost) {
   	var dollars = Math.floor(unitCost);
   	var cents = unitCost - dollars;
   	cents = Math.round(cents*100);
   	if(cents==0){
		cents = ".00";
	} else if(cents<10){
		cents = ".0"+cents;
	} else{
		cents = "."+cents;
	}	
	if(document.getElementById('unitprice')){
		document.getElementById('unitprice').innerHTML = "$"+dollars+cents; 
	}
	if(document.getElementById('unitprice2')){
		document.getElementById('unitprice2').innerHTML = "$"+dollars+cents;
	}
  
   	var dollars = Math.floor(retailCost);
   	var cents = retailCost - dollars;
   	cents = Math.round(cents*100);
   	if(cents==0){
		cents = ".00";
	} else if(cents<10){
		cents = ".0"+cents;
	} else{
		cents = "."+cents;
	}	
	if(document.getElementById('retailprice')){
		document.getElementById('retailprice').innerHTML = "$"+dollars+cents; 
	}
	if(document.getElementById('retailprice2')){
		document.getElementById('retailprice2').innerHTML = "$"+dollars+cents;
	}

	var dollars = Math.floor(totalCost);
   	var cents = totalCost - dollars;
   	cents = Math.round(cents*100);
   	if(cents==0){
		cents = ".00";
	} else if(cents<10){
		cents = ".0"+cents;
	} else{
		cents = "."+cents;
	}
	if(document.getElementById('totalprice')){
   		document.getElementById('totalprice').innerHTML = "$"+dollars+cents; 
	}
	if(document.getElementById('totalprice2')){
   		document.getElementById('totalprice2').innerHTML = "$"+dollars+cents; 
	}
}

function showOldBrowserAlert() {
	var msg = "Display of pricing changes requires Netscape 6.0+ or Internet Explorer 5.0+.\n";
	msg += "The correct price will be displayed after you select your options and add the item to your cart.\n\n";
	msg += "This does not affect your ability to purchase items from our store, \n";
	msg += "so please continue to shop and we apologize for this annoying message.\n\n";
	msg += "If you experience any problems ordering from us, please call us Toll-Free \n";
	msg += "at the number above for assistance with your purchase.  Thank You.";
   	alert(msg);
	alreadyWarned = 1;
}

function removeOldBrowserAlert(){
	if(document.getElementById('browserAlert')){
		document.getElementById('browserAlert').innerHTML = "";
	}
}
