// JavaScript Document for True FM site

//------------  function used in index.php   --------------------//
function usernamefocus()
{
	document.frmLogin.txtUsername.value="";
	document.frmLogin.txtPassword.value="";
	document.frmLogin.cmbWebsite.value="0";
	document.frmLogin.txtUsername.focus();
}


//------------end   function used in index.php   --------------------//
var email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/;
//-----------Dynamic paging, page moves ----------//


//------------  function used in index.php   --------------------//
function validateLogin(formName)
{
	frm1=eval("document."+formName);
	
	if(trim(frm1.txtUsername.value).length<1)
	{
		alert("Please enter username.");
		frm1.txtUsername.focus();
		return false;
	}
	else if(trim(frm1.txtPassword.value).length<1)
	{
		alert("Please enter password.");	
		frm1.txtPassword.focus();
		return false;
	}
	else
	{
		frm1.action="index1.php";
		frm1.submit();
	}
}


function funSubmit(formName,e)
{
	if(e.keyCode==13)
	{
		frm1=eval("document."+formName);
		if(trim(frm1.txtUsername.value).length<1)
		{
			alert("Please enter username.");
			frm1.txtUsername.focus();
			return false;
		}
		else if(trim(frm1.txtPassword.value).length<1)
		{
			alert("Please enter password.");	
			frm1.txtPassword.focus();
			return false;
		}
		else
		{
			frm1.action="index1.php";
			frm1.submit();
		}		
	}
}
//------------ end function used in index.php   --------------------//

//------------  function used in Profile.php   --------------------//
 
function validateProfile()
{
	if(trim(document.frmAdminProfile.txtUsername.value)=="")
	{
		alert("Please enter username.");
		document.frmAdminProfile.txtUsername.focus();
		return false;
	}
	else if(trim(document.frmAdminProfile.txtPassword.value)=="")
	{
		alert("Please enter password.");
		document.frmAdminProfile.txtPassword.focus();
		return false;
	}
	else if(trim(document.frmAdminProfile.txtCPassword.value)=="")
	{
		alert("Please re-type password.");
		document.frmAdminProfile.txtCPassword.focus();
		return false;
	}
	else if(trim(document.frmAdminProfile.txtPassword.value)!=trim(document.frmAdminProfile.txtCPassword.value))
	{
		alert("Password mismatch.");
		document.frmAdminProfile.txtPassword.focus();
		return false;
	}
	else if(trim(document.frmAdminProfile.txtEmail.value)=="")
	{
		alert("Please enter email address.");
		document.frmAdminProfile.txtEmail.focus();
		return false;
	}
	else if(!email.test(document.frmAdminProfile.txtEmail.value))
	{
		alert("Invalid email address.");
		document.frmAdminProfile.txtEmail.focus();
		return false;
	}
	else
	{
		document.frmAdminProfile.action="profile.php";
		document.frmAdminProfile.submit();
	}
}

//------------end  function used in Profile.php   --------------------//



//------------  function used in pagecontent.php   --------------------//

function funAddPage(act)
{
	if(act==0)// act=0 add page
	{
		if(trim(document.frmPage.txtPageName.value)=="")
		{
			alert("Please enter Subpage/Page Name");
			document.frmPage.txtPageName.focus();
			document.frmPage.txtPageName.value="";
			return false;
		}
		if(trim(document.frmPage.cmbPriority.value)==0)
		{
			alert("Please enter Priority.");
			document.frmPage.cmbPriority.select();
		
			return false;
		}

		document.frmPage.action="page1.php?act="+act;
		document.frmPage.submit();
			
	}
	
	if(act==1) //edit page
	{		
		if(trim(document.frmPage.txtPageName.value)=="")
		{
			alert("Please enter the new Category Name.");
			document.frmPage.txtPageName.focus();
			document.frmPage.txtPageName.value="";
			return false;
		}
		document.frmPage.action="page1.php?act="+act;
		document.frmPage.submit();
	}
	
	if(act==2) //delete page
	{		
		if(confirm("Are you sure you want to delete?"))
		{
			document.frmPage.action="page1.php?act="+act;
			document.frmPage.submit();
		}		
	}

}

//------------end  function used in pagecontent.php   --------------------//




//------------  function used in addPageContent.php   --------------------//
function funAddContent(action)
{
document.frmEditContent.action='addcontent1.php?act='+action;	
document.frmEditContent.submit();

}
//------------end  function used in addPageContent.php   --------------------//

//------------  function used for deleting records   --------------------//

function Del()
{
	if(confirm("Are you sure you want to delete this record?"))
	return true;
	else
	return false;			
}

//------------ end function used for deleting records   --------------------//

//------------  function used in addNews.php   --------------------//

