// Rollover Function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 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_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}// Pop-up Function 1function CSOpenWindow(action) {	var wf = "";		wf = wf + "width=" + action[3];	wf = wf + ",height=" + action[4];	wf = wf + ",resizable=" + (action[5] ? "yes" : "no");	wf = wf + ",scrollbars=" + (action[6] ? "yes" : "no");	wf = wf + ",menubar=" + (action[7] ? "yes" : "no");	wf = wf + ",toolbar=" + (action[8] ? "yes" : "no");	wf = wf + ",directories=" + (action[9] ? "yes" : "no");	wf = wf + ",location=" + (action[10] ? "yes" : "no");	wf = wf + ",status=" + (action[11] ? "yes" : "no");			window.open(action[1],action[2],wf);}// Pop-up function 2function CSURLPopupShow(formName, popupName, target) {	var form  = CSFindElement(formName);	var popup = form.elements[popupName];	window.open(popup.options[popup.selectedIndex].value, target);	popup.selectedIndex = 0;}// Confirm Delete Orderfunction askDelete(idOrder) {
  if(!window.confirm("Are you sure you want to delete Order " + idOrder + "?")) 
	return false;
  return true;	
}

// Confirm Delete Userfunction askDeleteUser(idUser) {
  if(!window.confirm("Are you sure you want to delete User " + idUser + "?")) 
	return false;
  return true;	
}

// Confirm Delete Orderfunction askDeleteCat(CatTitle) {
  if(!window.confirm("Are you sure you want to delete the " + CatTitle + " category?")) 
	return false;
  return true;	
}

// Menu Items Rollover
function showItem(title,text,image,evt){

	with (document.getElementById('Item').style){
		
		str = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" width=\"320\">";
		str +=	"<tr>";
		str +=	"		<td bgcolor=\"#DA851B\">";
		str +=	"			<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"318\">";
		str +=	"				<tr>";
		str +=	"					<td bgcolor=\"#FFFFFF\" align=\"center\">";
		str +=	"						<table border=\"0\" cellspacing=\"6\" cellpadding=\"0\" width=\"314\">";
		str +=	"							<tr>";
		if (image){
			str +=	"							<td width=\"120\">";
			str +=	"								<div class=\"small\">";
			str +=	"									<img src=\"/images/products/small/" + image + "\" width=\"120\">";
			str +=	"								</div>";
			str +=	"							</td>";
		}
		str +=	"								<td valign=\"top\">";
		str +=	"									<div class=\"small\">";
		str +=	"										<h2>" + title + "</h2>";
		if (text) {
			str +=	"										<font color=\"#999966\">" + text + "</font></div>";
		}
		else {
			str +=	"										<font color=\"#999966\"><b></b></font></div>";
		}
		str +=	"								</td>";
		str +=	"							</tr>";
		str +=	"						</table>";
		str +=	"					</td>";
		str +=	"				</tr>";
		str +=	"			</table>";
		str +=	"		</td>";
		str +=	"	</tr>";
		str +=	"</table>";
		str += "<br>";
	
		
		visibility = 'visible';
		document.getElementById('Item').innerHTML = str;
		
		if (document.all){

			left = evt.x;
			top = evt.y + (document.body.scrollTop + 10);

		}

		else{

			left = evt.pageX;
			top = evt.pageY;

		}
		
	}

}
		
// Hide Menu Items Rollover
function hideItem(){

		document.getElementById('Item').style.visibility='hidden';

}

// Hide Div Pass - Replace top if neccessary
function hideDiv(idDiv){
		document.getElementById(idDiv).style.visibility='hidden';
}
function showDiv(idDiv){
		document.getElementById(idDiv).style.visibility='visible';
}

// ValidateField
// Use this onBlur="checkInput(this)" in input tag
function checkInput(element) {
  if (element.value == "")
    alert("Please enter a value!");
}

function IsANumber(formField)
{
var valid = "0123456789"
var ok = "yes";
var temp;

	for (var i=0; i < formField.value.length; i++)
	{
		temp = "" + formField.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
		return false;
	}
}


function ValidateOnBlur(formField, minimumAllowed)
{
	if (IsANumber(formField) == false)
	{
		alert("Please enter a number.");
		formField.focus();
		formField.select();
		return;
	}
	if (formField.value < minimumAllowed && formField.value != 0)
	{
		{
			alert("There is a minimum order of " + minimumAllowed + " for this item.");
		}
		formField.focus();
		formField.select();
		return;
	}
}

//ModifyOrder Functions
function add_ItemTotal(fldQty,fldPrice,fldSPrice,fldITotal) {
	var iTotal;
	var q = fldQty.value;
	var op = fldPrice.value;
	var sp = fldSPrice.value;
	
	if (sp > 0){
		iTotal = parseFloat(Math.round((q * sp)*100)/100)
	}
	else {
		iTotal = Math.round((q * op)*100)/100
	}
	
	fldITotal.value = iTotal;
	document.forms.frmModify.txtOrderSubTotal.focus();
	return iTotal;
}

