//***************************************************************************************
function getobject(arg1)
{
	if(document.getElementById)
	return document.getElementById(arg1);
	else
	if(document.all) 
	return document.all(arg1);
	else 
	return false;
}
//***************************************************************************************
function TokenizeString(StringToSplit, Token)
{
	var Split_Array=StringToSplit.split(Token);
	return Split_Array;
}


//***************************************************************************************
function isInt(Int)
{
	if(Int.toString().search(/^-?[0-9]+$/) == 0)
	{
		return true;
	}
	else
	{
		return false;
	}
}

//***************************************************************************************
function UpdatePageTitle(arg1)
{
	if (arg1=='')
	{
		//Default
		document.title = 'Property Management Companies Nationwide that Manage Rental Homes and Houses';
	}
	else
	{
		document.title = arg1;
	}
}


//***************************************************************************************
function UCWords(str)
{
  var arrStr = str.split(' ');
  var strOut = '';
  var i = 0;
  
  while (i < arrStr.length)
  {
     firstChar  = arrStr[i].substring(0,1);
     remainChar = arrStr[i].substring(1);
     firstChar  = firstChar.toUpperCase(); 
     remainChar = remainChar.toLowerCase();
     strOut += firstChar + remainChar + ' ';
     i++;
  }
  
  return strOut.substr(0,strOut.length - 1);
}


//***************************************************************************************
function SetDropDownBoxDefaultValue(DropDown_id,Default_value,UseRegExpression)
{
	if(UseRegExpression==null)
	{
		var index=0;
		while(getobject(DropDown_id).options[index].text!=null)
		{
			if(getobject(DropDown_id).options[index].text==Default_value
				|| getobject(DropDown_id).options[index].value==Default_value)
			{
				getobject(DropDown_id).options[index].selected=true;
				break;
			}
			index++;
		}
	}
	else
	{
		var index=0;
		while(getobject(DropDown_id).options[index].text!=null)
		{
			if(Default_value.test(getobject(DropDown_id).options[index].text)
				|| Default_value.test(getobject(DropDown_id).options[index].value))
			{
				getobject(DropDown_id).options[index].selected=true;
				break;
			}
			index++;
		}
	}
}
//***************************************************************************************
function ShowChangingDataScreen(Main_Div_id, Image_Div_id, ScreenWidth, ScreenHeight, Image_Div_HTML, Allow_Scroll)
{
	
	getobject(Main_Div_id).style.width = screen.availWidth;
	getobject(Main_Div_id).style.height = getobject('body').scrollHeight+100;

	getobject(Main_Div_id).style.display = 'block';
	
	getobject(Image_Div_id).style.width=ScreenWidth;
	getobject(Image_Div_id).style.height=ScreenHeight;

	getobject(Image_Div_id).style.top=getobject('body').scrollTop+((getobject('body').clientHeight/2)-125);
	getobject(Image_Div_id).style.left=(getobject('body').scrollWidth/2)-(ScreenWidth.substr(0,ScreenWidth.length-2)/2);
	
	getobject(Image_Div_id).innerHTML='';
	getobject(Image_Div_id).innerHTML=Image_Div_HTML;

	
	if(Allow_Scroll)
	{
		getobject('body').style.overflow='hidden';
		//This is because IE sucks at everything they do!!!!!
		getobject(Main_Div_id).style.height = getobject('body').scrollHeight+1000;

	}
	
	getobject(Image_Div_id).style.display = 'block';
}
//***************************************************************************************
function HideChangingDataScreen(Main_Div_id, Image_Div_id)
{
	if(getobject('body').style.overflow=='hidden')
	{
		getobject('body').style.overflow='auto';
	}
	
	//getobject(Image_Div_id).innerHTML='';
	getobject(Main_Div_id).style.display = 'none';
	getobject(Image_Div_id).style.display = 'none';
}
//***************************************************************************************
function ShowUploadLogoScreen(Main_Div_id, Image_Div_id, Image, ScreenWidth, ScreenHeight)
{
	getobject(Main_Div_id).style.width = screen.availWidth;
	getobject(Main_Div_id).style.height = getobject('body').scrollHeight+100;

	getobject(Main_Div_id).style.display = 'block';
	
	getobject(Image_Div_id).style.width=ScreenWidth;
	getobject(Image_Div_id).style.height=ScreenHeight;

	getobject(Image_Div_id).style.top=getobject('body').scrollTop+((getobject('body').clientHeight/2)-125);
	getobject(Image_Div_id).style.left=(getobject('body').scrollWidth/2)-160;
	
	getobject(Image_Div_id).innerHTML='';
									
	getobject(Image_Div_id).style.display = 'block';
}
//***************************************************************************************
function HideUploadLogoScreen(Main_Div_id, Image_Div_id)
{
	getobject(Image_Div_id).innerHTML='';
	getobject(Main_Div_id).style.display = 'none';
	getobject(Image_Div_id).style.display = 'none';
}
//***************************************************************************************
function Get_All_Checked_Checkboxes(CheckBox_Div_ID)
{
	var checkboxes = getobject(CheckBox_Div_ID).getElementsByTagName("input");
	var checkboxes_List='';
	var firstbox=true;
	for (var i = 0; i < checkboxes.length; i++) 
	{
		var checkboxes_Type = checkboxes[i].getAttribute("type");
		if (checkboxes_Type == "checkbox") 
		{
			if(checkboxes[i].checked && !checkboxes[i].disabled)
			{
				if(firstbox)
				{
					checkboxes_List+=checkboxes[i].value;
					firstbox=false;
				}
				else
				{
					checkboxes_List+='|'+checkboxes[i].value;
				}
			}
		}
	}
	return checkboxes_List;
}

