// JavaScript Document - Jamaican Sensations - 08/29/04
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 flvFSTI4(){//v1.01
this.style.filter="";}

function flvFSTI3(v1,v2){//v1.01
var v3;if (v1.filters[0]&&v1.filters[0].status==2){v1.filters[0].Stop();}if (v2==0){v3="blendTrans(Duration="+v1.STI8+")";}else {v3="revealTrans(Duration="+v1.STI8+",Transition="+(v2-1)+")";}v1.style.filter=v3;}

function flvFSTI2(){//v1.01
var v1,v2=document,v3=v2.STI4,v4;for (v4=0;v3&&v4<v3.length&&(v1=v3[v4])&&v1.STI5;v4++){if (v1.filters&&!v2.STI7){flvFSTI3(v1,v1.STI3);v1.filters[0].Apply();}v1.src=v1.STI5;if (v1.filters&&!v2.STI7){v1.filters[0].Play();}}}

function flvFSTI1(){//v1.01
// Copyright 2003, Marja Ribbers-de Vroed, FlevOOware (www.STI1.nl/dreamweaver/)
var v1=arguments,v2=document,v3;v2.STI4=new Array();v2.STI7=(navigator.userAgent.toLowerCase().indexOf("mac")!=-1);for (var v4=0;v4<v1.length-2;v4+=5){v3=MM_findObj(v1[v4]);if (v3){v3.STI5=v3.src;v3.STI6=v1[v4+1];v3.STI2=v1[v4+2];v3.STI3=v1[v4+3];v3.STI8=v1[v4+4];v2.STI4[v2.STI4.length]=v3;if (v3.filters&&!v2.STI7){flvFSTI3(v3,v3.STI2);v3.onfilterchange=flvFSTI4;v3.filters[0].Apply();}v3.src=v3.STI6;if (v3.filters&&!v2.STI7){v3.filters[0].Play();}}}}

function aboutPopUp(str){
window.open("about.asp?string=" + str,"about","width=375,menubar=0,resizable=1,scrollbars=yes,status=0,titlebar=0,toolbar=0,left=25,top=25")}

function slideshowPopUp(str){
window.open("slideshow.asp?string=" + str,"slideshow","height=450,width=375,menubar=0,resizable=0,scrollbars=yes,status=0,titlebar=0,toolbar=0,left=25,top=25")}

function isBlank(s)
{
	for (var i=0;i<s.length;i++){
		var c=s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}

function isEmailAddress(s)
{
	if (window.RegExp) {
		var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
		var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
		var reg1 = new RegExp(reg1str);
		var reg2 = new RegExp(reg2str);
		if (!reg1.test(s) && reg2.test(s)) {
			return true;
		}
		return false;
	  } else {
		if(s.indexOf("@") >= 0)
			return true;
		field.focus();
		field.select();
		return false;
	  }
}

function verify(f)
{
	var msg;
	var v;
	var empty_fields = "";
	var errors = "";
	
	for(var i=0;i<f.length;i++){
		var e = f.elements[i];
		if (((e.type == "text") || (e.type == "textarea")) && e.required == true && !e.isEmail) {
			if ((e.value == null) || (e.value == "") || isBlank(e.value)){
				empty_fields += "\n   " + e.name;
				continue;
			}
			
			if (e.numeric || (e.min != null) || (e.max != null)){
				v = parseFloat(e.value);
				if (isNaN(v) || ((e.min != null) && (v < e.min)) || ((e.max != null) && (v > e.max))) {
					errors += "- The field " + e.name + " must be a number";
					if (e.min != null)
						errors += " that is greater than " + e.min;
					if (e.max != null && e.min != null)
						errors += " and less than " + e.max;
					else if (e.max != null)
						errors += " that is less than " + e.max;
					errors += ".\n";
				}
			}
		}
		if (!e.required && e.numeric == true && e.value > "") {
			if ((e.min != null) || (e.max != null)){
				v = parseFloat(e.value);
				if (isNaN(v) || ((e.min != null) && (v < e.min)) || ((e.max != null) && (v > e.max))) {
					errors += "- The field " + e.name + " must be a number";
					if (e.min != null)
						errors += " that is greater than " + e.min;
					if (e.max != null && e.min != null)
						errors += " and less than " + e.max;
					else if (e.max != null)
						errors += " that is less than " + e.max;
					errors += ".\n";
				}
			}
		}
		if ((e.isEmail == true) && !isEmailAddress(e.value)){
			errors += "\n- The field " + e.name + " is not a valid e-mail address configuration."
		}
	}

	if (!empty_fields && !errors) return true;
	
	msg = "The form cannot be submitted.";
	
	if(empty_fields) {
		msg += "\n- The following required field(s) are empty: " + empty_fields;
		if (errors) msg += "\n";
	}
	msg += errors;
	alert(msg);
	return false;
}

function putMessage(s)
{
	var msg

	switch (s){
		case 'dbInsertSuccess':
			msg = 'New record was successfully added';
			break;
		case 'dbInsertFailed':
			msg = 'Unable to add new record. Please contact support for assistance.';
		case 'dbUpdateSuccess':
			msg = 'Record was successfully updated';
			break;
		case 'dbUpdateFailed':
			msg = 'Unable to update record. Please contact support for assistance.';
		case  'dbError':
			msg = 'A database error has occurred. Please contact support for assistance.';
			break;
		default:
			return false;
			break;
	}
	alert(msg);
	return true;
}

function calcPrice(frm, basePrice, intCategoryOptions, intProductOptions)
{
	var i, selObj, selIndex, selPrice;
	var frmName = frm.name;
	var totalPrice = basePrice;
	var frmPrice = eval("document." + frmName + ".amount");
		
	for(i=0; i<intCategoryOptions; i++) {
		selObj = eval("document." + frmName + ".custom1_" + i);
		selIndex = selObj.selectedIndex;
		selPrice = selObj.options[selIndex].value;
		totalPrice = parseFloat(totalPrice) + parseFloat(selPrice)
	}
	for(i=0; i<intProductOptions; i++) {
		selObj = eval("document." + frmName + ".custom2_" + i);
		selIndex = selObj.selectedIndex;
		selPrice = selObj.options[selIndex].value;
		totalPrice = parseFloat(totalPrice) + parseFloat(selPrice)
	}

	frmPrice.value = totalPrice;
}

function writeOptionString(frm, intCategoryOptions, intProductOptions)
{
	var i, selObj, selIndex, selOption;
	frmName = frm.name;
	var strOptionString = ""
	var os0 = eval("document." + frmName + ".os0");
	var os1 = eval("document." + frmName + ".os1");
	//alert(intCategoryOptions + "," + intProductOptions);
	
	for (i=0; i<intCategoryOptions; i++) {
		selObj = eval("document." + frmName + ".custom1_" + i);
		selID = selObj.id;
		strOptionString = strOptionString + selID + "-";
		selIndex = selObj.selectedIndex;
		selOption = selObj.options[selIndex].id;
		strOptionString = strOptionString + selOption +"; ";
		}
	os0.value = strOptionString;
	strOptionString = "";
	for (i=0; i<intProductOptions; i++) {
		selObj = eval("document." + frmName + ".custom2_" + i);
		selID = selObj.id;
		strOptionString = strOptionString + selID + "-";
		selIndex = selObj.selectedIndex;
		selOption = selObj.options[selIndex].id;
		strOptionString = strOptionString + selOption +"; ";
		}
	os1.value = strOptionString;

	return true;
}
