// JavaScript Document

var openPictureWin='';
var openTellFriendWin='';
var openGenericWin='';
var openCardWin='';
var openInfoWin='';
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 openInfoWindow(pg,unique,nm,w,h,sc,ctr){
	window.openInfoWin=dhtmlwindow.open(unique, "iframe", pg, nm, "width=" + w + "px,height=" + h + "px,resize=0,scrolling=1,center=" + ctr, "recal")
	window.openInfoWin.onclose=function(){ 
		return true;
	}
}

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) {
    openInfoWindow(pageToLoad,winName,'',width,height,scroll,center);
    return;
}

function goback()
{
	window.history.go(-1)
}

function goback2()
{
	window.history.go(-2)
}

function checkrequired(which,margin) {
var message = "";
message += "The form was not submitted due to the following error(s).<br>\n";
message += "The following required fields are empty:<br>\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 += "<br> &raquo; " + shortFieldName.replace(/_/g," ");
				pass=false;
				comma = ", ";
         			}
     		 }
   	}
}
//message += "</ol>\n";
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;
	}
}

// constants to define the title of the alert and button text.
var ALERT_TITLE = "Oops!";
var ALERT_BUTTON_TEXT = "Close";
var ALERT_HEIGHT_MARGIN = "150px";


// over-ride the alert method only if this a newer browser.
// Older browser will see standard alerts
if(document.getElementById) {
	window.alert = function(txt) {
		createCustomAlert(txt);
	}
}


function createCustomAlert(txt) {
	// shortcut reference to the document object
	d = document;
	
	

	// if the modalContainer object already exists in the DOM, bail out.
	if(d.getElementById("modalContainer")) return;

	// create the modalContainer div as a child of the BODY element
	mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
	mObj.id = "modalContainer";
	 // make sure its as tall as it needs to be to overlay all the content on the page
	mObj.style.height = document.documentElement.scrollHeight + "px";
	
	

	// create the DIV that will be the alert 
	alertObj = mObj.appendChild(d.createElement("div"));
	alertObj.id = "alertBox";
	alertObj.style.marginTop = ALERT_HEIGHT_MARGIN;
	// MSIE doesnt treat position:fixed correctly, so this compensates for positioning the alert
	if(d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";
	// center the alert box
	alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth)/2 + "px";

	// create an H1 element as the title bar
	h1 = alertObj.appendChild(d.createElement("h1"));
	h1.appendChild(d.createTextNode(ALERT_TITLE));

	// create a paragraph element to contain the txt argument
	msg = alertObj.appendChild(d.createElement("p"));
	msg.innerHTML = txt;
	
	// create an anchor element to use as the confirmation button.
	btn = alertObj.appendChild(d.createElement("a"));
	btn.id = "closeBtn";
	btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT));
	btn.href = "#";
	// set up the onclick event to remove the alert when the anchor is clicked
	btn.onclick = function() { removeCustomAlert();return false; }

	
}

// removes the custom alert from the DOM
function removeCustomAlert() {
	document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
}
