function screenres(dimension)
{
	if (dimension == 'x')
		document.write('<INPUT TYPE=hidden NAME="screenresx" VALUE="' + screen.width + '">');
	else
		document.write('<INPUT TYPE=hidden NAME="screenresy" VALUE="' + screen.height + '">');
}

function jmail(user)
{
	var user;
	var domain = 'coasthomebuyers';
	var suffix = 'com';

	document.write('<a href="' + 'mai' + 'lto:' + user + '@' + domain + '.' + suffix + '">' + user + '@' + domain + '.' + suffix + '</a>');
} 

function ValidateZip(textbox){

	var sNewZip
	var sZip
	
	sZip = textbox.value;
	sZip = sZip.replace(/\D/g, "");
		
	if (sZip.length==9)
	{
		//alert(sZip);
		sNewZip = sZip.substring(0,5) + "-" + sZip.substring(5);
		//alert(sNewZip);
		textbox.value = "";	
		textbox.value = sNewZip;		
	}

}

function ValidatePhoneNumber(textbox){

	var sNewPhone
	var sPhone
	
	sPhone = textbox.value;
	sPhone = sPhone.replace(/\D/g, "");
	
	//if (sPhone.length=7)
	//{
	//	sNewPhone = sPhone.substring(0,3) + "-" + sPhone.substring(3,7);
	//	textbox.value = "";	
	//	textbox.value = sNewPhone;
	//}
	
	//alert(sPhone)
	//alert(sPhone.length)

	if (sPhone.length==10)
	{
		sNewPhone = "(" + sPhone.substring(0,3) + ") " + sPhone.substring(3,6) + "-" + sPhone.substring(6);
		//sNewPhone = sNewPhone + sPhone.substring(6);
		textbox.value = "";	
		textbox.value = sNewPhone;	
	}
	
}

function numbersonly(myfield, e, dec)
{
	var key;
	var keychar;

	if (window.event)
   	key = window.event.keyCode;
	else if (e)
   	key = e.which;
	else
   	return true;
	keychar = String.fromCharCode(key);

	// control keys
	if ((key==null) || (key==0) || (key==8) || 
    	(key==9) || (key==13) || (key==27) )
   		return true;

	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
   		return true;

	// decimal point jump
	else if (dec && (keychar == "."))
   		{
   		myfield.form.elements[dec].focus();
   		return false;
   		}
	else
   		return false;
}

function formatCurrency(num) {
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
        num = "0";
        sign = (num == (num = Math.abs(num)));
        num = Math.floor(num*100+0.50000000001);
        cents = num%100;
        num = Math.floor(num/100).toString();
        if(cents<10)
            cents = "0" + cents;
            for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
                num = num.substring(0,num.length-(4*i+3))+','+
                num.substring(num.length-(4*i+3));
     return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function checkWholeForm(theForm) {
    var str="";
	var why = "";
	
	str = theForm.sendername.value
	if (str.length<1){
		why += "Please enter your name.\n";
	}	
	
	sPhone = theForm.phone.value;
	sPhone = sPhone.replace(/\D/g, "");	
	if (sPhone.length!=10)
	{
		why += "Please enter a valid phone number, including area code.\n";		
	}

	sPhone = theForm.altphone.value;
	sPhone = sPhone.replace(/\D/g, "");	
	if (sPhone.length!=10)
	{
		why += "Please enter a valid alternate phone number, including area code.\n";		
	}
		
	str = theForm.email.value
	if (str.length<1){
		why += "Please enter your email address.\n";
	}	
	
	str = theForm.address.value
	if (str.length<1){
		why += "Please enter the property address.\n";
	}			

	str = theForm.city.value
	if (str.length<1){
		why += "Please enter the city.\n";
	}
	
	str = theForm.marketingsource.value	
	if (str.length<1){
		why += "Please select how you found out about us.\n";
	}		

    if (why != "") {
       alert(why);
       return false;
    }
return true;
}


function popup(mylink, windowname) {
    if (! window.focus)return true;
    var href;
    if (typeof(mylink) == 'string')
        href=mylink;
    else
        href=mylink.href;
    window.open(href, windowname, 'width=600,height=400,scrollbars=yes');
    return false;
}

function targetopener(mylink, closeme, closeonly) {
    if (! (window.focus && window.opener))return true;
    window.opener.focus();
    if (! closeonly)window.opener.location.href=mylink.href;
    if (closeme)window.close();
    return false;
}
