// Common LRE functions

var propNum = 1; // Default big-pic viewing number

//////////////////
// Popup Functions

function popUpImg(url, pageWidth, pageHeight)
{
    var args = "width=" + (pageWidth + 20) + ",height=" + (pageHeight + 10) + ",scrollbars,resizable";
    var date = new Date();
    var now = date.getTime();
    var name = (now).toString(10);
    
    _w = window.open('',name,args);
    _w.document.open();
    _w.document.write("<html>\n<head><title>Viewing " + url + "</title>\n</head>\n<body style='margin: 0px'>\n");
    _w.document.write("<meta http-equiv='imagetoolbar' content='no'>");
    _w.document.write("<table width='100%' border='0' cellpadding='0' cellspacing='0' style='height: 100%'>\n<tr>\n<td align='center' valign='middle'>\n");
    _w.document.write("<a href='javascript:window.close()'><img src='" + url + "' alt='Click to close' border='0' /></a>\n");
    _w.document.write("</td></tr></table>\n");
    _w.document.write("</body>\n</html>");
    _w.document.close();
}

function popUp(url, pageWidth, pageHeight)
{
    var args = "width=" + pageWidth + ",height=" + pageHeight + ",scrollbars,resizable=no";
    var date = new Date();
    var now = date.getTime();
    var name = (now).toString(10);
    
    window.open(url,name,args);
}

//////////////////////////
// Verification Functions

function verify(msg)
{
    return confirm(msg);
}

function checkEmail(val, type) {
    var error = "";
    if ((val == "" || val.length < 3) || (val.indexOf("@") == "-1") || (val.indexOf(".") == "-1")) {
        error = "Please enter a valid '" + type + "' email address.\n";
    }

    return error;
}

function verifyForm(theForm) {
    var why = "";
    if (theForm.realname)
    {
		val = theForm.realname.value;
		if (val == "") {
			why += "Please enter a valid name.\n";
		}
    }
    if (theForm.email)
    {
        why += checkEmail(theForm.email.value, 'from');
    }
    if (theForm.recipient)
    {
        why += checkEmail(theForm.recipient.value, 'to');
    }
    
    if (why != "") {
        alert(why);
        return false;
    }
    return true;
}

/////////////////////////
// Featured Properties Slideshow
function runSlideShow(){
    if(typeof(document.images.PictureBox) == "undefined")
    {
        return;
    }

    if (document.all){
        document.images.PictureBox.style.filter="blendTrans(duration=2)";
        document.images.PictureBox.style.filter="blendTrans(duration=CrossFadeDuration)";
        document.images.PictureBox.filters.blendTrans.Apply();
    }

    if (document.getElementById) // If we`re not in Netscape 4.x
    {
        document.images.PictureBox.src = preLoad[jss].src;
        if (document.getElementById) document.getElementById("featTitle").innerHTML    = featTitle[jss];
        if (document.getElementById) document.getElementById("featLocation").innerHTML = featLocation[jss];
        if (document.getElementById) document.getElementById("featBed").innerHTML      = featBed[jss];
        if (document.getElementById) document.getElementById("featBath").innerHTML     = featBath[jss];
        if (document.getElementById) document.getElementById("featPrice").innerHTML    = featPrice[jss];
        if (document.getElementById) document.getElementById("featSqfeet").innerHTML   = featSqfeet[jss];
        if (document.all) document.images.PictureBox.filters.blendTrans.Play();

        featID = featIDArray[jss];

        jss = jss + 1;
        if (jss > (pss)) jss=1;
        tss = setTimeout('runSlideShow()', SlideShowSpeed);
    }
}

function openFeatProp(target)
{
    location.href = target + featID;
}

function checkForSearchCriteria(theForm)
{
    ok = false;
    
    for(i=0;i<theForm.length;i++)
    {
    	// Check if it's not a required field
    	if (theForm.elements[i].name != 'siteScript'
    		&& theForm.elements[i].name != 'siteScreen'
    		&& theForm.elements[i].name != 'action')
    	{
    		if (theForm.elements[i].value)
    		{
    			ok = true;
    		}    		
    	}
    }
    if (ok == false)
    {
    	alert("Please enter more search criteria.");
    }
    return ok;
}

///////////////////////////
// Broken-Image Prevention
function ImageLoadFailed(target, replacement) {
    target.src = replacement;
}

/////////////////////////
// Dreamweaver Functions

function MM_swapImgRestore() { //v3.0
  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() { //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 MM_findObj(n, d) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  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];}
}
