var add_community="add_community.php";
var all_testimonials="all_testimonials.php";
var root="http://www.hoasite.net/index.php";
var height=460;
xpos2=0;
ypos2=0;
iWidth2=200;
iHeight2=250;
xpos2=(screen.width-iWidth2)/2;
ypos2=(screen.height-iHeight2)/2;
var selected_row=""
function m_onClick(obj){
	if(selected_row!=""){
		selected_row.style.backgroundColor='#F5F5F5'
	}
	obj.style.backgroundColor='#CCCCCC'
	selected_row=obj
}
function m_onOver(obj){
	obj.style.backgroundColor='#FFFFCC'
}
function m_onOut(obj){
	if(selected_row!=obj){
		obj.style.backgroundColor='#F5F5F5'
	}else{
		obj.style.backgroundColor='#CCCCCC'
	}
}
function doChkExp()
{
	window.location='community_detail.php?at=cd&csv=1';	
}

function doZip()
{
	window.open('add_zip.php','AddZip','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=200,height=250,screenx='+xpos2+',screeny='+ypos2+',left='+xpos2+',top='+ypos2+'');
}

function openLnk(lnk)
{
	if(this.add_community==lnk)
	{
		var home_page=location.href;	
		if((home_page==this.root)||(home_page==this.root+"#")||(home_page==this.root+"?q=2"))
		{
			document.getElementById("mainFrame").innerHTML="<iframe marginheight='0' marginwidth='0' frameborder='0' src='"+add_community+"' width='550' height='"+height+"'></frame>";
			document.getElementById("more").style.visibility="hidden";
		}
		else
		{
			location.href="index.php?q=2";
		}
		
	}
	else if(this.all_testimonials==lnk)
	{
		var home_page=location.href;
		if((home_page==this.root)||(home_page==this.root+"#"))
		{
			document.getElementById("mainFrame").innerHTML="<iframe frameborder='0' src='"+all_testimonials+"' width='550' height='"+height+"'></frame>";
		}
		else
		{
			location.href="index.php?q=1";
		}
	}
}

function doCancel()
{
	window.parent.location=this.root;
}
function doValidate()
{
	var errstr = "";
	var flagerr =0;
	if(document.frmAddCommunity.txt_community_name.value=="Community name goes here" || document.frmAddCommunity.txt_community_name.value=="")
	{
			if(document.frmAddCommunity.txt_community_name.value!="")
			{
				errstr = errstr + "Incorrect community name.\n"
			}
			else
			{
				errstr = errstr + "Please enter community name.\n"
			}
			flagerr=1;
	}
	if(document.frmAddCommunity.txt_community_name.value!="" && document.frmAddCommunity.txt_community_name.value.length >=100)
	{
			errstr = errstr + "Community name can be 100 characters long. Please re-enter the community name.\n"
			flagerr=1;
	}
	if(document.frmAddCommunity.txt_street_add1.value=="Community address goes here" || document.frmAddCommunity.txt_street_add1.value=="")
	{
			if(document.frmAddCommunity.txt_street_add1.value!="")
			{
				errstr = errstr + "Incorrect street address.\n"
			}
			else
			{
				errstr = errstr + "Please enter street address.\n"
			}
			flagerr=1;
	}
	if(document.frmAddCommunity.txt_city.value=="City" || document.frmAddCommunity.txt_city.value=="")
	{
			if(document.frmAddCommunity.txt_city.value!="")
			{
				errstr = errstr + "Incorrect city.\n"
			}
			else
			{
				errstr = errstr + "Please enter city.\n"
			}
			flagerr=1;
	}
	if(document.frmAddCommunity.cb_state[document.frmAddCommunity.cb_state.selectedIndex].text=="Select.....")
	{
			errstr = errstr + "Please select state.\n"
			flagerr=1;
	}
	if(document.frmAddCommunity.txt_zip.value=="")
	{
			errstr = errstr + "Please enter zipcode.\n"
			flagerr=1;
	}
	if (document.frmAddCommunity.community_photo.value!="")
	{
		var lo=document.frmAddCommunity.community_photo.value
		var flo=lo.split("\\")
		var len=flo.length
		var nm=flo[len-1]
		var xt=nm.split(".")
		var xtlen=xt.length
		var ext = xt[xtlen-1];
			if(ext!="jpg" && ext!="gif" && ext!="png" && ext!="JPG" && ext!="GIF" && ext!="PNG")
			{
				errstr = errstr + "Please upload jpg,gif or png photo.\n"
				flagerr=1;
			}
	}
	if(document.frmAddCommunity.txt_contact_name.value=="Enter first name of contact person" || document.frmAddCommunity.txt_contact_name.value=="")
	{
			if(document.frmAddCommunity.txt_contact_name.value!="")
			{
				errstr = errstr + "Incorrect first name.\n"
			}
			else
			{
				errstr = errstr + "Please enter First name.\n"				
			}
			flagerr=1;
	}
	if(document.frmAddCommunity.txtlastname.value=="Enter last name of contact person" || document.frmAddCommunity.txtlastname.value=="")
	{
			if(document.frmAddCommunity.txtlastname.value!="")
			{
				errstr = errstr + "Incorrect last name.\n"
			}
			else
			{
				errstr = errstr + "Please enter last name.\n"				
			}
			flagerr=1;
	}
	if(document.frmAddCommunity.txt_contact_email.value=="Enter e-mail" || document.frmAddCommunity.txt_contact_email.value=="")
	{
			if(document.frmAddCommunity.txt_contact_email.value!="")
			{
				errstr = errstr + "Incorrect email.\n"
			}
			else
			{
				errstr = errstr + "Please enter contact email.\n"				
			}
			flagerr=1;
	}
	if(document.frmAddCommunity.txt_password1.value!="")
	{
			if(document.frmAddCommunity.txt_password1.value!="" && document.frmAddCommunity.txt_password1.value!=document.frmAddCommunity.txt_password2.value)
			{
				errstr = errstr + "Incorrect Password"
				flagerr=1;
			}
	}
	else
	{
			errstr = errstr + "Please enter password.\n"				
			flagerr=1;
	}
	if(flagerr==1)
	{
			alert(errstr);
			return false;
	}
	else
	{
		document.frmAddCommunity.submit();
	}
	
}