//***************************************************************************************
function CheckUncheckBoxes(CheckBox_Div_ID, actiontype)
{
	var checkboxes = getobject(CheckBox_Div_ID).getElementsByTagName("input");
	var firstbox=true;
	for (var i = 0; i < checkboxes.length; i++) 
	{
		var checkboxes_Type = checkboxes[i].getAttribute("type");
		if (checkboxes_Type == "checkbox") 
		{
			if(actiontype=='check')
			{
				checkboxes[i].checked=true;
			}
			else
			{
				checkboxes[i].checked=false;
			}
		}
	}
	return true;
}


//***************************************************************************************
function ValidatePhoneSyntax (input_field_id)
{
	var PhoneValue=getobject(input_field_id).value;

	if (PhoneValue=='')
	{
		return true;
	}

	var phoneRe = /^(\d?-)*[2-9]\d{2}-\d{3}-\d{4}\s*((ext)\.?\s*(\d+))*$/; 
		
	if(phoneRe.test(PhoneValue))
	{
		getobject(input_field_id).style.backgroundColor='White';
		return true;
	}
	else
	{
		return false;
	}
}

//***************************************************************************************
function CheckProfLiability(input_field_id)
{
	var PL=getobject(input_field_id).value;
	if (PL.length!=0)
	{
		if(!isInt(PL))
		{	
			getobject(input_field_id).style.backgroundColor='RED';
			//errorNoDataSave('save_company_data');
			return false;
		}
		else
		{
			getobject(input_field_id).style.backgroundColor='WHITE';
			//allowDataSave('save_company_data');
			return true;
		}
	}
	else
	{
		getobject(input_field_id).style.backgroundColor='WHITE';
		//allowDataSave('save_company_data');
		return false;
	}
}
//***************************************************************************************
function ValidateEmailSyntax (input_field_id)
{
	var emailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{3}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/;
	if(emailRe.test(getobject(input_field_id).value))
	{
		getobject(input_field_id).style.backgroundColor='White';
		return true;
	}
	else
	{
		return false;
	}
	
}

//***************************************************************************************
function AddTableCell(Table_id, CellsToAdd, Row_innerHTML)
{
	var Row_innerHTML_array=Row_innerHTML.split('|');
	
	var Cell_Info=new Array();
	var CellArrayIndex=0;
	while(Row_innerHTML_array[CellArrayIndex].length>0)
	{
		var tempArray=Row_innerHTML_array[CellArrayIndex].split('_');
		Cell_Info[tempArray[0]]=tempArray[1];
		
	CellArrayIndex++;
	}

	var table=getobject(Table_id);
	var lastrow=table.rows.length;
	var row=table.insertRow(lastrow);
	
	var CellWidth=100/parseInt(CellsToAdd);
	
	var Cell='';
	var index=0;
	while(index<CellsToAdd)
	{
		Cell=row.insertCell(index);
		Cell.setAttribute('align','center');
		Cell.setAttribute('width',CellWidth+'%');
		Cell.setAttribute('valign','top');
		Cell.setAttribute('wordwrap','true');
		Cell.setAttribute('class','geo-FPM_Select_Area_text');
		Cell.innerHTML=Cell_Info['Cell'+index];
		
	index++;
	}
		
}
//***************************************************************************************
function AddTableCellNew(Table_id, CellsToAdd, Row_innerHTML)
{
	Cell_Info=Row_innerHTML.split('CELL_');

	if (Cell_Info.length>1)
	{
		
		var table=getobject(Table_id);
		var lastrow=table.rows.length;
		var row=table.insertRow(lastrow);
			row.setAttribute('id',Cell_Info[0]);
			
		var CellWidth=100/parseInt(CellsToAdd);
	
		var Cell='';
		var index=0;
		while(index<CellsToAdd)
		{
			Cell=row.insertCell(index);
			Cell.setAttribute('align','center');
			Cell.setAttribute('width',CellWidth+'%');
			Cell.setAttribute('valign','top');
			Cell.setAttribute('wordwrap','true');
			Cell.setAttribute('class','geo-FPM_Select_Area_text');
			Cell.innerHTML=Cell_Info[index+1]; //+1 because first row will be the TR ID
			index++;
		}
	}
		
}

