// JavaScript Document
// Example: obj = findObj("image1");
function findObj(theObj, theDoc) {

	var p, i, foundObj;
	
	if(!theDoc) theDoc = document;
	if((p = theObj.indexOf("?")) > 0 && parent.frames.length) {
		theDoc = parent.frames[theObj.substring(p+1)].document;
		theObj = theObj.substring(0,p);
	}
	if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
	for (i=0; !foundObj && i < theDoc.forms.length; i++) 
	foundObj = theDoc.forms[i][theObj];
	for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
	foundObj = findObj(theObj,theDoc.layers[i].document);
	if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
	
	return foundObj;

}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	tmp = changeImages.arguments;
	if (document.images && (preloadFlag == true)) {
		for (i=0; i<changeImages.arguments.length; i+=2) {
			document.images[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;

function preloadImages() {
	tmp = preloadImages.arguments;
	if (document.images && (preloadFlag == true)) {
		for (i=0; i<preloadImages.arguments.length; i++) {
			image = new Image(preloadImages.arguments[i]);
		}
	}
}


function setMainPic(productref, thumbindex) {

	main = findObj("mainpic");
	tmb = findObj("thumbpic" + thumbindex);
	
	msrc = String(main.src);
	tsrc = String(tmb.src);
	
	msrc = msrc.replace(productref + "/large", productref + "/thumb");
	tsrc = tsrc.replace(productref + "/thumb", productref + "/large");
	
	main.src = tsrc;
	tmb.src = msrc;

}

function setMainPicNotThumb(productref, thumbindex) {

	main = findObj("mainpic");
	tmb = findObj("thumbpic" + thumbindex);
	
	msrc = String(main.src);
	tsrc = String(tmb.src);
	
	msrc = msrc.replace(productref + "/large", productref + "/thumb");
	tsrc = tsrc.replace(productref + "/thumb", productref + "/large");
	
	main.src = tsrc;

}

function setMainPicSwitched(productref, thumbindex) {

	main = findObj("mainpic");
	tmb = findObj("thumbpic" + thumbindex);
	
	msrc = String(main.src);
	tsrc = String(tmb.src);
	
	msrc = msrc.replace(productref + "/thumb", productref + "/large");
	tsrc = tsrc.replace(productref + "/large", productref + "/thumb");
	
	main.src = tsrc;
	tmb.src = msrc;

}

function submitForm(formName) {
	
	fm = findObj(formName);
	fm.submit();
	
}

function showInfo(pr) {
	
	nl = "display_product.php?productref=" + pr;
	enc = window.open(nl, "Inf", "height=300, width=500, toolbar=no, resizable=yes, status=no, titlebar=no, scrollbars=yes");
	enc.focus();
	
}

function showPackage(pr) {
	
	nl = "display_package.php?ref=" + pr;
	enc = window.open(nl, "Inf", "height=300, width=500, toolbar=no, resizable=yes, status=no, titlebar=no, scrollbars=yes");
	enc.focus();
	
}

function validateEnquiryForm() {
	var dm = document.forms["contactform"];
	var errorMsg = "";
	
	if (!dm.name.value) {
		errorMsg = errorMsg + "Name is required\n";
	}
	if (!((dm.tel.value)||(dm.email.value))) {
		errorMsg = errorMsg + "Telephone Number or E-mail address are required\n";
	}
	if (!isEmail(dm.email.value)&&dm.email.value.length>0) {
		errorMsg = errorMsg + "Invalid E-mail Address\n";
	}
	if (!((dm.subject.value)||(dm.comments.value))) {
		errorMsg = errorMsg + "Subject or Comments are required";
	}
	if (errorMsg) {
		alert(errorMsg);
		return false;
	} else {
		return true;
	}
}

function isEmail(str) {
	var ret = true;
	if (str.indexOf("@")<=0) {
		ret = false;
	}
	if (str.lastIndexOf(".")<str.indexOf("@")) {
		ret = false;
	}
	return ret;
}

function entsub(loginsubscriber) {
  if (window.event && window.event.keyCode == 13)
    loginsubscriber.submit();
  else
    return true;}

function mailadvicespage(category, content)
{
	mailadvices = window.open("mailadvices.php?displaycate=" + category + "&displaycont=" + content, "mailadvices", "width=400, height=350, scrollbars=0, toolbar=0, status=0")
	mailadvices.focus();
}
