if (document.images)

{
	tmPics= new Array(4);
	tmPics[0] = new Array(2);
	tmPics[0][0] = new Image();
	tmPics[0][0].src = "images/pmenu/m-home.gif";
	tmPics[0][1] = new Image();
	tmPics[0][1].src = "images/pmenu/s-home.gif";
	tmPics[1] = new Array(2);
	tmPics[1][0] = new Image();
	tmPics[1][0].src = "images/pmenu/m-about.gif";
	tmPics[1][1] = new Image();
	tmPics[1][1].src = "images/pmenu/s-about.gif";
	tmPics[2] = new Array(2);
	tmPics[2][0] = new Image();
	tmPics[2][0].src = "images/pmenu/m-buying.gif";
	tmPics[2][1] = new Image();
	tmPics[2][1].src = "images/pmenu/s-buying.gif";
	tmPics[3] = new Array(2);
	tmPics[3][0] = new Image();
	tmPics[3][0].src = "images/pmenu/m-selling.gif";
	tmPics[3][1] = new Image();
	tmPics[3][1].src = "images/pmenu/s-selling.gif";
	tmPics[4] = new Array(2);
	tmPics[4][0] = new Image();
	tmPics[4][0].src = "images/pmenu/m-letting.gif";
	tmPics[4][1] = new Image();
	tmPics[4][1].src = "images/pmenu/s-letting.gif";
	tmPics[5] = new Array(2);
	tmPics[5][0] = new Image();
	tmPics[5][0].src = "images/pmenu/m-relocation.gif";
	tmPics[5][1] = new Image();
	tmPics[5][1].src = "images/pmenu/s-relocation.gif";
	tmPics[6] = new Array(2);
	tmPics[6][0] = new Image();
	tmPics[6][0].src = "images/pmenu/m-premier.gif";
	tmPics[6][1] = new Image();
	tmPics[6][1].src = "images/pmenu/s-premier.gif";
	tmPics[7] = new Array(2);
	tmPics[7][0] = new Image();
	tmPics[7][0].src = "images/pmenu/m-local.gif";
	tmPics[7][1] = new Image();
	tmPics[7][1].src = "images/pmenu/s-local.gif";
	tmPics[8] = new Array(2);
	tmPics[8][0] = new Image();
	tmPics[8][0].src = "images/pmenu/m-emag.gif";
	tmPics[8][1] = new Image();
	tmPics[8][1].src = "images/pmenu/s-emag.gif";
	tmPics[9] = new Array(2);
	tmPics[9][0] = new Image();
	tmPics[9][0].src = "images/pmenu/m-mailing.gif";
	tmPics[9][1] = new Image();
	tmPics[9][1].src = "images/pmenu/s-mailing.gif";
	tmPics[10] = new Array(2);
	tmPics[10][0] = new Image();
	tmPics[10][0].src = "images/pmenu/m-contact.gif";
	tmPics[10][1] = new Image();
	tmPics[10][1].src = "images/pmenu/s-contact.gif";
}



function tmOn(which)
 {
   if (document.images)
    {
      document.getElementById("tm"+which).src= tmPics[which][1].src;
    }
 }

function tmOff(which)
 {
   if (document.images)
    {
      document.getElementById("tm"+which).src= tmPics[which][0].src;
    }
 }



function getElementsByClassname(clsName)
{    
	var retVal = new Array();    
	var elements = document.getElementsByTagName("*");
    for(var i = 0;i < elements.length;i++)
	{        
		if(elements[i].className.indexOf(" ") >= 0)
		{
			var classes = elements[i].className.split(" ");
            for(var j = 0;j < classes.length;j++)
			{                
				if(classes[j] == clsName)                    
					retVal.push(elements[i]);            
			}        
		}        
		else if(elements[i].className == clsName)
			retVal.push(elements[i]);    
	}    
	return retVal;
}



function deletetemplate(message) {
if (message == null){
   message = "Are you sure you want to remove this item?";
 }
if (confirm(message)) 
return true; 
else 
return false; 

}



function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function isInt(x) { 
   var y=parseInt(x); 
   if (isNaN(y)) return false; 
   return x==y && x.toString()==y.toString(); 
 } 
 
 function isNumber(x)
 {
	//var y = x * 1;
	if (isNan(x)) return false;
	return true;
 }
 
function isPosNumber(x)
 {
	//var y = x * 1;
	if (isNaN(x)) return false;
	if (x <=0) return false;
	return true;
 }
 
 
function isPosInt(x) { 
   var y=parseInt(x); 
   if (isNaN(y)) return false;
   if (y <= 0) return false;
   return x==y && x.toString()==y.toString(); 
 } 
 
 function isNotNeg(x) { 
   var y=parseInt(x); 
   if (isNaN(y)) return false;
   if (y < 0) return false;
   return x==y && x.toString()==y.toString(); 
 } 


function Left(str, n)
{
   if (n <= 0)
         return "";
   else if (n > String(str).length)
         return str;
   else
         return String(str).substring(0,n);
}


function checkEmail(strEmail) 
{
	var filter = /^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i;
	if (!filter.test(strEmail)) 
	{
		return false;
	}
	else
	{
		return true;
	}
}