//***************************************************************************************
function ClearTable(Table_id)
{
	var table = getobject(Table_id);
	var index=table.rows.length-1;
	while(index>=0)
	{
		table.deleteRow(index);
	index--;
	}	
}
//***************************************************************************************
function CreateStateList(FeildID_To_Change,JS_Events)
{
var State_Sel_List=""+
			"<Select name=\"States_Selection_dropdown\" id=\"States_Selection_dropdown\" "+JS_Events+">"+
				"<option value =\"PSS\">Please Select a State </option>"+
				"<option value =\"AL\">Alabama </option>"+
              	"<option value =\"AK\">Alaska </option>"+
                "<option value =\"AZ\">Arizona</option>"+
                "<option value =\"AR\">Arkansas </option>"+
                "<option value =\"CA\">California </option>"+
                "<option value =\"CO\">Colorado </option>"+
                "<option value =\"CT\">Connecticut</option>"+
                "<option value =\"DE\">Delaware</option>"+
                "<option value =\"FL\">Florida</option>"+
                "<option value =\"GA\">Georgia</option>"+
                "<option value =\"HI\">Hawaii </option>"+
                "<option value =\"ID\">Idaho </option>"+
                "<option value =\"IL\">Illinois </option>"+
                "<option value =\"IN\">Indiana </option>"+
                "<option value =\"IA\">Iowa </option>"+
                "<option value =\"KS\">Kansas</option>"+
                "<option value =\"KY\">Kentucky</option>"+
                "<option value =\"LA\">Louisiana</option>"+
                "<option value =\"ME\">Maine</option>"+
                "<option value =\"MD\">Maryland</option>"+
                "<option value =\"MA\">Massachusetts</option>"+
                "<option value =\"MI\">Michigan </option>"+
                "<option value =\"MN\">Minnesota</option>"+
                "<option value =\"MS\">Mississippi </option>"+
                "<option value =\"MO\">Missouri </option>"+
                "<option value =\"MT\">Montana</option>"+
                "<option value =\"NE\">Nebraska </option>"+
                "<option value =\"NV\">Nevada </option>"+
                "<option value =\"NH\">New Hampshire</option>"+
                "<option value =\"NJ\">New Jersey</option>"+
                "<option value =\"NM\">New Mexico</option>"+
                "<option value =\"NY\">New York</option>"+
                "<option value =\"NC\">North Carolina</option>"+
                "<option value =\"ND\">North Dakota</option>"+
                "<option value =\"OH\">Ohio</option>"+
                "<option value =\"OK\">Oklahoma</option>"+
                "<option value =\"OR\">Oregon </option>"+
                "<option value =\"PA\">Pennsylvania</option>"+
                "<option value =\"RI\">Rhode Island</option>"+
                "<option value =\"SC\">South Carolina</option>"+
                "<option value =\"SD\">South Dakota</option>"+
                "<option value =\"TN\">Tennessee</option>"+
                "<option value =\"TX\">Texas</option>"+
                "<option value =\"UT\">Utah</option>"+
                "<option value =\"VT\">Vermont</option>"+
                "<option value =\"VA\">Virginia</option>"+
                "<option value =\"WA\">Washington</option>"+
                "<option value =\"DC\">Washington DC</option>"+
                "<option value =\"WV\">West Virginia</option>"+
                "<option value =\"WI\">Wisconsin</option>"+
                "<option value =\"WY\">Wyoming</option>"+
			"</select>";
		getobject(FeildID_To_Change).innerHTML=State_Sel_List;
}
//***************************************************************************************
function createRequestObject() 
{
	var reqob = null;

	if (window.ActiveXObject) 
	{
		try 
		{
			reqob = new ActiveXObjec.XMLt("Msxml2HTTP");
		}
		catch (e) 
		{
			try 
			{
				reqob = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) 
			{
				try
				{
					reqob = new ActiveXObject("MSxml2.XMLHTTP");
				}
				catch (e)
				{
					reqob = false;
				}
			}
		}
	}
	else if (window.XMLHttpRequest) {
		try {
			reqob = new XMLHttpRequest();
		}
		catch (e) {
			reqob = false;
		}
	}

	return reqob;
}
//***************************************************************************************
var http = createRequestObject();

