// JavaScript Document

function openPictureWindow(img,nm,picnm,w,h){
	openColorboxFile(pg,w,h,nm);
	//return false;
}
function openTellFriendWindow(pg,nm,w,h){
	openColorboxFile(pg,w,h);
	//return false;
}
// Generic function to open a window
function openAWindow( pg, winName, w, h, center, scroll) {
    openColorboxFile(pg,w,h);
	//return false;
}
function openGenericWindow(pg,nm,w,h,sc,ctr){
	openColorboxFile(pg,w,h);
	//return false;
}
function openCardWindow(pg,w,h){
	openColorboxCARD(pg,w,h,'Manage Your Credit Cards on File');
	//return false;
}
function openAdminCardWindow(pg,w,h){
	openColorboxFile(pg,w,h,'Payment Method');
	//return false;
}
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;
		openColorboxFile(url,350,150,'Rate Product');
	}
}

function openInfoWindow(pg,unique,nm,w,h,sc,ctr){
	openColorboxFile(pg,w,h);
	//return false;
}

function refreshParent(url){
	return true;
	window.parent.location.href=url;
}

function autoSubmit(form)
{
	window.location.href = form.shipMethod.options[form.shipMethod.selectedIndex].value;
}

function openColorboxCARD(hr,w,h,t){
	if(!w){
		w = "75%";
	}
	if(!h){
		h = "75%";
	}
	$.fn.colorbox({
		href:hr,
		title:t,
		width:w,
		height:h,
		iframe:"true",
		onClose:function(){  }
	}); 
	return false;
}

function openColorboxFile(hr,w,h,t){
	if(!w){
		w = "75%";
	}
	if(!h){
		h = "75%";
	}
	$.fn.colorbox({href:hr,title:t,width:w,height:h,iframe:"true"}); 
	return false;
}

function openColorboxHTML(ht,w,h,t){
	if(!w){
		w = "75%";
	}
	if(!h){
		h = "75%";
	}
	$.fn.colorbox({html:ht,title:t,width:w,height:h}); 
	return false;
}


button2 = new Image();
button2.src = "<?= SECUREWEB ?>/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;
}

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);
	openColorboxHTML(message,500,250);
	return false;
}
else
	return true;
}

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) {
		openColorboxHTML(txt,400,250);
	}
}

function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}


