var itemtarget="";   									//target
var itemborderwidth=0;									//image border width

var Hoffset="9px"
var Voffset="0"
var ie=document.all
var ns6=document.getElementById&&!document.all

function openWindow(theURL,winName,features) 
{
	NewWindow=window.open(theURL,winName,features);
	NewWindow.focus()
}

function itemHTML(item,alt)
{
	var itemhtml="";
	if (item[1]!=""){itemhtml='<a href="'+item[1]+'" target="'+itemtarget+'">';}
	itemhtml+='<img src="'+item[0]+'" alt="'+alt[0]+'" border="'+itemborderwidth+'"><br><center><b>'+alt[0]+'</b></center>';
	if (item[1]!=""){itemhtml+='</a>';}
	return itemhtml;
}

function ImageLoader(placeholder, itemindex)
{
	if (document.getElementById)
	{
		var itemobject=document.getElementById(placeholder);
		itemobject.innerHTML=itemHTML(itemphotos[itemindex],itemalt[itemindex]);
		return false;
	}
}

function SYS_trackObject(n, d) {
  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=SYS_trackObject(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;}

function FormCheck(formname)
{
	var errors = "";
	if (formname == "requestcma" || formname == "inquiry")
	{
		if (document.thisform.firstname.value=="") 
		{
	    	errors = errors + "- First Name is missing\n";
	    }
		if (document.thisform.email.value=="") 
		{
	    	errors = errors + "- Email Address is missing\n";
	    }
	    else
	    {
			if (email_check(document.thisform.email.value)==false)
			{
				errors = errors + "- Invalid Email Address\n";
			}
	    }
	}
	if (formname == "newsletter")
	{
		if (document.thisform.firstname.value=="") 
		{
	    	errors = errors + "- First Name is missing\n";
	    }
		if (document.thisform.email.value=="") 
		{
	    	errors = errors + "- Email Address is missing\n";
	    }
	    else
	    {
			if (email_check(document.thisform.email.value)==false)
			{
				errors = errors + "- Invalid Email Address\n";
			}
	    }
		var call = document.thisform.call;	    
		if (call.length>0 && call.value == undefined) 
		{
			if(checkEmpty(checkradiovalue(call))) 
			{
				errors = errors + "- Response missing for:  Would you like me to call you to discuss your needs? \n";
			}
		}
		var own = document.thisform.own;	    
		if (own.length>0 && own.value == undefined) 
		{
			if(checkEmpty(checkradiovalue(own))) 
			{
				errors = errors + "- Response missing for:  Do you currently own a home in " + document.thisform.community.value +"? \n";
			}
		}
		var cma = document.thisform.cma;	    
		if (cma.length>0 && cma.value == undefined) 
		{
			if(checkEmpty(checkradiovalue(cma))) 
			{
				errors = errors + "- Response missing for:  Do you require a Current Market Evaluation for your property? \n";
			}
		}
	}
	if (formname == "value")
	{
		if (document.thisform.firstname.value=="") 
		{
	    	errors = errors + "- First Name is missing\n";
	    }
		//if (document.thisform.phone.value=="") 
		//{
	    //	errors = errors + "- Phone Number is missing\n";
	    //}
		if (document.thisform.email.value=="") 
		{
	    	errors = errors + "- Email Address is missing\n";
	    }
	    else
	    {
			if (email_check(document.thisform.email.value)==false)
			{
				errors = errors + "- Invalid Email Address\n";
			}
	    }
	}
	if (errors!="")
	{
		alert (errors);
		return false;
	}
	return true;
}

function email_check(string){
	var addressPattern = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	return addressPattern.test(string);}

function checkEmpty(strng) {
	if (strng == null || strng == "") return true;
    for (i=0;i<strng.length;i++) {
    	if (strng.charAt(i) != ' ') return false;}
    return true;}
function checkradiovalue(f) {
	if (f.length>0 && f.value == undefined){
		for (var i=0; i < f.length; i++) {
			if (f[i].checked) return rad_val = f[i].value;}}
	else {
		if (f.checked) return rad_val = f.value;}    
	return null;}