function checknocode(notocheck)
{

var checkOK = "0123456789";
var checkStr = notocheck;
var allValid = true;

for (i = 0;  i < checkStr.length;  i++)
{
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkOK.length;  j++)
	if (ch == checkOK.charAt(j))
	break;
	if (j == checkOK.length)
	{
	     
		allValid = false;
		break;
	}
}
return allValid;
}


function checkNumeric(objName,minval,maxval,period)
{
var checkOK = "0123456789" + period;
var checkStr = objName;
var allValid = true;
var decPoints = 0;
var allNum = "";

for (i = 0;  i < checkStr.value.length;  i++)
{
	ch = checkStr.value.charAt(i);
	for (j = 0;  j < checkOK.length;  j++)
	if (ch == checkOK.charAt(j))
	break;
	if (j == checkOK.length)
	{
		allValid = false;
		break;
	}
	if (ch != ",")
		allNum += ch;
}
if (!allValid)
{	
	return (false);
}// set the minimum and maximum
var chkVal = allNum;
var prsVal = parseInt(allNum);
if (chkVal != "" && !(prsVal >= minval && prsVal <= maxval))
{
	return (false);
}
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

function setDisabled(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.disabled = newValue;
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].disabled = newValue;
	}
}



function isradio(oField)
{
	if (typeof(oField[0]) !=  "undefined")
	{
		if (oField[0].type=="radio")
		{
			return true;
		}
	}
	return false;
}

function checkform(frmName)
{
	var bGoingon = true;
	var nItems = document.forms[frmName].elements.length;
	for (x=0; x < nItems; x++)
	{
		oField = document.forms[frmName].elements[x];
		strField =  document.forms[frmName].elements[x].name;
		if (Left(strField,2)=="r_")
		{
			strVal = "";
			if (typeof(oField) == "undefined")
				continue;

			strVal = trim(document.forms[frmName].elements[strField].value);

			thisOK = true;
			errMessage = ""
			if (Left(strField,3)=="r_e")
			{
				if (strVal.length < 1)
				{
					thisOK = false;
				}
				else if (!checkEmail(strVal))
				{
					thisOK = false;
				}
			}
			else if (Left(strField,3)=="r_i")
			{
				if (strVal.length < 1)
				{
					thisOK = false;
				}
			
				else if (!isInt(strVal))
				{
					thisOK = false;
				}
			}
			else if (Left(strField,3)=="r_I")
			{
				if (strVal.length < 1)
				{
					thisOK = false;
				}

				else if (!isPosInt(strVal))
				{
					thisOK = false;
				}
			}
			
			else if (Left(strField,3)=="r_Z")
			{
				if (strVal.length < 1)
				{
					thisOK = false;
				}

				else if (!isNotNeg(strVal))
				{
					thisOK = false;
				}
			}

			else if (Left(strField,3)=="r_B")
			{
				if (!document.forms[frmName].elements[strField].checked)
				{
					thisOK = false;
				}
			}
			
			else if (Left(strField,3)=="r_n")
			{
				if (strVal.length < 1)
				{
					thisOK = false;
				}

				else if (!isNumber(strVal))
				{
					thisOK = false;
				}
			}
			else if (Left(strField,3)=="r_N")
			{
				if (strVal.length < 1)
				{
					thisOK = false;
				}

				else if (!isPosNumber(strVal))
				{
					thisOK = false;	
			
				}
			}

			
			else if (Left(strField,3)=="r_Y")
			{
				if (strVal.length < 1)
				{
					thisOK = false;
				}
				else if (!checknocode(strVal))
				{
					thisOK = false;	
				}
			}
			
			else if (Left(strField,3)=="r_s")
			{
				if (strVal.length < 1)
				{
					thisOK = false;
				}
			}
			if (!thisOK)
			{
				bGoingon = false;
				oField.style.borderColor = "red";
				
				
			}
			else
			{
				oField.style.borderColor = "#918b87";
			}

		}
	}
	if (bGoingon)
	{
		return true;
	}
	else
	{
		alert("Please complete required fields");
		return false;
	}

}

function goodpass(checkStr, minlength, maxlength)
{
	var checkOK = "0123456789abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var foundit = true;
	if (checkStr.length < minlength)
		return false;
	else if (checkStr.length > maxlength)
		return false;
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		foundit = false;
		for (j = 0;  j < checkOK.length;  j++)
		{
			if (ch == checkOK.charAt(j))
			{
				foundit = true;
				break;
			}
		}	
			
		if (!foundit)
			return false
	}
	return true;
}

function checkpassform()
{
	if (goodpass(document.forms["login_form"].username.value, 5, 20) && goodpass(document.forms["login_form"].password.value, 4, 20))
	{
		doChallengeResponse();
		return true;
	}
	else
	{
		alert("Invalid user name or password");
		return false;
	}
}

function doChallengeResponse() {
        str = document.forms["login_form"].username.value.toLowerCase() + ":" + 
        sha256_digest(document.forms["login_form"].password.value) + ":" + 
        document.forms["login_form"].challenge.value; 
        document.forms["login_form"].password.value = ""; 
        document.forms["login_form"].challenge.value = ""; 
        document.forms["login_form"].response.value = sha256_digest(str); 
        return false; 
  } 
  
  function showmap()
  {
	window.open('http://www.julierossresidential.com/images/map.gif','mapwindow','width=560,height=560,left=50,top=20,screenX=50,screenY=20');
	return false;
  }