function PreLoadImg()
{
    MM_preloadImages('images/popdivframe/topleft.png','images/popdivframe/top.png','images/popdivframe/topright.png','images/popdivframe/left.png','images/popdivframe/right.png','images/popdivframe/bottomleft.png','images/popdivframe/bottom.png','images/popdivframe/bottomright.png');
}
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 confReset(){var conf = confirm("Remove ALL information from the form?");
if(true == conf){return true;}else if(false == conf){return false;}}

// Form submissions *START*
function CheckPropReg(form)
{
    var firstname = repl_qstr(form.firstname.value);
    var lastname = repl_qstr(form.lastname.value);
    var tel = repl_qstr(form.tel.value);
    var email = repl_qstr(form.email.value);
    var ceml = repl_qstr(form.ceml.value);
    var password = repl_qstr(form.password.value);
    var cpwd = repl_qstr(form.cpwd.value);
    var agree = form.agree.checked;
    
    var url = "prop_reg.asp"
    url += "?firstname=" + firstname
    url += "&lastname=" + lastname
    url += "&tel=" + tel
    url += "&email=" + email
    url += "&ceml=" + ceml
    url += "&password=" + password
    url += "&cpwd=" + cpwd
    url += "&agree=" + agree
    
    openPopDiv(url);
    
    return false;
}

extArray = new Array(".gif", ".jpg", ".png");
function LimitAttach(file) {
    if (!file){return "";}
    while (file.indexOf("\\") != -1){file = file.slice(file.indexOf("\\") + 1);ext = file.slice(file.indexOf(".")).toLowerCase();for (var i = 0; i < extArray.length; i++){if (extArray[i] == ext) { allowSubmit = true; break;}}}
    return file;
}

function CheckPropAdd(form)
{   
    var prov_id = form.prov_id.value;
    var city = repl_qstr(form.city.value);
    var region = repl_qstr(form.region.value);
    var stadium = form.stadium.value;
    var mytitle = repl_qstr(form.mytitle.value);
    var myprice = repl_qstr(form.myprice.value);
    var neg = form.neg.value;
    var mytype = repl_qstr(form.mytype.value);
    
    var checkboxes = "";
    
    var dates1 = form.dates1;
    if (dates1.checked == true)
    {checkboxes+=dates1.value+"_"}
    
    var dates2 = form.dates2;
    if (dates2.checked == true)
    {checkboxes+=dates2.value+"_"}
    
    var dates3 = form.dates3;
    if (dates3.checked == true)
    {checkboxes+=dates3.value+"_"}
    
    var dates4 = form.dates4;
    if (dates4.checked == true)
    {checkboxes+=dates4.value+"_"}
    
    var dates5 = form.dates5;
    if (dates5.checked == true)
    {checkboxes+=dates5.value+"_"}
    
    var descrip = repl_qstr(form.descrip.value);
    var prop_id = form.prop_id.value;
    
    var url = "prop_add.asp"
    url += "?prov_id=" + prov_id
    url += "&city=" + city
    url += "&region=" + region
    url += "&stadium=" + stadium
    url += "&mytitle=" + mytitle
    url += "&myprice=" + myprice
    url += "&neg=" + neg
    url += "&mytype=" + mytype
    url += "&checkboxes=" + checkboxes
    url += "&descrip=" + descrip
    url += "&prop_id=" + prop_id
    
    openPopDiv(url);
    //init();
    return false;
}
// Form submissions *END*

