/* Generic check checkbox function*/
function selectCheckbox(strID) {
	document.getElementById(strID).checked = true;
}

/* Generic check email function*/
function checkEmail(emailAddy) {
  if (emailAddy.value.length==0)
  {
    return true ;
  }
  if (emailAddy.value.indexOf("@",0) < 1 || emailAddy.value.indexOf(".",0) < 1)
  {
    alert("Please check the field:\n The email address appears incorrectly formed") ;
    emailAddy.focus() ;
	return false ;
  }
  return true ;
}

/* Function to check if year is valid ie. Initial value of "Year" or otherwise it must be a   numeric. Don't worry if the person believes they are a few centuries old! */
function checkYear(numberField) {
  allNumeric=true ;
  if (numberField.value.length==0 || numberField.value=="Year")
  {
    return true ;
  }

  for (i=0 ; i<numberField.value.length ; i++)  {    checkChar=numberField.value.charAt(i) ;
    if (checkChar<'0' || checkChar>'9')
	{
	  allNumeric=false ;
	}  
  }
  
  if (allNumeric==false)
  {
    alert("Please check the field:\n Only numbers permitted");
	numberField.focus() ;
	return false ;
  }
  
  return true ;
}

/* generic check for number(ie 0-9) */
function checkNumber(numberField) {
  allNumeric=true ;
  if (numberField.value.length==0)
  {
    return true ;
  }

  for (i=0 ; i<numberField.value.length ; i++)  {    checkChar=numberField.value.charAt(i) ;
    if (checkChar<'0' || checkChar>'9')
	{
	  allNumeric=false ;
	}  
  }
  
  if (allNumeric==false)
  {
    alert("Please check the field:\n Only numbers permitted");
	numberField.value = "";
	numberField.focus(numberField);
	return false ;
  }
  return true ;
}

/* generic phone number checker allowing brackets for prefix */
function checkPhone(phoneField) {
  allNumeric=true ;
  if (phoneField.value.length==0)
  {
    return true ;
  }
  
  for (i=0 ; i<phoneField.value.length ; i++)  {    checkChar=phoneField.value.charAt(i) ;
    if (checkChar!=' ' && checkChar!='\(' && checkChar!='\)'  && (checkChar<'0' || checkChar>'9') )
	{
	  allNumeric=false ;
	}  
  }
  
  if (allNumeric==false)
  {
    alert("Please check the field:\n Only numbers, spaces and \(\) permitted");
	phoneField.focus() ;
	return false ;
  }
  return true ;
}

//confirm delete message
function confirmDelete(theMessage,theDirect) {
  if( confirm(theMessage) ) {
    canClose = false;
 	document.location.replace(theDirect);
  }
}

function myfunc()
{
	document.location.href=document.fmSearch.strSearchType.options[document.fmSearch.strSearchType.selectedIndex].value + "?strKeyword=" + document.fmSearch.strKeyword.value;
	return false;
}

function activate(showthis, iconshow, iconhide){
		if (document.getElementById(showthis).style.display == '')
			document.getElementById(showthis).style.display = 'none';
		else
			document.getElementById(showthis).style.display = '';
			
		if (iconshow != null){
			document.getElementById(iconshow).style.display = '';
			document.getElementById(iconhide).style.display = 'none';
		}
	}
	function initialise(hidethis, display){
		if (display == 'hide'){
			//alert(hidethis);
			document.getElementById(hidethis).style.display = 'none';
		}
		if (display == 'show'){
			//alert(hidethis);
			document.getElementById(hidethis).style.display = '';
		}
	}

//function used for currency change
function menudirect(curchange){
var URL = document.curchange.currencyid.options[document.curchange.currencyid.selectedIndex].value;
window.location.href = URL;
}

function killAutofill(){
  is = document.getElementsByTagName("INPUT");
  for(i=0;i<is.length;i++)
    is[i].style.backgroundColor = "";
  ss = document.getElementsByTagName("SELECT");
  for(i=0;i<ss.length;i++)
    ss[i].style.backgroundColor = "";
}

//Newsletter subscribe form
function focusName(element) {
  if (element.value == " name...") {
    element.value = "";
  }
}

function blurName(element) {
  if (element.value == "") {
    element.value = " name...";
  }
}

function focusEmail(element) {
  if (element.value == " email...") {
    element.value = "";
  }
}

function blurEmail(element) {
  if (element.value == "") {
    element.value = " email...";
  }
}

