//Validating Login Details
function validateLoginDetails()
{
		with(document.formobject)
		{		
				if (txtUserName.value=="")
				{
					alert("Please Enter the Username");
					txtUserName.focus();
					return false;
				}else if(txtPassword.value=="")
				{
					alert("Please Enter the Password");
					txtPassword.focus();
					return false;
				}
				eventflag.value="true";
		}
	return true;
}


//Validating User Group
function ValidateUserGroup()
{
		with(document.formobject)
		{		
				if (txtGroupName.value=="")
				{
					alert("Please Enter the Group Name");
					txtGroupName.focus();
					return false;
				}
				ValidateUserGroupeventflag.value="true";
		}
	return true;
}

//Validating Group Permissions
function ValidateGrouPermissions()
{
		with(document.formobject)
		{		
				ValidateGrouPermissionsflag.value="true";
		}
	return true;
}



//Checking User Name
function checkUserName()
{
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null)
		{
			alert ("Your browser does not support AJAX!");
			return false;
		}
		username=document.formobject.txtUserName.value;	 
		var url='CheckUserName.php';
		url=url+"?username="+username;		
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);		
		xmlHttp.send(null);
		return false;
	
}

function stateChanged() 
{ 
		if(xmlHttp.readyState==4)
		{ 	
				var result=xmlHttp.responseText;
				var resultarray=result.split("----------!!!!!!________RSI_________!!!!!!!!--------");
				if(resultarray[1]==1)
				{
					document.getElementById("usernamecheck").innerHTML="Username Available";
					document.formobject.usernamehiddencheck.value=1;
				}else
				{
					document.getElementById("usernamecheck").innerHTML="Username Unavailable";
					document.formobject.usernamehiddencheck.value=0;
				}
		}
}
//Ajax Main Function
function GetXmlHttpObject()
{
		var xmlHttp=null;
		try
		{
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		}
		catch (e)
		{
		// Internet Explorer
			try
			{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
		return xmlHttp;
}
//Validating System Users
function ValidateSystemUser(flag)
{
		with(document.formobject)
		{		
				if (GroupID.value==-1)
				{
					alert("Please Select the User Group");
					GroupID.focus();
					return false;
				}else if (txtUserName.value=="")
				{
					alert("Please Enter the User Name");
					txtUserName.focus();
					return false;
				}else if((flag==0) && (txtPassword.value==""))
				{
					alert("Please Enter the Password");
					txtPassword.focus();
					return false;
				}else if(txtFirstName.value=="")
				{
					alert("Please Enter the First Name");
					txtFirstName.focus();
					return false;
				}else if(txtLastName.value=="")
				{
					alert("Please Enter the Last Name");
					txtLastName.focus();
					return false;
				}else if(Gender.value==-1)
				{
					alert("Please Select the Gender");
					Gender.focus();
					return false;
				}else if(txtEmail.value=="")
				{
					alert("Please Enter the Email");
					txtEmail.focus();
					return false;
				}else if(!(isEmail(txtEmail.value)))
				{
					alert("Please Enter the Email (abc@abc.com)");
					txtEmail.focus();
					return false;
				}else if(AccountStatus.value==-1)
				{
					alert("Please Select the Account Status");
					AccountStatus.focus();
					return false;
				}
				ValidateSystemUserflag.value="true";
		}
	return true;	
}

//Validating User Permissions

function ValidateUserPermissions()
{
		with(document.formobject)
		{		
				ValidateUserPermissionsflag.value="true";
		}
	return true;
}


//Validating CMS

function ValidateCmsPage()
{
		with(document.formobject)
		{		
				if (MasterLinkID.value==-1)
				{
					alert("Please Select the Master Link");
					MasterLinkID.focus();
					return false;
				}else if (txtLinkTitle.value=="")
				{
					alert("Please Enter the Link Title");
					txtLinkTitle.focus();
					return false;
				}else if(txtPageTitle.value=="")
				{
					alert("Please Enter the Page Title");
					txtPageTitle.focus();
					return false;
				}else if(Sequence.value=="")
				{
					alert("Please Enter the Page Sequence");
					Sequence.focus();
					return false;
				}else if(txtImage.value.length>5)
				{
						if(ImagePositionID.value==-1)
						{
							alert("Please Select the Image Position");
							ImagePositionID.focus();
							return false;
						}
				}
				ValidateCmsPageflag.value="true";
		}
	return true;	
}

//Validating News Articles

function ValidateNews()
{
		with(document.formobject)
		{		
				if (txtNewsTitle.value=="")
				{
					alert("Please Enter the News Title");
					txtNewsTitle.focus();
					return false;
				}else if(BriefDescription.value=="")
				{
					alert("Please Enter the Head Line");
					BriefDescription.focus();
					return false;
				}else if(txtArticleDate.value=="")
				{
					alert("Please Enter the Article Date");
					txtArticleDate.focus();
					return false;
				}
				ValidateNewsflag.value="true";
		}
	return true;	
}

//Validating Uploads

function ValidateUploads()
{
		with(document.formobject)
		{		
				ValidateUploadsflag.value="true";
		}
	return true;		
}



//Validating CMS Data
function validateotherdata()
{
	with(document.formobject)
	{		
				otherdataflag.value="true";
	}
	return true;	
}

//Loading Other CMS Data
function loadcmscontents()
{
	document.formobject.submit();
}

//Validating Website Configuration

function ValidateWebsiteConfiguration()
{
	with(document.formobject)
	{		
				ValidateWebsiteConfigurationflag.value="true";
	}
	return true;	
}

//Validating Change Password
function ValidateChangePassword()
{
		with(document.formobject)
		{
					if(txtOldPassword.value=="")
					{
							alert("Please Enter the Old Password");
							txtOldPassword.focus();
							return false;
					}else if(txtNewPassword.value.length<8)
					{
							alert("Please Enter the New Password(Minimum 8 Characters)");
							txtNewPassword.focus();
							return false;
					}else if(txtNewPassword.value!=txtConfirmPassword.value)
					{
							alert("New Password doesnt Match , Please reconfirm");
							txtNewPassword.focus();
							return false;
					}
				
				ValidateChangePasswordflag.value="true";
	}
	return true;	
}



//Validate Product Categories
function ValidateProductCategory()
{
		with(document.formobject)
		{		
				if (Title.value=="")
				{
					alert("Please Enter the Category name");
					Title.focus();
					return false;
				}
				ValidateProductCategoryflag.value="true";
		}
	return true;	
}

//Validate Product
function ValidateProducts()
{
		with(document.formobject)
		{		
				if (CategoryID.value==-1)
				{
					alert("Please Select Product Category");
					CategoryID.focus();
					return false;
				}else if (txtProductTitle.value=="")
				{
					alert("Please Enter the Product Title");
					txtProductTitle.focus();
					return false;
				}else if (BreifDescription.value=="")
				{
					alert("Please Enter the Breif Description");
					BreifDescription.focus();
					return false;
				}
				ValidateProductsflag.value="true";
		}
	return true;	
}

//Validating Contact Us Form
function ValidateContactUs()
{
		with(document.ContactUsForm)
		{		
				if (txtName.value=="")
				{
					alert("Please Enter your Name");
					txtName.focus();
					return false;
				}else if(txtEmail.value=="")
				{
					alert("Please Enter the Email");
					txtEmail.focus();
					return false;
				}else if(!(isEmail(txtEmail.value)))
				{
					alert("Please Enter the Email (abc@abc.com)");
					txtEmail.focus();
					return false;
				}else if(inquiry.value=="")
				{
					alert("Please Enter the your Inquiry Details");
					inquiry.focus();
					return false;
				}
				contactusformflag.value="true";
		}
	return true;	
}

function ValidateProductOverviews()
{
		with(document.formobject)
		{		
				if (LinkTitle.value=="")
				{
					alert("Please Enter the Product Overview");
					LinkTitle.focus();
					return false;
				}else if(MetaTitle.value=="")
				{
					alert("Please Enter the Meta Title");
					MetaTitle.focus();
					return false;
				}
				ValidateProductOverviewsflag.value="true";
		}
	return true;	
	
}