// standard functions
window.onMouseMove = mouser;
window.onLoad = PreLoadImg;
function PreLoadImg(){MM_preloadImages("../images/close.png","../images/popdivsframe/bottom.png","../images/popdivsframe/bottomleft.png","../images/popdivsframe/bottomright.png","../images/popdivsframe/left.png","../images/popdivsframe/right.png","../images/popdivsframe/top.png","../images/popdivsframe/topleft.png","../images/popdivsframe/topright.png","../images/loading.gif");}
function MM_swapImgRestore() {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() {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) {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); return x;}
function MM_swapImage() {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 GetXmlHttpObject(){if (window.XMLHttpRequest){return new XMLHttpRequest();}if (window.ActiveXObject){return new ActiveXObject("Microsoft.XMLHTTP");}return null;}

var xmlhttp_divpopup;
function divpopup(themethod,theurl,atclicksend){if(atclicksend){MoveDivToClick("PopDiv");}if (themethod.length == 0 || theurl.length == 0){document.getElementById("PopDiv").innerHTML = "";hide("PopDiv");return;}xmlhttp_divpopup = GetXmlHttpObject();if (xmlhttp_divpopup == null){alert ("Your browser does not support XMLHTTP!");return;}xmlhttp_divpopup.onreadystatechange = stateChanged_divpopup;xmlhttp_divpopup.open(themethod,theurl,true);xmlhttp_divpopup.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');xmlhttp_divpopup.send(theurl);}
function stateChanged_divpopup(){if (xmlhttp_divpopup.readyState == 1){dispload("PopDiv","","w");}if (xmlhttp_divpopup.readyState == 4){disp("PopDiv");document.getElementById("PopDiv").innerHTML = xmlhttp_divpopup.responseText;}}
var loadingpic = "<center><div class=\"loadingpic\"></div></center>";
var loadingwindow = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td class=\"PopDivFrameTopLeft\">&nbsp;&nbsp;&nbsp;</td><td class=\"PopDivFrameTop\"></td><td class=\"PopDivFrameTopRight\">&nbsp;&nbsp;&nbsp;</td></tr><tr><td class=\"PopDivFrameLeft\">&nbsp;&nbsp;&nbsp;</td><td class=\"PopDivFrameBg\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"width: 100%;\"><tr><td class=\"popDivTopBar\" onmousedown=\"return MoveDiv('PopDiv');\" onmouseup=\"return StopDiv('PopDiv');\"><table cellpadding=\"2\" cellspacing=\"0\" border=\"0\" style=\"width: 100%;\"><tr><td style=\"text-align: left; font-size: 14px; color: #ffffff;\"><b>Loading...</b></td><td style=\"text-align: right;\"><input type=\"button\" class=\"popDivCloseBut\" value=\" \" title=\"close\" onclick=\"javascript:ClosePopDiv();\" /></td></tr></table></td></tr><tr><td style=\"width: 200px; height: 100px; vertical-align: middle; text-align: center;\">" + loadingpic + "</td></tr></table></td><td class=\"PopDivFrameRight\">&nbsp;&nbsp;&nbsp;</td></tr><tr><td class=\"PopDivFrameBottomLeft\">&nbsp;&nbsp;&nbsp;</td><td class=\"PopDivFrameBottom\"></td><td class=\"PopDivFrameBottomRight\">&nbsp;&nbsp;&nbsp;</td></tr></table>";
var posx;var posy;var DivX = 150;var DivY = 50;var xmlhttp;var DivClkLft;var DivClkRgt;var moveX;var moveY;
function mouser(event){posx = event.clientX;posy = event.clientY;}
function dispload(divID,Msg,dw){disp(divID);if(dw=="d"){GetElm(divID).innerHTML = "<center>" + loadingpic + "<br/><b>" + Msg + "</b></center>";}else if(dw=="w"){GetElm(divID).innerHTML = loadingwindow;}}
function MoveDivToClick(divID){if (!posx){posx = 150;}if (!posy){posy = 50;}moveX = posx;moveY = posy;DivX = posx;DivY = posy;document.getElementById(divID).style.left = DivX + "px";document.getElementById(divID).style.top = DivY + "px";}
function MoveDiv(divID){dsblSlct(document.body);DivClkLft = posx - DivX;DivClkRgt = posy - DivY;document.onmousemove = MovemyDiv;function MovemyDiv(){moveX = posx - DivClkLft;moveY = posy - DivClkRgt;DivX = moveX;DivY = moveY;document.getElementById(divID).style.left = moveX + "px";document.getElementById(divID).style.top = moveY + "px";}}
function StopDiv(divID){enblSlct(document.body);document.onmousemove = StopmyDiv;function StopmyDiv(){if (moveX != null && moveY != null){if (document.getElementById(divID).style.visibility != 'hidden'){DivX = moveX;DivY = moveY;} else {DivX = DivX;DivY = DivY;}document.getElementById(divID).style.left = moveX + "px";document.getElementById(divID).style.top = moveY + "px";}}}
function ClosePopDiv(){document.getElementById("PopDiv").innerHTML = "";hide("PopDiv");}
function dsblSlct(trgt){if (typeof trgt.onselectstart!="undefined"){trgt.onselectstart=function(){return false};}else if (typeof trgt.style.MozUserSelect!="undefined"){trgt.setAttribute("class","moznone");document.getElementById("PopDiv").setAttribute("class","PopDivNotSelect");}else{trgt.onmousedown=function(){return false};trgt.style.cursor = "default";}}
function enblSlct(trgt){if (typeof trgt.onselectstart!="undefined"){trgt.onselectstart=function(){return true};}else if (typeof trgt.style.MozUserSelect!="undefined"){trgt.setAttribute("class","moztext");document.getElementById("PopDiv").setAttribute("class","PopDiv");}else{trgt.onmousedown=function(){return true};trgt.style.cursor = "select";}}
function disp(div){document.getElementById(div).style.display="block";}
function hide(div){document.getElementById(div).style.display="none";}
function confirmAct(){var conf = confirm("Are you sure you want to take this action?");if(true == conf){return true;}else if(false == conf){return false;}}
function confirmDel(){var conf = confirm("Are you sure you want to delete the selected items?");if(true == conf){return true;}else if(false == conf){return false;}}
function fixForURL(val){return escape(encodeURI(val));}
function GetElm(fld){return document.getElementById(fld);}
function GetElmVal(fld){if(document.getElementById(fld)){return document.getElementById(fld).value;}}
function Trim(s) {while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r')){ s = s.substring(1,s.length); }while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r')){ s = s.substring(0,s.length-1); }return s;}