function checkName(str)
{
        var vname = str
		if (vname == " name...")
             return false;
        if (vname == "")
             return false;
        return true;
}
function checkEmailF(str)
{
        var apos = str.indexOf("@");
        var dpos = str.indexOf(".");
        var epos = str.indexOf("]");
        var fpos = str.indexOf("[");     
        if (apos<=0 || dpos<=0 || epos>0 || fpos>0 )
             return false;
        if (dpos+1>=str.length)
             return false;
        return true;
}
function ValidateForm()
{
        if (!checkName(document.theForm.name.value)){
                alert("Please enter your first name.");
                return false;
        }
		if (!checkEmailF(document.theForm.email.value)){
                alert("Please enter a valid email address.");
                return false;
        }
	return true;
}

function enquiryForm(contact) {
  allCorrect=true ;
  
  if (contact.FirstName.value=="" || 
	  contact.LastName.value=="" ||
	  contact.Phone.value=="" ||
	  contact.Email.value=="" ) {
	allCorrect=false ;
  }
  if (allCorrect==false)
  {
	alert("Please fill in all fields marked *") ;
	return false ;
  } 
	return true ;
}

//no spam email address
var user;
var domain;
var suffix;
function nospam(user,domain,suffix) {
	document.write('<a href="' + 'mailto:' + user + '@' + domain + '.' + suffix + '">' + user + '@' + domain + '.' + suffix + '</a>');
}

function nospamsml(user,domain,suffix) {
	document.write('<a href="' + 'mailto:' + user + '@' + domain + '.' + suffix + '" class="lnkNBlack10UL">' + user + '@' + domain + '.' + suffix + '</a>');
}

//netscape css fix

function WM_netscapeCssFix() {
   if (document.WM.WM_netscapeCssFix.initWindowWidth != window.innerWidth || document.WM.WM_netscapeCssFix.initWindowHeight != window.innerHeight) {
    document.location = document.location;
  }
}

function WM_netscapeCssFixCheckIn() {
  if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) == 4)) {
    if (typeof document.WM == 'undefined'){
      document.WM = new Object;
    }
    if (typeof document.WM.WM_scaleFont == 'undefined') {
      document.WM.WM_netscapeCssFix = new Object;
      document.WM.WM_netscapeCssFix.initWindowWidth = window.innerWidth;
      document.WM.WM_netscapeCssFix.initWindowHeight = window.innerHeight;
    }
    window.onresize = WM_netscapeCssFix;
  }
}

WM_netscapeCssFixCheckIn()

//prevents window from capture in frames

if (top.location != self.location) {
        top.location = self.location
}

//popup windows for references

function popupWindow(referenceHTML, w, h) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	windowProperties = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,resizable'
	reference = window.open(referenceHTML, 'refName', windowProperties)
	if (parseInt(navigator.appVersion) >= 4) { reference.window.focus(); }
	}

//popup windows for calculators

function popupCalculator(mypage,myname,w,h,scroll) {
	var wi = screen.width - 100;
	var he = screen.height - 100;
	var winl = (screen.width - wi) / 2;
	var wint = ((screen.height - he) / 2) - 20;
	winprops = 'height='+he+',width='+wi+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function PrintThisPage() 
{ 
	var w = 700;
	var h = 450;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	var sOption = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,resizable'
   	var sWinHTML = document.getElementById('contentarea').innerHTML; 
   	var winprint=window.open("","",sOption);
       winprint.document.open(); 
       winprint.document.write('<html><head><title>Lawyers Conveyancing</title>'); 
       winprint.document.write('<link rel="stylesheet" href="http://www.lawyersrealestate.com.au/inc/lawyersrealestate.css" type="text/css">'); 
       winprint.document.write('<script language="JavaScript" src="/inc/lawyersrealestate.js"></script>'); 
       winprint.document.write('</head>'); 
       winprint.document.write('<body><a name="top"></a>'); 
       winprint.document.write('<table width="100%" "cellpadding="0" cellspacing="0"><tr><td align="left" class="txtNBlue11"><b>Lawyers Conveyancing</b><br>');
	   winprint.document.write('<a href="mailto:enquiries@lawyersrealestate.com.au" class="lnkNBlue11UL">enquiries@lawyersrealestate.com.au</a><br><br></td>');
	   winprint.document.write('<td align="right"><span class="txtNBlack10">[<a href="javascript:window.close()" class="lnkNBlack10HL">close window</a>]</span></td></tr></table>'); 
       winprint.document.write(sWinHTML);          
       winprint.document.write('</body></html>'); 
       winprint.document.close(); 
       winprint.focus(); 
}
function FlashControl(ClsId,Url,Width,Height,AutoStart)
{
	document.write('<object classid="' + ClsId + '" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + Width + '" height="' + Height + '">')
	document.write('<param name="movie" value="' + Url + '">')							  
	document.write('<param name="wmode" value="Transparent">')
	document.write('<param name="quality" value="high">')
	document.write('<param name="menu" value="false">')
	document.write('<embed src="' + Url + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + Width + '" height="' + Height + '" menu="false" wmode="Transparent"></embed>')
	document.write('</object>')
}
