﻿// open visual info
function openReplace(sUrl) {
	var url = sUrl;
	winReplace = window.open(url, "replace","scrollbars=yes, status=yes, menubar=no, width=540, height=350, resizable=yes");
	winReplace.focus();
}
function openMessage(sUrl) {
	var url = sUrl;
	msWin = window.open(url, "ms","scrollbars=no, status=yes, menubar=no, width=450, height=400, resizable=yes");
	msWin.focus();
}

//pass a form name an array of itmes and an array of descriptive names - for the alert messages.
function checkFormItems(form, items, messages) {
	for (var i=0; i<items.length; i++) {				
		formItem = eval(form + "." + items[i]);
		formItemValue = eval(form + "." + items[i] + ".value");
		if (formItemValue == "" || formItemValue == "any") {
			alert("Please fill in the field: " + "\"" + messages[i] + "\"");
			formItem.focus();
			return false;
		}
	}
	return true;
}

function checkIsNumber(form, items, messages) {
	for (var i=0; i<items.length; i++) {				
		formItem = eval(form + "." + items[i]);
		formItemValue = eval(form + "." + items[i] + ".value");
		if (formItemValue != "") {			
			if (isNaN(formItemValue)) {
				alert("The field: " + "\"" + messages[i] + "\"" + "is not a valid number.");
				formItem.focus();
				return false;
			}
		}
	}
	return true;
}

// indicates how many characters have been entered in a textfield.
function numCharCount(form, field, length_limit) {	
	var length = calculate_msglen(eval("document" + "." + form + "." + field + ".value"));
	textlimit.innerText = length;
	if (length > length_limit) {
		alert("Warning: " + length_limit + " is the max number of characters you can enter for this field. \n Please cut down your text.");
	}
}	

