// Common LRE functions

var propNum = 1; // Default big-pic viewing number

var currentTime = new Date();
var year = currentTime.getFullYear();

//////////////////
// 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";
    var date = new Date();
    var now = date.getTime();
    var name = (now).toString(10);
    
    window.open(url,name,args);
}

//////////////////////////
// Verification Functions
/* Still used?  Conflicting with other verify()
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) {
    /*
    // changing the alt doesn't seem to work in Firefox, but does work in IE
    if (target.alt == "") {target.alt = "Image Not Available";}
    */
    // undoing the onerror keeps us from getting into an infinite loop if replacement is bad
    target.onerror = '';
    target.onError = ''; // just in case we capitalized like standard
    target.src = replacement;
}

/////////////////////////
// MySite thing
function change(src, target)
{
    if (src.checked)
    {
        document.getElementById(target).value = 1;
    } else {
        document.getElementById(target).value = 0;
    }
}

function flip(src, target)
{
    if (src.checked)
    {
        document.getElementById(target).value = target;
    } else {
        document.getElementById(target).value = '';
    }
}


/////////////////////////
// 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];}
}
//////////////////////

sfHover = function()
		{
			var x = cssQuery("ul[id='mainMenu']");
			var sfEls = cssQuery("li", x);
			for (var i=0; i<sfEls.length; i++)
			{
				sfEls[i].onmouseover=function() {
					this.className+=" sfhover";
					hideDropDown();
				}
				sfEls[i].onmouseout=function() {
					this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
					showDropDown();
				}
			}
		}
		
function hideDropDown()
{
}


function showDropDown()
{
}

//puts up bookmark logo if IE 
function bookmark() {
	if (window.external)
	document.write('<a href="javascript:window.external.AddFavorite(self.location,document.title)"><img src="images\/mar_web_bookmark_ico.gif" border="0"><\/a>');
}

function verify(theForm)
{
 var why = "";
 why += checkField(theForm.FirstName.value, "First Name");
 why += checkField(theForm.LastName.value, "Last Name");
 why += checkField(theForm.Company.value, "Company"); 
 why += checkEmail(theForm.Email.value, "Email");
 why += checkField(theForm.Phone.value, "Phone"); 
 if (why != "") {
  alert(why);
  return false;
 }
 return true;
}
 
function checkEmail(val, type) {
    var error = "";
    if ((val == "" || val.length < 3) || (val.indexOf("@") == "-1") || (val.indexOf(".") == "-1")) {
        error = "Please enter a valid '" + type + "' E-mail address.\n";
    }
 
    return error;
}
 
function checkField (val, field) {
 var error = "";
 if (val == "") {
  error = "You must enter a value in the " + field + " field.\n";
 }
 
 var crud = /["'`]/; // No quotes please!
 if (crud.test(val)) {
  error = "No quotes are allowed in the " + field + " field.\n";
 }
 
 return error;
}


