var nextHighestContentItem = 1;
var current_parent_id = -1;
var nextHighestImageId = 0;
var __short_sale = -1;
var __contact = 0;
var __document = 0;
var __content = 0;
var __category = 0;
var __listing = 0;
var __contact_group = 0;
var __mortgage = 0;
var __form = 0;
var __image = 0;
var __forms = '';
var __leads = 1;

function save_form(theform)
{
	//alert(__short_sale);
	var a = new Array();
	a = parse_form_vars_to_array(theform);
	a['__action'] = 'SAVEFORM';
	a['__short_sale'] = __short_sale;
	a['__leads'] = __leads;
	
	var rv = clientRequestResponse('/admin/shortsales_manager.php',a,'POST');
	
	return rv;
}

function save_form_bp(theform)
{
	var a = new Array();
	a = parse_form_vars_to_array(theform);
	a['__action'] = 'SAVEFORMBP';
	
	var rv = clientRequestResponse('/admin/shortsales_manager.php',a,'POST');
	//alert(rv);
	return rv;
}

function load_form(__form_name)
{
	var a = new Array();
	a['__action'] = 'LOADFORM';
	a['__short_sale'] = __short_sale;
	a['__form_name'] = __form_name;
	a['__leads'] = __leads;
	clientRequest('property_content','/admin/shortsales_manager.php',a,'POST');
}

function tell_a_friend(theform)
{
	var a = new Array();
	a = parse_form_vars_to_array(theform);
	a['__action'] = 'TELLAFRIEND';
	var rv = clientRequestResponse('/client_manager.php',a,'POST');
	
	alert(rv);
	
	if(rv.indexOf('ERROR:') == -1)
	{
		theform.yemail.value = '';
		theform.f1email.value = '';
		theform.f2email.value = '';
		theform.yname.value = '';
		theform.f1name.value = '';
		theform.f2name.value = '';
	}
	
	return rv;
}

function contact_us(theform)
{
	var a = new Array();
		
	a = parse_form_vars_to_array(theform);
	a['__action'] = 'CONTACTUS';
	
	rePhoneNumber = new RegExp(/^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/);
	rePhoneNumber2 = new RegExp(/^[1-9]\d{2}\-\d{3}\-\d{4}$/);
	rePhoneNumber3 = new RegExp(/^[1-9]\d{9}$/);
 
    if (!rePhoneNumber.test(theform.phone.value) && !rePhoneNumber2.test(theform.phone.value) && !rePhoneNumber3.test(theform.phone.value))
	{
		alert("Error sending message:\r\n\r\nPhone Number should be in this format 555-555-1212");
	}
	else
	{
		var rv = clientRequestResponse('/client_manager.php',a,'POST');
		alert(rv);
	
		if(rv == 'Your message has been sent!')
		{
			theform.name.value = '';
			theform.email.value = '';
			theform.phone.value = '';
			theform.comment.value = '';
		}
	}
	
	return rv;
}

function is_valid_phone(str)
{
	rePhoneNumber = new RegExp(/^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/);
	rePhoneNumber2 = new RegExp(/^[1-9]\d{2}\-\d{3}\-\d{4}$/);
	rePhoneNumber3 = new RegExp(/^[1-9]\d{9}$/);
	
	if (!rePhoneNumber.test(str) && !rePhoneNumber2.test(str) && !rePhoneNumber3.test(str))
	{
		return false;
	}
	else
	{
		return true;
	}
}

function is_empty(str)
{
	if(str.length == 0)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function is_valid_email(str)
{
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1)
	{
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	{
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
	{
		return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1)
	 {
		return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	 {
		return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1)
	 {
		return false;
	 }
	
	 if (str.indexOf(" ")!=-1)
	 {
		return false;
	 }

	 return true;
}