function calculate_msglen(message)
{
	var nbytes = 0;	
	for (i=0; i<message.length; i++) {		
		var ch = message.charAt(i);
		if(escape(ch).length > 4) {
			nbytes += 2;
		} else if (ch == '\n') {
			if (message.charAt(i-1) != '\r') {
				nbytes += 1;
			}
		} else if (ch == '<' || ch == '>') {
			nbytes += 4;
		} else {
			nbytes += 1;
		}
	}
	return nbytes;
}
function checkcomma(str) {
    var pos = document.getElementById(str).value.indexOf(',')
    if (pos >= 0) {
        alert('no commas allowed in the bullet points'); return false;
    }

}
// used in propertyAdd.asp propertyEdit
function chkPropertyFormItems(status) {
    
    checkcomma('ctl00_ContentPlaceHolder1_txtTextLine1');
    checkcomma('ctl00_ContentPlaceHolder1_txtTextLine2');
    checkcomma('ctl00_ContentPlaceHolder1_txtTextLine3');
    checkcomma('ctl00_ContentPlaceHolder1_txtTextLine4');
    checkcomma('ctl00_ContentPlaceHolder1_txtTextLine5');
    checkcomma('ctl00_ContentPlaceHolder1_txtTextLine6');
    checkcomma('ctl00_ContentPlaceHolder1_txtTextLine7');
    checkcomma('ctl00_ContentPlaceHolder1_txtTextLine8');
    checkcomma('ctl00_ContentPlaceHolder1_txtTextLine9');
    checkcomma('ctl00_ContentPlaceHolder1_txtTextLine10');    

    if (status == "For Rent") {
        var arrayFormItem = new Array('ctl00_ContentPlaceHolder1_ddlAgent1', 'ctl00_ContentPlaceHolder1_ddlPropType', 'ctl00_ContentPlaceHolder1_txtRoadNum', 'ctl00_ContentPlaceHolder1_txtRoadName', 'ctl00_ContentPlaceHolder1_ddlSuburb', 'ctl00_ContentPlaceHolder1_ddlPriceOption', 'ctl00_ContentPlaceHolder1_ddlPaymentPeriod', 'ctl00_ContentPlaceHolder1_ddlLeaseTerm', 'ctl00_ContentPlaceHolder1_ddlNumBed', 'ctl00_ContentPlaceHolder1_ddlNumBed', 'ctl00_ContentPlaceHolder1_ddlNumBath', 'ctl00_ContentPlaceHolder1_txtDescriptionLong', 'ctl00_ContentPlaceHolder1_txtDescriptionShort')
        var arrayFormItemDescription = new Array('Listing Agent 1', 'Property Type', 'Rd Num', 'Rd Name', 'Suburb', 'Price Option', 'Payment Period', 'Lease Term', 'Bedrooms', 'Bathrooms', 'Long Description', 'Short Description')
        var arrayCurrencyFormItem = new Array('ctl00_ContentPlaceHolder1_txtPrice', 'ctl00_ContentPlaceHolder1_txtPricelow', 'ctl00_ContentPlaceHolder1_txtPriceHigh', 'ctl00_ContentPlaceHolder1_txtBond', 'ctl00_ContentPlaceHolder1_txtInternal', 'ctl00_ContentPlaceHolder1_txtExternal','ctl00_ContentPlaceHolder1_txtCarBayRental','ctl00_ContentPlaceHolder1_txtVariableOutgoingYearly','ctl00_ContentPlaceHolder1_txtVariableOutgoingSqm','ctl00_ContentPlaceHolder1_txtPriceYearly','ctl00_ContentPlaceHolder1_txtPriceSqm','ctl00_ContentPlaceHolder1_txtOutgoings');
        var arrayCurrencyFormItemDescription = new Array('Price', 'Price Low', 'Price High', 'Bond', 'Internal Sqm', 'External Sqm','Car Bay Rental/Month','Variable Outoings/Yr','Variable Outoings/Sqm','Price/Yr','Price/Sqm','Outgoings');
    }
    else {
        var arrayFormItem = new Array('ctl00_ContentPlaceHolder1_ddlAgent1', 'ctl00_ContentPlaceHolder1_ddlPropType', 'ctl00_ContentPlaceHolder1_txtRoadNum', 'ctl00_ContentPlaceHolder1_txtRoadName', 'ctl00_ContentPlaceHolder1_ddlSuburb', 'ctl00_ContentPlaceHolder1_ddlPriceOption', 'ctl00_ContentPlaceHolder1_ddlNumBed', 'ctl00_ContentPlaceHolder1_ddlNumBath', 'ctl00_ContentPlaceHolder1_txtDescriptionLong', 'ctl00_ContentPlaceHolder1_txtDescriptionShort')
        var arrayFormItemDescription = new Array('Listing Agent 1', 'Property Type', 'Rd Num', 'Rd Name', 'Suburb', 'Price Option', 'Bedrooms', 'Bathrooms', 'Long Description', 'Short Description')
        var arrayCurrencyFormItem = new Array('ctl00_ContentPlaceHolder1_txtPrice', 'ctl00_ContentPlaceHolder1_txtPricelow', 'ctl00_ContentPlaceHolder1_txtPriceHigh', 'ctl00_ContentPlaceHolder1_txtRatesCouncil', 'ctl00_ContentPlaceHolder1_txtRatesWater', 'ctl00_ContentPlaceHolder1_txtRatesStrata', 'ctl00_ContentPlaceHolder1_txtLotsize', 'ctl00_ContentPlaceHolder1_txtInternal', 'ctl00_ContentPlaceHolder1_txtExternal', 'ctl00_ContentPlaceHolder1_txtOutgoingsRate','ctl00_ContentPlaceHolder1_txtCarBayRental','ctl00_ContentPlaceHolder1_txtVariableOutgoingYearly','ctl00_ContentPlaceHolder1_txtVariableOutgoingSqm','ctl00_ContentPlaceHolder1_txtPriceYearly','ctl00_ContentPlaceHolder1_txtPriceSqm');
        var arrayCurrencyFormItemDescription = new Array('Price', 'Price Low', 'Price High', 'Council Rates', 'Water Rates', 'Strata Rates', 'Lot Size', 'Internal Sqm', 'External Sqm', 'Outgoings','Car Bay Rental/Month','Variable Outoings/Yr','Variable Outoings/Sqm','Price/Yr','Price/Sqm');
    }

    if (checkFormItems('aspnetForm', arrayFormItem, arrayFormItemDescription)) {        
        var strPriceOption = document.getElementById("ctl00_ContentPlaceHolder1_ddlPriceOption").value;
        switch (strPriceOption) {
            case "Range":

                //                document.getElementById("ctl00_ContentPlaceHolder1_txtPrice").value = "";
                if (aspnetForm.ctl00_ContentPlaceHolder1_txtPricelow.value == "" || aspnetForm.ctl00_ContentPlaceHolder1_txtPricelow.value == "0") {
                    alert("Please fill in the field: " + "\"From\"");
                    aspnetForm.ctl00_ContentPlaceHolder1_txtPricelow.focus();
                    return false;
                }
                if (aspnetForm.ctl00_ContentPlaceHolder1_txtPriceHigh.value == "" || aspnetForm.ctl00_ContentPlaceHolder1_txtPriceHigh.value == "0") {
                    alert("Please fill in the field: " + "\"To\"");
                    aspnetForm.ctl00_ContentPlaceHolder1_txtPriceHigh.focus();
                    return false;
                }
                break;
            case "Price":

                aspnetForm.ctl00_ContentPlaceHolder1_txtPricelow.value = "";
                aspnetForm.ctl00_ContentPlaceHolder1_txtPriceHigh.value = "";
                if (aspnetForm.ctl00_ContentPlaceHolder1_txtPrice.value == "" || aspnetForm.ctl00_ContentPlaceHolder1_txtPrice.value == "0") {
                    alert("Please fill in the field: " + "\"Price\"");
                    aspnetForm.ctl00_ContentPlaceHolder1_txtPrice.focus();
                    return false;
                }
                break;
            case "PriceFrom":

                aspnetForm.ctl00_ContentPlaceHolder1_txtPricelow.value = "";
                aspnetForm.ctl00_ContentPlaceHolder1_txtPriceHigh.value = "";
                if (aspnetForm.ctl00_ContentPlaceHolder1_txtPrice.value == "" || aspnetForm.ctl00_ContentPlaceHolder1_txtPrice.value == "0") {
                    alert("Please fill in the field: " + "\"Price\"");
                    aspnetForm.ctl00_ContentPlaceHolder1_txtPrice.focus();
                    return false;
                }
                break;
            case "EOI":                
                aspnetForm.ctl00_ContentPlaceHolder1_txtPricelow.value = "";
                aspnetForm.ctl00_ContentPlaceHolder1_txtPriceHigh.value = "";
                if (aspnetForm.ctl00_ContentPlaceHolder1_txtPrice.value == "" || aspnetForm.ctl00_ContentPlaceHolder1_txtPrice.value == "0") {
                    alert("Please fill in the field: " + "\"Price\"");
                    aspnetForm.ctl00_ContentPlaceHolder1_txtPrice.focus();
                    return false;
                }
                break;
        }
        
        
        if(document.getElementById("ctl00_ContentPlaceHolder1_auctionDate")!=null)
        {
         if(document.getElementById("ctl00_ContentPlaceHolder1_auctionDate").value!='' || document.getElementById("ctl00_ContentPlaceHolder1_ddlhour").value!='' || document.getElementById("ctl00_ContentPlaceHolder1_ddlmin").value!='' || document.getElementById("ctl00_ContentPlaceHolder1_ddlampm").value!='')
         {
         
            if(document.getElementById("ctl00_ContentPlaceHolder1_auctionDate").value=='')
            {
                 alert('Please select auction date');
                  document.getElementById("ctl00_ContentPlaceHolder1_auctionDate").focus();
                  return false;
            }
         
         
            if(document.getElementById("ctl00_ContentPlaceHolder1_ddlhour").value=='' || document.getElementById("ctl00_ContentPlaceHolder1_ddlmin").value=='' ||document.getElementById("ctl00_ContentPlaceHolder1_ddlampm").value=='')
            {
                alert('Please select auction time');
                
                if(document.getElementById("ctl00_ContentPlaceHolder1_ddlampm").value=='')
                {
                    document.getElementById("ctl00_ContentPlaceHolder1_ddlampm").focus();
                }
                
                if(document.getElementById("ctl00_ContentPlaceHolder1_ddlmin").value=='')
                {
                    document.getElementById("ctl00_ContentPlaceHolder1_ddlmin").focus();
                }               
                
                
                if(document.getElementById("ctl00_ContentPlaceHolder1_ddlhour").value=='')
                {
                    document.getElementById("ctl00_ContentPlaceHolder1_ddlhour").focus();
                }
                
                return false;
            }
         }
        }                
        
        
        return (checkIsNumber('aspnetForm', arrayCurrencyFormItem, arrayCurrencyFormItemDescription))
    }
    else
        return false;

    return true;
}