function edit(mess, docs,commId,community_name,street_add1,street_add2,city,state,zip,contact_name,last_name,contact_phone,contact_email,AdvertiseOn,PM,status,keywords,comm_photo,commam)
{
	
	document.frmAddCommunity.hdnCommId.value=commId;
	document.frmAddCommunity.txt_community_name.value=community_name;
	document.frmAddCommunity.txt_street_add1.value=street_add1;
	document.frmAddCommunity.txt_street_add2.value=street_add2;
	document.frmAddCommunity.txt_city.value=city;	
	
	for(i=0;i<document.frmAddCommunity.cb_state.options.length;i++)
	{
		if(document.frmAddCommunity.cb_state.options[i].text==state)
		{
			document.frmAddCommunity.cb_state.options[i].selected=true;
		}
	}
	document.frmAddCommunity.txt_zip.value=zip;
	document.frmAddCommunity.txt_contact_name.value=contact_name;
	document.frmAddCommunity.txtlastname.value=last_name;
	document.frmAddCommunity.txt_contact_phone.value=contact_phone;
	document.frmAddCommunity.txt_contact_email.value=contact_email;
	
	if(document.frmAddCommunity.chkAdvertiseOn.value==AdvertiseOn)
	{
		document.frmAddCommunity.chkAdvertiseOn.checked=true;
	}
	else
	{
		document.frmAddCommunity.chkAdvertiseOn.checked=false;
	}
	
	if(document.frmAddCommunity.chkPM.value==PM)
	{
		document.frmAddCommunity.chkPM.checked=true;
	}
	else
	{
		document.frmAddCommunity.chkPM.checked=false;
	}
	
	if(document.frmAddCommunity.chkDOCS.value==docs)
	{
		document.frmAddCommunity.chkDOCS.checked=true;
	}
	else
	{
		document.frmAddCommunity.chkDOCS.checked=false;
	}
	
	if(document.frmAddCommunity.chkMES.value==mess)
	{
		document.frmAddCommunity.chkMES.checked=true;
	}
	else
	{
		document.frmAddCommunity.chkMES.checked=false;
	}

	for(i=0;i<document.frmAddCommunity.rdo_status.length;i++)
	{
		if(document.frmAddCommunity.rdo_status[i].value==status)
		{
			document.frmAddCommunity.rdo_status[i].checked=true;
			break;
		}
	}
	
	document.frmAddCommunity.txt_keywords.value=keywords;
	if(comm_photo!='' && comm_photo!='.')
	{
		document.getElementById('cpto').innerHTML='(<a href="../admin/files/'+comm_photo+'" target="_blank">'+comm_photo+'</a>)';
		document.getElementById('remp').innerHTML='<a href="?at=cd&rem=1&cid='+commId+'">Remove this photo and use default</a>';
	}
	if(comm_photo=='' || comm_photo=='.')
	{
		document.getElementById('cpto').innerHTML='(<a href="../images/dreamstime_859711.jpg" target="_blank">default.jpg</a>)';
		document.getElementById('remp').innerHTML='';
	}
	/*msg=""
	a=document.getElementById("community_photo");
	for(x in a)
	{
		msg+=x+"\n";
	}
	alert(msg+"\n"+comm_photo);*/
	if(commam!=0)
	{
		document.getElementById('amass').innerHTML="<b>"+commam+"</b>";
	}
	else
	{
		document.getElementById('amass').innerHTML="<b>No AM assigned</b>";	
	}

}