function repl_qstr(value)
{
    value = value.replace(/[$]/g,"%24");
    value = value.replace(/[&]/g,"%26");
    value = value.replace(/[<]/g,"%3C");
    value = value.replace(/[>]/g,"%3E");
    value = value.replace(/[?]/g,"%3F");
    value = value.replace(/[;]/g,"%3B");
    value = value.replace(/[#]/g,"%23");
    value = value.replace(/[:]/g,"%3A");
    value = value.replace(/[=]/g,"%3D");
    value = value.replace(/[,]/g,"%2C");
    value = value.replace(/[\"]/g,"%22");
    value = value.replace(/[\']/g,"%27");
    value = value.replace(/[~]/g,"%7E");
    value = value.replace(/[+]/g,"%2B");
    value = value.replace(/[%]/g,"%25");
    value = value.replace(/\n/g,"<br/>");
    return value;
}

function chkProvSel(){if(document.getElementById("province").value.length == 0){alert("Please select a province first!");document.getElementById("province").focus();}}
function chkCitySel(){if(document.getElementById("city").value.length == 0){alert("Please select a city first!");document.getElementById("city").focus();}}
function checkPrices(form){var min = form.min_price;var max = form.max_price;if (min.value != "" && max.value != ""){if ((min.value*1)>(max.value*1)){alert("Your maximum price is smaller than your minimum price!");max.focus();return false;}}}

// ----DIV POPUP CODE----
// set X & Y Position to the same as the div style
var DivX = 300; // default = left: 300px;
var DivY = 200; // default = top: 200px;
// AJAX GetXmlHttpObject function
var xmlhttp;
function GetXmlHttpObject(){/*code for IE7+, Firefox, Chrome, Opera, Safari*/if (window.XMLHttpRequest){return new XMLHttpRequest();}/*code for IE6, IE5*/if (window.ActiveXObject){return new ActiveXObject("Microsoft.XMLHTTP");}return null;}
// AJAX openPopDiv function
function openPopDiv(page){if (page.length == 0){document.getElementById("PopDiv").innerHTML = "";document.getElementById("PopDiv").style.display = "none";return;}xmlhttp = GetXmlHttpObject();if (xmlhttp==null){alert ("Your browser does not support XMLHTTP!");return;}var url = page;xmlhttp.onreadystatechange=stateChanged_openPopDiv;xmlhttp.open("POST",url,true);xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');xmlhttp.send(url);}
function stateChanged_openPopDiv(){if (xmlhttp.readyState==4){document.getElementById("PopDiv").style.display = "block";document.getElementById("PopDiv").innerHTML = xmlhttp.responseText;}}
// X and Y of the mouse position function
var x;var y;
function mouser(event){x = event.clientX;y = event.clientY;}// cal this on the <body> tag - onmousemove="javascript:mouser(event);"
// move popup while mouse button is down
var DivClkLft;var DivClkRgt;var moveX;var moveY;
function MoveDiv(divID){dsblSlct(document.body);DivClkLft = x - DivX;DivClkRgt = y - DivY;document.onmousemove = MovemyDiv;
function MovemyDiv(){moveX = x - DivClkLft;moveY = y - DivClkRgt;DivX = moveX;DivY = moveY;document.getElementById(divID).style.left = moveX + "px";document.getElementById(divID).style.top = moveY + "px";}}
// stop popup when mouse button is lifted
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";}}}
// close popup
function ClosePopDiv(){document.getElementById("PopDiv").innerHTML = "";document.getElementById("PopDiv").style.display = "none";}

// AJAX VerifyMemberLogin *START*
function VerifyMemberLogin(un,pwd)
{
    if (un.length == 0 || pwd.length == 0 || un == "*Email Address" || pwd == "*Password")
    {
        document.getElementById("logStatus").innerHTML = "Fill in both fields and<br/>wait for ready state:";
        document.getElementById("butLogVer").innerHTML = "<input type=\"button\" class=\"subm\" name=\"login\" value=\"Login\" />";
        document.getElementById("logChkTxt").value = "FALSE";
        return;
    }
    
    xmlhttp = GetXmlHttpObject();
    if (xmlhttp==null){alert ("Your browser does not support XMLHTTP!");return;}
    
    var url="checkMemberLogin.asp";
    url=url+"?un="+un;
    url=url+"&pwd="+pwd;
    xmlhttp.onreadystatechange=stateChanged_VerifyMemberLogin;
    xmlhttp.open("POST",url,true);
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send(url);
}
function stateChanged_VerifyMemberLogin()
{if (xmlhttp.readyState==4){
    if (xmlhttp.responseText == "FALSE"){
        document.getElementById("butLogVer").innerHTML = "<input type=\"button\" class=\"subm\" name=\"login\" value=\"Login\" />";
        document.getElementById("logStatus").innerHTML = "&nbsp;<br/>Searching...";
    } else if (xmlhttp.responseText == "INACTIVE") {
        document.getElementById("butLogVer").innerHTML = "<input type=\"button\" class=\"subm\" name=\"login\" value=\"Login\" />";
        document.getElementById("logStatus").innerHTML = "&nbsp;<br/>Inactive Membership!";
    } else if (xmlhttp.responseText == "estLogTrue") {
        document.getElementById("butLogVer").innerHTML = "<input type=\"submit\" class=\"subm\" name=\"login\" value=\"Login\" />";
        document.getElementById("logStatus").innerHTML = "&nbsp;<br/>Ready!";
    }
    document.getElementById("logChkTxt").value = xmlhttp.responseText;
}

}
// AJAX VerifyMemberLogin *END*

// AJAX populateCity *START*
function populateCity(provID)
{
    var cityDiv;
    var regionDiv;
    cityDiv = '<select style="width: 197px;" name="city" id="city" ';
    cityDiv = cityDiv + 'onclick="javascript:chkProvSel()" ';
    cityDiv = cityDiv + 'onfocus="javascript:chkProvSel()" ';
    cityDiv = cityDiv + 'onchange="javascript:populateRegion(this.value);">';
    cityDiv = cityDiv + '<option value="">--City--</option>';
    cityDiv = cityDiv + '</select>';
    regionDiv = '<select style="width: 197px;" name="region" id="region" ';
    regionDiv = regionDiv + 'onclick="javascript:chkCitySel()">';
    regionDiv = regionDiv + '<option value="">--Region--</option>';
    regionDiv = regionDiv + '</select>';
    
    if (provID.length == 0)
    {document.getElementById("cityDiv").innerHTML = cityDiv;document.getElementById("regionDiv").innerHTML = regionDiv;return;}
    
    xmlhttp = GetXmlHttpObject();
    if (xmlhttp==null){alert ("Your browser does not support XMLHTTP!");return;}
    
    var url="getCities.asp";
    url=url+"?prov_id=" + provID;
    xmlhttp.onreadystatechange = stateChanged_populateCity;
    xmlhttp.open("POST",url,true);
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send(url);
}
function stateChanged_populateCity()
{if (xmlhttp.readyState==4){document.getElementById("cityDiv").innerHTML = xmlhttp.responseText;}}
// AJAX populateCity *END*

// AJAX populateRegion *START*
function populateRegion(city)
{
    var regionDiv;
    regionDiv = '<select style="width: 197px;" name="region" id="region" ';
    regionDiv = regionDiv + 'onclick="javascript:chkCitySel()" ';
    regionDiv = regionDiv + 'onfocus="javascript:chkCitySel()">';
    regionDiv = regionDiv + '<option value="">--Region--</option>';
    regionDiv = regionDiv + '</select>';
    if (city.length == 0)
    {document.getElementById("regionDiv").innerHTML = regionDiv;return;}
    
    xmlhttp = GetXmlHttpObject();
    if (xmlhttp==null){alert ("Your browser does not support XMLHTTP!");return;}
    
    var url="getRegions.asp";
    url=url+"?city=" + city;
    xmlhttp.onreadystatechange = stateChanged_populateRegion;
    xmlhttp.open("POST",url,true);
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send(url);
}
function stateChanged_populateRegion()
{if (xmlhttp.readyState==4){document.getElementById("regionDiv").innerHTML = xmlhttp.responseText;}}
// AJAX populateRegion *END*

// AJAX checkEmlExists *START*
function checkEmlExists(eml)
{
    xmlhttp = GetXmlHttpObject();
    if (xmlhttp==null){alert ("Your browser does not support XMLHTTP!");return;}
    
    var url="checkEmlExists.asp";
    url=url+"?eml=" + eml;
    xmlhttp.onreadystatechange = stateChanged_checkEmlExists;
    xmlhttp.open("POST",url,true);
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send(url);
}
function stateChanged_checkEmlExists()
{if (xmlhttp.readyState==4){
var emlexists;emlexists = xmlhttp.responseText;if(emlexists == "FALSE"){alert("The email address supplied is not a valid member email");document.recoverEml.eml.select();return false;}else if(emlexists == "TRUE"){openPopDiv('RecoverPwdForm.asp?met=post&eml=' + document.recoverEml.eml.value);}}}
// AJAX checkEmlExists *END*

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 LoadImageResult(form)
{
    var mypic = form.mypic;
    if (mypic.value == ""){
        alert("Please select an image for upload!");
        mypic.focus();
        return false;
    }
    return true;
}

function selected_blank(fld)
{
    for(i=0;i<fld.length;i++)
    {
        if(fld.options[i].value=='')
        {
            fld.selectedIndex=i;
        }
    }
}

function setValBlank(myfld,replVal){if (myfld.value == replVal){myfld.value = "";}}
function setValDefault(myfld,replVal){if (myfld.value == ""){myfld.value = replVal;}}

function CheckMemberLoginFields(form){
    var un = form.un;
    var pwd = form.pwd;
    var chk = form.logChkTxt;
    
    if (un.value == "*Email address" || un.value == "")
    {alert("Please enter your email address");un.focus();return false;}
    if (pwd.value == "*Password" || pwd.value == "")
    {alert("Please enter your password");pwd.focus();return false;}
    if (chk.value != "estLogTrue")
    {alert("Incorrect email and password combination\nOR\nYour membership has not been activated yet");pwd.select();return false;}
    return true;
}
function checkPwdRec(form)
{var eml = form.eml;var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;if(eml.value == "*Email address" || eml.value == ""){alert("Please enter your email address");eml.focus();return false;}if(!eml.value.match(emailRegex)){alert("You have entered an invalid email address");eml.select();return false;}checkEmlExists(eml.value);return false;}

function checkFields(form){
    var name = form.name;
    var email = form.email;
    var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
    var tel = form.tel;
    
    if (name.value == "")
    {alert("Please enter your name");name.focus();return false;}
    if (email.value == "")
    {alert("Please enter your email address");email.focus();return false;}
    if(!email.value.match(emailRegex)) {alert('You have entered an invalid email.');email.focus();return false;}
    if (tel.value == "")
    {alert("Please enter your contact number");tel.focus();return false;}
    return true;
}

function checkAllDates()
{
    for (i=0;i<document.prop_add.length;i++)
    {
        if (document.prop_add[i].type=="checkbox")
        {
            document.prop_add[i].checked=true;
        }
    }
}

function uncheckAllDates()
{
    for (i=0;i<document.prop_add.length;i++)
    {
        if (document.prop_add[i].type=="checkbox")
        {
            document.prop_add[i].checked=false;
        }
    }
}