/*
One Time Popup Script
By Website Abstraction (http://www.wsabstract.com) and
Java-Scripts.net (http://www.java-scripts.net)
Over 200+ free scripts here!
*/

//number of days the cookie should 
//last (0 will cause it to always pop up)
var expDays = 1; 

//url of the page you want to popup
var page = "/message.asp?mid=1";

var windowprops = "scrollbars=yes, status=yes, menubar=no, width=450, height=400, resizable=yes";

function GetCookie (name) { 
  var arg = name + "="; 
  var alen = arg.length; 
  var clen = document.cookie.length; 
  var i = 0; 
  while (i < clen) { 
    var j = i + alen; 
   if (document.cookie.substring(i, j) == arg) 
       return getCookieVal (j); 
      i = document.cookie.indexOf(" ", i) + 1; 
 if (i == 0) break; 
} 
return null;
}

function SetCookie (name, value) { 
  var argv = SetCookie.arguments; 
  var argc = SetCookie.arguments.length; 
  var expires = (argc > 2) ? argv[2] : null; 
  var path = (argc > 3) ? argv[3] : null; 
  var domain = (argc > 4) ? argv[4] : null; 
  var secure = (argc > 5) ? argv[5] : false; 
document.cookie = name + "=" + escape (value) + 
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
((path == null) ? "" : ("; path=" + path)) + 
((domain == null) ? "" : ("; domain=" + domain)) + 
((secure == true) ? "; secure" : "");

}