function newData()
{
	document.frmAddCommunity.hdnCommId.value=""
	document.frmAddCommunity.txt_community_name.value="";
	document.frmAddCommunity.txt_street_add1.value="";
	document.frmAddCommunity.txt_street_add2.value="";
	document.frmAddCommunity.txt_city.value="";
	document.frmAddCommunity.cb_state.options[0].selected=true;
	document.frmAddCommunity.txt_zip.value="";
	document.frmAddCommunity.txt_contact_name.value="";
	document.frmAddCommunity.txt_contact_phone.value="";
	document.frmAddCommunity.txt_contact_email.value="";
	document.frmAddCommunity.txt_keywords.value="";	
	document.frmAddCommunity.chkAdvertiseOn.checked=false;
	document.frmAddCommunity.chkPM.checked=false;

	for(i=0;i<document.frmAddCommunity.rdo_status.length;i++)
	{
		if(document.frmAddCommunity.rdo_status[i].value=="Active")
		{
			document.frmAddCommunity.rdo_status[i].checked=true;
			break;
		}
	}
}


function doValidate2()
{
	var errstr = "";
	var flagerr =0;
	if(document.frmAddCommunity.txt_community_name.value=="Community name goes here" || document.frmAddCommunity.txt_community_name.value=="")
	{
			if(document.frmAddCommunity.txt_community_name.value!="")
			{
				errstr = errstr + "Incorrect community name.\n"
			}
			else
			{
				errstr = errstr + "Please enter community name.\n"
			}
			flagerr=1;
	}
	if(document.frmAddCommunity.txt_community_name.value!="" && document.frmAddCommunity.txt_community_name.value.length >=100)
	{
			errstr = errstr + "Community name can be 100 characters long. Please re-enter the community name.\n"
			flagerr=1;
	}
	if(document.frmAddCommunity.txt_street_add1.value=="Community address goes here" || document.frmAddCommunity.txt_street_add1.value=="")
	{
			if(document.frmAddCommunity.txt_street_add1.value!="")
			{
				errstr = errstr + "Incorrect street address.\n"
			}
			else
			{
				errstr = errstr + "Please enter street address.\n"
			}
			flagerr=1;
	}
	if(document.frmAddCommunity.txt_city.value=="City" || document.frmAddCommunity.txt_city.value=="")
	{
			if(document.frmAddCommunity.txt_city.value!="")
			{
				errstr = errstr + "Incorrect city.\n"
			}
			else
			{
				errstr = errstr + "Please enter city.\n"
			}
			flagerr=1;
	}
	if(document.frmAddCommunity.cb_state[document.frmAddCommunity.cb_state.selectedIndex].text=="Select")
	{
			errstr = errstr + "Please select state.\n"
			flagerr=1;
	}
	if(document.frmAddCommunity.txt_zip.value=="")
	{
			errstr = errstr + "Please enter zipcode.\n"
			flagerr=1;
	}
	if (document.frmAddCommunity.community_photo.value!="")
	{
		var lo=document.frmAddCommunity.community_photo.value
		var flo=lo.split("\\")
		var len=flo.length
		var nm=flo[len-1]
		var xt=nm.split(".")
		var xtlen=xt.length
		var ext = xt[xtlen-1];
			if(ext!="jpg" && ext!="gif" && ext!="png" && ext!="JPG" && ext!="GIF" && ext!="PNG")
			{
				errstr = errstr + "Please upload jpg,gif or png photo.\n"
				flagerr=1;
			}
	}
	if(document.frmAddCommunity.txt_contact_name.value=="Enter full name of contact person" || document.frmAddCommunity.txt_contact_name.value=="")
	{
			if(document.frmAddCommunity.txt_contact_name.value!="")
			{
				errstr = errstr + "Incorrect contact name.\n"
			}
			else
			{
				errstr = errstr + "Please enter contact name.\n"				
			}
			flagerr=1;
	}
	if(document.frmAddCommunity.txt_contact_email.value=="Enter Text" || document.frmAddCommunity.txt_contact_email.value=="")
	{
			if(document.frmAddCommunity.txt_contact_email.value!="")
			{
				errstr = errstr + "Incorrect email.\n"
			}
			else
			{
				errstr = errstr + "Please enter contact email.\n"				
			}
			flagerr=1;
	}
	if(flagerr==1)
	{
			alert(errstr);
			return false;
	}
	else
	{
		document.frmAddCommunity.submit();
	}
	
}