function add_Weight(fldQty,fldWeight,fldTWeight) {
	var iTotal;
	var q = fldQty.value;
	var w = fldWeight.value;
	
	iTotal = Math.round((q * w)*100)/100
	
	fldTWeight.value = iTotal;
	return;
}

function add_SubTotal() {
	var loop=0, sum=0;
	for (loop = arguments.length-1; loop>=0; loop--)
		sum += parseFloat(arguments[loop]);
	
	document.forms.frmModify.txtOrderSubTotal.value = Math.round(sum*100)/100;
	document.forms.frmModify.txtOrderTotal.focus();
	return;
}

function add_Total() {
	var loop=0, sum=0;
	for (loop = arguments.length-1; loop>=0; loop--)
		sum += parseFloat(arguments[loop]);
	
	document.forms.frmModify.txtOrderTotal.value = Math.round(sum*100)/100;
	return;
}

function finalCheck(formField) {
    var proceed = true
    proceed = IsANumber(formField)
    if (!proceed)
		formField.focus();
		formField.select();
		return false;
		return proceed;
}

// Beginning of Address Script

    function Location(pId, pLabel, pCompany, pAddress, pCity, pState, pZip, pResidence, pPhone, pFax, pCountry) {
        this.pId = pId;
        this.pLabel = pLabel;
        this.pCompany = pCompany;
        this.pAddress = pAddress;
        this.pCity = pCity;
        this.pState = pState;
        this.pZip = pZip;
        this.pResidence = pResidence;
        this.pPhone = pPhone;
        this.pFax = pFax;
        this.pCountry = pCountry;
    }

    //function sets APARTMENT field to null if NONE is checked
    function pj_set_APARTMENT() {
        if (document.form1.apt_code[3].checked) {
            document.form1.apt_code_ext.value = "";
            document.form1.city.focus();
        }
    }

    function changeAddress() {
        var f = document.forms[0];
        var i;
        var val = f.location_id.options[f.location_id.selectedIndex].value;

        var cnt;
        var found = false;
        for (cnt = 0; !found && cnt < locations.length; cnt++) {
            if (locations[cnt].pId == val) {
              found = true;
            }
        }
        cnt = cnt - 1;
        if (found) {
            populateScreen(cnt);
        }
        else {
            clearScreen();
        }
    }

    function clearScreen() {
        var f = document.forms[0];
        document.form1.txtShipCompany.value     = "";
        document.form1.txtShipAddress.value     = "";
        document.form1.txtShipCity.value        = "";
        document.form1.txtShipState.value       = "";
        document.form1.txtShipZip.value			= "";
        document.form1.txtShipPhone.value       = "";
        document.form1.txtShipFax.value         = "";
        document.form1.txtShipCountry.value     = "";
        document.form1.txtLocationTitle.value   = "";

        for (i = 0; i < f.rbHomeDelivery.length; i++) {
            f.rbHomeDelivery[i].checked = false;
        }
        //document.getElementById('lTitle').style.visibility='visible';
        //document.getElementById('lField').style.visibility='visible';
    }

    function populateScreen(cnt) {
        var f = document.forms[0];
        document.form1.txtShipCompany.value     = locations[cnt].pCompany;
        document.form1.txtShipAddress.value     = locations[cnt].pAddress;
        document.form1.txtShipCity.value        = locations[cnt].pCity;
        document.form1.txtShipState.value       = locations[cnt].pState;
        document.form1.txtShipZip.value			= locations[cnt].pZip;
        document.form1.txtShipPhone.value       = locations[cnt].pPhone;
        document.form1.txtShipFax.value         = locations[cnt].pFax;
        document.form1.txtShipCountry.value     = locations[cnt].pCountry;
        document.form1.txtLocationTitle.value   = locations[cnt].pLabel;
		
        //document.getElementById('lTitle').style.visibility='hidden';
        //document.getElementById('lField').style.visibility='hidden';
		
        // set rbHomeDelivery/TRUE/FALSE
        for (i=0; i< f.rbHomeDelivery.length; i++) {
            f.rbHomeDelivery[i].checked = (f.rbHomeDelivery[i].value == locations[cnt].pResidence);
        }
    }
// End of Address Script

// Array for button controls
//CSAct[/*CMP*/ 'EmptyBasket'] = new Array(CSGotoLink,/*URL*/ '/shop/emptybasket.asp','');
//CSAct[/*CMP*/ 'CheckOut'] = new Array(CSGotoLink,/*URL*/ '/shop/SignIn.asp?action=shipping','');

// Popup Arrays
//CSAct['HOWTOORDER'] = new Array(CSOpenWindow,'/shop/p_HowToOrder.html','',470,400,false,true,false,false,false,false,false);