function CheckEnquiry(form)
{
    var enquiry = form.enquiry;
    var name = form.name;
    var surname = form.surname;
    var company = form.company;
    var city = form.city;
	var email = form.email;
	var conemail = form.conemail;
    var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
    var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
    var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
	var cell = form.cell;
	var telwork = form.telwork;
	var telhome = form.telhome;
	var hear = form.hear;
	var agree = form.agree;
	var myagreefalse = 0;
    
    var enquirychk = 0;
    for (i=0, n=enquiry.length; i<n; i++)
    {if (enquiry[i].checked == true){enquirychk += 1;}}
    if (enquirychk == 0){alert('Please specify what your enquiry is about.');return false;}
	if (name.value == ""){alert('Please enter your Name in the space provided.');name.focus();return false;}
    if (surname.value == ""){alert('Please enter your Surname in the space provided.');surname.focus();return false;}
	if (company.value == ""){alert('Please enter your Company / Organization Name in the space provided');company.focus();return false;}
	if (city.value == ""){alert('Please enter your city in the space provided');city.focus();return false;}
	if (email.value == ""){ alert('Please enter your email address in the space provided');email.focus();return false;}
    if(!email.value.match(emailRegex)){alert('You have entered an invalid email.');email.focus();return false;}
	if (conemail.value == ""){ alert('Please enter your confirmation email address in the space provided');conemail.focus();return false;}
    if(!conemail.value.match(emailRegex)){alert('You have entered an invalid email.');conemail.focus();return false;}
	if (conemail.value != email.value){alert('Your Email confirmation does not match with your specified email address');conemail.focus();return false;}
    if (cell.value == ""){alert('Please enter your cell number in the space provided');cell.focus();return false;}
	if (telwork.value == ""){alert('Please enter your work telephone number in the space provided');telwork.focus();return false;}
	if (telhome.value == ""){alert('Please enter your home telephone number in the space provided');telhome.focus();return false;}
	if (hear.value == ""){alert('Please specify how you heard from us');hear.focus();return false;}
	if (agree.checked == false){document.getElementById('err_terms').style.display = "block";myagreefalse += 1;}
	else{document.getElementById('err_terms').style.display = "none";}
	if (myagreefalse > 0){return false;}
	return true;
}
