/// <reference path="library/jquery.intellisense.js" />

function addLoadEvent(func) 
{
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } 
    else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}


function doc(id)
{
	var ie	= (document.all);
	var ns4	= document.layers?true:false;
	var dom	= document.getElementById && !document.all?true:false;

	if (dom) return document.getElementById(id);
	else if (ie) return document.all[id];
	else if (ns4) return document.layers[id];
}


function onlyNumbers(evt) 
{
    // keyCode      Key
    // --------------------------------
    // 48/58        0/9
    // 8            Backspace
    var e = evt;
    var charCode = e.which || e.keyCode;
    var valid = false;
    
    if (charCode >= 48 && charCode <= 58 || charCode==8) valid = true;
    return valid;
}


function ErrorHandler(elem, message) 
{
    doc(elem).innerHTML = message;
    doc(elem).style.display = "block";
}


function contactValidation()
{
    var errStr = "";
    var valid = true;
    
    // Run thru input fields and check if values are empty. If a value is empty append to the errStr variable.
    if (doc("txtFullname").value=="") { errStr += "<li>Fullname</li>"; } 
    if (doc("txtEmail").value=="") { errStr += "<li>Email address</li>"; } 
    if (doc("txtEmail").value != "" && !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(doc("txtEmail").value))) { errStr += "<li>Email address: incorrect format</li>"; }
    if (doc("txtPhone").value=="") { errStr += "<li>Telephone</li>"; } 
    if (doc("txtAddress").value=="") { errStr += "<li>Address</li>"; } 
    if (doc("txtEnquiry").value=="") { errStr += "<li>Enquiry</li>"; }
        
    // If an error appears build list element, display to user and stop form from submitting by returning false.
    if (errStr!="") {
        errStr = "<p>Please complete the following fields before proceeding.</p><ul>" + errStr + "</ul>";
        ErrorHandler("errStr", errStr);
        valid = false;
    }
    
    return valid;
}


function insertFlash(filename,width,height,alt) {
	
    //Defaults for width + height
    width=(width==null)?500:width;
    height=(height==null)?500:height;
    
    //When no flash is detected supply alt text
    if (alt == null || alt == "") alt = "Your browser doesn\'t support Flash Player";
    
    var axObject, e;

    try {
	    axObject = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
    } 
    catch (e) {
    }
    
    //Detect if user has flash |
    if (axObject || navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) {
        document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
        document.write('codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"');
        document.write('width="' + width + '" height="' + height + '" id="">');
        document.write('<param name="movie" value="flash/' + filename + '">');
        document.write('<param name=quality value=high>');
		document.write('<param name="wmode" value="transparent">');
        
        document.write('<embed src="flash/' + filename + '" quality=high bgcolor=#ffffff width="' + width + '" height="' + height + '"');
        document.write('name="' + filename + '" align="" wmode="transparent" type="application/x-shockwave-flash"');
        document.write('pluginspage="https://www.macromedia.com/go/getflashplayer" wmode="transparent">');
        document.write('</embed>');
        
        document.write('</object>');
    }
    //If the user doesnt have flash then display an image.
    else {
        document.write('<img src="/images/trans.gif" style="background:red;overflow:hidden; width:' + width + '; height:' + height + ';" alt="' + alt + '">');
        alert("Your browser doesn\'t support Flash Player");
    }
}


function liHover(id, className, overOut) 
{
	if (overOut == "over") doc(id).className = className;
	else doc(id).className='';
}


function menu() 
{
    var lis = doc("nav").getElementsByTagName("LI");
    
    for (i=0; i<lis.length; i++) {
        if (lis[i].lastChild.tagName=="UL") {
         	lis[i].onmouseover = function()
         	{
               this.lastChild.style.display = "block";
            }
            lis[i].onmouseout=function()
            {
               this.lastChild.style.display = "none";
            }
        }
    }
}