function windowOpen(theURL, Name, popW, popH, scroll, resize) { // V 1.0
    var winleft = (screen.width - popW) / 2;
    var winUp = (screen.height - popH) / 2;
    winProp = 'width=' + popW + ',height=' + popH + ',left=' + winleft + ',top=' + winUp + ',scrollbars=' + scroll + ',resizable=' + resize + '';
    Win = window.open(theURL, Name, winProp);
    Win.window.focus();
}


function MM_findObj(n, d) { //v4.0
	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 && document.getElementById) x=document.getElementById(n); return x;
	}

function validate_form(formName, requiredName, additional) {
    blnValid = true;
    oForm = eval(formName);
    alert('I am debugging here');
    var arrRequired = new Array();
    var strRequired = new String(eval(requiredName + '.value'));
    arrRequired = strRequired.split(";");
    for (i = 0; i < arrRequired.length; i++) {
        if (eval(formName + '.' + arrRequired[i] + '.value.length') < 1) {
            alert('Please fill in a title, description, price and variant');
            eval(formName + '.' + arrRequired[i] + '.focus()')
            blnValid = false;
            return blnValid;
        }
    }
    if (additional.length > 0) {
        eval(blnValid = additional)
    }
    return blnValid
}

function IsValid(){
	blnValid = true;
	if (blnValid==true && (x=MM_findObj('txtName'))!=null) {if(x.value == "") {window.alert( "Please enter your Name." ); x.focus(); blnValid = false;}}
	if (blnValid==true && (x=MM_findObj('txtEmail'))!=null && (y=MM_findObj('txtPhone'))!=null) {if(x.value == "" && y.value == "") {window.alert( "Please enter an Email Address or a Phone Number." ); x.focus(); blnValid = false;}}
	if (blnValid==true && (x=MM_findObj('txtEnquiry'))!=null) {if(x.value == "") {window.alert( "Please enter an Enquiry." ); x.focus(); blnValid = false;}}
	return blnValid;
}


function showNavContent(ID) {
    var oContent = document.getElementById('sub' + ID);
    var oimage = document.getElementById('img' + ID);
    var oSection = document.getElementById('section' + ID);

    if (oContent.style.display == "none") {
        oContent.style.display = '';
        oContent.style.left = 125 * ID + 2;
        oimage.src = '/images/minus.gif';
        oimage.alt = 'Click Here To Collapse This Section';
        ChangeClass(oSection, 'sectionover');
    }
    else {
        oContent.style.display = 'none';
        oimage.src = '/images/plus.gif';
        oimage.alt = 'Click Here To Expand This Section';
        ChangeClass(oSection, 'section')
    }
}

function showCatContent(ID) {
    var oContent = document.getElementById('sub' + ID);
    var oimage = document.getElementById('img' + ID);
    var oSection = document.getElementById('section' + ID);

    if (oContent.style.display == "none") {
        oContent.style.display = '';
        oimage.src = '/images/minus.gif';
        oimage.alt = 'Click Here To Collapse This Section';
        ChangeClass(oSection, 'sectionover')
    }
    else {
        oContent.style.display = 'none';
        oimage.src = '/images/plus.gif';
        oimage.alt = 'Click Here To Expand This Section';
        ChangeClass(oSection, 'section')
    }
}

function ChangeClass(obj, new_style) {
    obj.className = new_style;
}


function showQuotationContent(trID) {
    var oContent = document.all.item(trID);
    // alert('Debug ' + oContent.length + trID + ' TRs');
    var oimage = document.all.item(trID + "img");
    // alert('Debug ' + oimage.name + " " + trID + ' image');
    if (oContent.style.display == "none") {
        oContent.style.display = ''; oimage.src = 'images/collapse.gif'; oimage.alt = 'Click Here To Collapse This Category';
    }
    else {
        oContent.style.display = 'none'; oimage.src = 'images/expand.gif'; oimage.alt = 'Click Here To Expand This Category';
    }
}

xImgs = new Array(10);
function formatCurrency(num) {
    num = num.toString().replace(/\$|\,/g, '');
    if (isNaN(num))
        num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num * 100 + 0.50000000001);
    cents = num % 100;
    num = Math.floor(num / 100).toString();
    if (cents < 10)
        cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
        num = num.substring(0, num.length - (4 * i + 3)) + ',' +
num.substring(num.length - (4 * i + 3));
    return (((sign) ? '' : '-') + '$' + num + '.' + cents);
}

function checkAll(field) {
    var cost = 0
    for (var i = 0; i < field.length; i++) {
        if (field[i].checked == true) {
            var e = field[i];
            thiscost = parseFloat(e.value)
            if ((x = MM_findObj('txt' + Right(e.name, (e.name.length - 6)))) != null) { thiscost = (thiscost * x.value) }
            cost = cost + thiscost
        }
    }
    field.costs.value = formatCurrency(cost)
}

function Right(s, n) { var t = s.length; if (n > t) n = t; return s.substring(t - n, t); }

function ChangedTextbox(field) {
    if (isNumeric(field.value) != true) field.value = 1
    if (field.value == 0) field.value = 1
    if ((x = MM_findObj('ProdID' + Right(field.name, (field.name.length - 3)))) != null) { x.checked = true }
    checkAll(document.checkbox)
}

function isNumeric(value) {
    if (value == "") { return false }
    if (value.charAt(0) == "-") start = 1;
    else start = 0;
    for (i = start; i < value.length; i++) {
        if (value.charAt(i) < "0") { return false; }
        if (value.charAt(i) > "9") { return false; }
    }
    return true;
}

function addtofavorite(vdomain, vtitle) {
    url = "http://" + vdomain
    title = vtitle
    if (window.sidebar) // firefox
        window.sidebar.addPanel(title, url, "");
    else if (window.opera && window.print) { // opera
        var elem = document.createElement('a');
        elem.setAttribute('href', url);
        elem.setAttribute('title', title);
        elem.setAttribute('rel', 'sidebar');
        elem.click();
    }
    else if (document.all)// ie
        window.external.AddFavorite(url, title);
}