function funAddNews(act)
{
	if(trim(document.frmAddNews.txtNewsTitle.value)=='')
	{
		alert('Please enter news title.');	
		document.frmAddNews.txtNewsTitle.focus();
		return false;
	}
	if(trim(document.frmAddNews.txtNewsContent.value)=='')
	{
		alert('Please enter news content.');	
		document.frmAddNews.txtNewsContent.focus();
		return false;
	}
	document.frmAddNews.action="news1.php?act="+act;
	document.frmAddNews.submit();		
}

//------------end  function used in addNews.php   --------------------//

//------------  function used in addHomeContent.php   --------------------//

function updateContent()
{
	document.frmAddContent.action="homecontent1.php";
	document.frmAddContent.submit();	
}
//function used in news manager.php
function newsManagerLinkList(url,pg,index,type,so)
{
	var url  = url+"?pg="+pg+"&index="+index+"&type="+type+"&so="+so;
	passvalue(url);
}
//function used in addNews.php
function validateNews()
{
	if(trim(document.frmAddNews.txtNewsTitle.value).length==0)
	{
	alert("Please enter news title.");
	document.frmAddNews.txtNewsTitle.focus();
	return false;
	}
	var fckval =FCKeditorAPI.__Instances['txtNewsContent'].GetHTML();
	if(fckval=="")
	{
	alert("Please enter news content.");
	FCKeditorAPI.__Instances['txtNewsContent'].Focus();
	return false;
	}
	document.frmAddNews.action="addNews.php";
	document.frmAddNews.submit();
}

//Function used in settings.php & addContent.php
function validateContent(formname,fieldname,actionpage,message)
{
	var frmname=eval("document."+formname);
	var fckval =FCKeditorAPI.__Instances[fieldname].GetHTML();
	if(fckval=="")
	{
	alert("Please enter "+message+" content.");
	FCKeditorAPI.__Instances[fieldname].Focus();
	return false;
	}
	
	
	if(message=="page")
	frmname.action=actionpage+".php?act="+frmname.hidact.value+"&pid="+frmname.hidpageId.value;
	else
	frmname.action=actionpage+".php";
	frmname.submit();
}


//Function used in contentmanager.php

function funAddPage(act)
{

	if(act==0)// act=0 add page
	{
		if(trim(document.frmPage.myvar1.value)=="0")
		{
		alert("To add a new page please click on the 'Add Pages' on the top");
		return false;
		}
		else
		{
			if(trim(document.frmPage.txtPageName.value)=="")
			{
				alert("Please enter Subpage/Page Name");
				document.frmPage.txtPageName.focus();
				document.frmPage.txtPageName.value="";
				return false;
			}
			
			if(trim(document.frmPage.cmbPriority.value)==0)
			{
				alert("Please select priority.");
				document.frmPage.cmbPriority.select();
				return false;
			}
		}
		
			
	}
	
	if(act==1) //edit page
	{		
		if(trim(document.frmPage.txtPageName.value)=="")
		{
			alert("Please enter the new page name.");
			document.frmPage.txtPageName.focus();
			document.frmPage.txtPageName.value="";
			return false;
		}
		
	}
	
	
	if(act==2) //delete page
	{	
		var delpage;
		delpage="0";	
		if(confirm("Are you sure you want to delete?"))
		delpage="1";
				
	}
if(act==0 || act==1 || delpage=="1")
{
	document.frmPage.action="contentmanager1.php?act="+act;
	document.frmPage.submit();
}

}

//Function used in contentmanager.php
//--------------------------------------------------------------//

function funlistWebpart()
{
	document.frmPage.action='contentmanager.php?myact=1';	
	document.frmPage.submit();
}

//------------ end function used in addHomeContent.php   --------------------//


//Function used in client side in Contact form
function chkContactMail()
{
	if(trim(document.frmContact.txtFirstName.value)=="")
	{
	alert("Please enter first name.");
	document.frmContact.txtFirstName.focus();
	return false;
	}
	if(trim(document.frmContact.txtLastName.value)=="")
	{
	alert("Please enter last name.");
	document.frmContact.txtLastName.focus();
	return false;
	}
	if(trim(document.frmContact.txtEmail.value)=="")
	{
	alert("Please enter email address.");
	document.frmContact.txtEmail.focus();
	return false;
	}
	if(!email.test(trim(document.frmContact.txtEmail.value)) && trim(document.frmContact.txtEmail.value)!="")
	{
		alert("Invalid email address.");
		document.frmContact.txtEmail.focus();
		return false;
	}
	if(trim(document.frmContact.txtMessage.value)=="")
	{
	alert("Please enter message/queries.");
	document.frmContact.txtMessage.focus();
	return false;
	}
document.frmContact.action="contact.php?flag=1";
document.frmContact.submit();
}

//For validating rate content
function validateRateContent()
{
	if(trim(document.frmRates.txtRateContent.value)=="")
	{
	alert("Please enter mortgage rates.");
	document.frmRates.txtRateContent.focus();
	return false;
	}
	else
	return true;
}