function DeleteCookie (name) { 
  var exp = new Date(); 
  exp.setTime (exp.getTime() - 1); 
  var cval = GetCookie (name); 
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function amt(){
  var count = GetCookie('count')
   
  if(count == null) {
    SetCookie('count','1')
    return 1
} else {
   var newcount = parseInt(count) + 1;
   DeleteCookie('count')
   SetCookie('count',newcount,exp)
return count

}

}

function getCookieVal(offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
     endstr = document.cookie.length;
     return unescape(document.cookie.substring(offset, endstr));
}

function checkCount() {
  var count = GetCookie('count');
  if (count == null) {
    count=1;
    SetCookie('count', count, exp);
    window.open(page, "", windowprops);
  } else {
    count++;
    SetCookie('count', count, exp);
  }

}

today = new Date();
sDate = today.getDate();
var sDay;
var sMonth;
var dayNames = new Array ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
var monthNames = new Array ('January','February','March','April','May','June','July','August','September','October','November','December');
sDay = dayNames[today.getDay()];
sMonth = monthNames[today.getMonth()];
sYear =  today.getYear();
sYear = sYear < 2000 ? sYear + 1900 : sYear;
finalDate =  sDay + ", " + sMonth + " " + sDate;


function echeck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("Invalid Email")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail Address")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert("Invalid E-mail Address")
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    alert("Invalid E-mail Address")
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert("Invalid E-mail Address")
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    alert("Invalid E-mail Address")
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	    alert("Invalid E-mail Address")
	    return false
	 }

	 return true					
}
