//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(usernamehiddencheck.value==0)
				{
					alert("The Username has been Taken : Please enter another Username");
					txtUserName.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;
				}else if(flag==0)
				{
						if(txtPassword.value=="")
						{
							alert("Please Enter the Password");
							txtPassword.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 Breif Description");
					BriefDescription.focus();
					return false;
				}else if(txtImage.value.length>5)
				{
						if(ImagePositionID.value==-1)
						{
							alert("Please Select the Image Position");
							ImagePositionID.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)
	{		
				
				if (txtWebsiteTitle.value=="")
				{
					alert("Please Enter the Website Title");
					txtWebsiteTitle.focus();
					return false;
				}else if (txtEnquiryEmail.value=="")
				{
					alert("Please Enter the Enquiry Email Address(es)");
					txtEnquiryEmail.focus();
					return false;
				}else if (txtCareerEmail.value=="")
				{
					alert("Please Enter the Career Email Address(es)");
					txtCareerEmail.focus();
					return false;
				}else if(txtMainHeadline.value=="")
				{
					alert("Please Enter the Head Line Message");
					txtMainHeadline.focus();
					return false;
				}
				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 Resources

function ValidateResources()
{
		with(document.formobject)
		{
				if(Sequence.value=="")
				{
					alert("Please Enter the Sequence");
					Sequence.focus();
					return false;
				}else if(actionflag==0)
				{
					if(SupportingFile.value.length<5)
					{
						alert("Please upload the File");
						SupportingFile.focus();
						return false;
					}
				}
				ValidateResourcesflag.value="true";
		}
}


//Validating Enquiry Form

function ValidateEnquiryForm()
{
		with(document.formobject)
		{
				if (txtName.value=="")
				{
					alert("Please Enter the Name");
					txtName.focus();
					return false;
				}else if (txtEmail.value=="")
				{
					alert("Please enter the Email Address");
					txtEmail.focus();
					return false;
				}else if(!(isEmail(txtEmail.value)))
				{
					alert("Please Enter a valid Email (abc@abc.com)");
					txtEmail.focus();
					return false;
				}else if(description.value=="")
				{
					alert("How we can help you?");
					description.focus();
					return false;
				}
				enquiryflag.value="true";
		}
		return true;
}

//Validate Post

function ValidatePost()
{
		with(document.formobject)
		{		
				if (CategoryID.value==-1)
				{
					alert("Please Select the Blog Category");
					CategoryID.focus();
					return false;
				}else if (CategoryID.value==-2)
				{
					if(NewCategory.value=="")
					{
						alert("Please Enter the New Suggested Category");
						NewCategory.focus();
						return false;
					}
				}else if (PostTitle.value=="")
				{
					alert("Please Enter the Post Title");
					PostTitle.focus();
					return false;
				}else if((PostedBy.value=="") && (AuthorID.value==0))
				{
					alert("Please select a Author or Enter the Posted By Field");
					PostedBy.focus();
					return false;
				}else if(PostDate.value=="")
				{
					alert("Please Enter the Date");
					PostDate.focus();
					return false;
				}else if(!(isDate(PostDate.value)))
				{
					alert("Please Enter the Date in the correct format (yyyy-mm-dd)");
					PostDate.focus();
					return false;
				}
				ValidatePostflag.value="true";
		}
		return true;	
}

//Validate Comment
function ValidateClientComment()
{
		with(document.commentform)
		{		
				if (txtName.value=="")
				{
					alert("Please Enter the 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(cmsdescription.value=="")
				{
					alert("Please Enter the Comments");
					cmsdescription.focus();
					return false;
				}
				ValidateClientCommentflag.value="true";
		}
		return true;	
}

//Validate Admin Comments
function ValidateAdminClientComment()
{
		with(document.commentform)
		{		
				if (txtName.value=="")
				{
					alert("Please Enter the 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;
				}
				ValidateClientCommentflag.value="true";
		}
		return true;	
}


function ChangeDisplay(actiontype)
{
	if(actiontype==1)
	{
		//Write A Comment
		if(document.getElementById("commentformdiv").style.display=="none")
		{
			document.getElementById("commentformdiv").style.display="block";	
		}else if(document.getElementById("commentformdiv").style.display=="block")
		{
			document.getElementById("commentformdiv").style.display="none";	
		}
	}else
	{
		//view comments	
		if(document.getElementById("commentsmaindiv").style.display=="none")
		{
			document.getElementById("commentsmaindiv").style.display="block";
			document.getElementById("commentformdiv").style.display="block";
		}else if(document.getElementById("commentsmaindiv").style.display=="block")
		{
			document.getElementById("commentsmaindiv").style.display="none";
			document.getElementById("commentformdiv").style.display="none";
		}
	}
}

//Change Display

function ChangeMainListing(section,flag)
{
	if(section=='new')
	{
		document.getElementById("inactivenew").style.display="none";	
		document.getElementById("activenew").style.display="block";	
		document.getElementById("inactivert").style.display="block";	
		document.getElementById("activert").style.display="none";	
		document.getElementById("newslisting").style.display="block";
		document.getElementById("roundtablelisting").style.display="none";
	}else if(section=='rt')
	{
		document.getElementById("inactivenew").style.display="block";	
		document.getElementById("activenew").style.display="none";	
		document.getElementById("inactivert").style.display="none";	
		document.getElementById("activert").style.display="block";	
		document.getElementById("newslisting").style.display="none";
		document.getElementById("roundtablelisting").style.display="block";
	}
}





//Blog Enhancement Scripts

function ValidateRegistrationProcess()
{
		with(document.registerform)
		{
				if(txtFirstName.value=="")
				{
					alert("Please Enter your First Name");
					txtFirstName.focus();
					return false;
				}else if(txtLastName.value=="")
				{
					alert("Please Enter your Last Name");
					txtLastName.focus();
					return false;
				}else if (txtEmail.value=="")
				{
					alert("Please enter the Email Address");
					txtEmail.focus();
					return false;
				}else if(!(isEmail(txtEmail.value)))
				{
					alert("Please Enter a valid Email (abc@abc.com)");
					txtEmail.focus();
					return false;
				}else if(usernamehiddencheck.value==0)
				{
					alert("The Email is already registered with us - Please enter another Email Address");
					txtEmail.focus();
					return false;
				}else if(txtPassword.value=="")
				{
					alert("Please Enter your password");
					txtPassword.focus();
					return false;
				}else if(txtConfirmPassword.value=="")
				{
					alert("Please Enter confirm your password");
					txtConfirmPassword.focus();
					return false;
				}else if(txtPassword.value!=txtConfirmPassword.value)
				{
					alert("Password doesnt Match , Please Re-enter the password");
					txtPassword.value="";
					txtConfirmPassword.value="";
					txtPassword.focus();
					return false;
				}else if(Country.value==-1)
				{
					alert("Please Select your Country of Residence");
					Country.focus();
					return false;
				}else if(Source.value==-1)
				{
					alert("Where did you hear about us?");
					Source.focus();
					return false;
				}
				ValidateRegistrationProcessflag.value="true";
		}
		return true;
}


//Ajax Function for Checking Email

function checkEmail()
{
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null)
		{
			alert ("Your browser does not support AJAX!");
			return false;
		}
		with(document.registerform)
		{
			if (txtEmail.value=="")
			{
				alert("Please enter the Email Address");
				txtEmail.focus();
				return false;
			}else if(!(isEmail(txtEmail.value)))
			{
				alert("Please Enter a valid Email (abc@abc.com)");
				txtEmail.focus();
				return false;
			}
			Email=txtEmail.value;	 
		}
		
		var url='checkEmail.php';
		url=url+"?Email="+Email;		
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=CheckEmailStateChanged;
		xmlHttp.open("GET",url,true);		
		xmlHttp.send(null);
		return false;
}

function CheckEmailStateChanged() 
{ 
		if (xmlHttp.readyState==4)
		{ 	
				var result=xmlHttp.responseText;
				var resultarray=result.split("----------!!!!!!________RSI_________!!!!!!!!--------");
				if(resultarray[1]==1)
				{
					document.registerform.usernamehiddencheck.value=1;
				}else
				{
					document.getElementById("usernamecheck").innerHTML="Email already registered";
					document.registerform.usernamehiddencheck.value=0;
				}
		}
}

//Validate Blog User

function ValidateBlogUser()
{
		with(document.formobject)
		{
				if(txtFirstName.value=="")
				{
					alert("Please Enter your First Name");
					txtFirstName.focus();
					return false;
				}else if(txtLastName.value=="")
				{
					alert("Please Enter your Last Name");
					txtLastName.focus();
					return false;
				}else if(Country.value==-1)
				{
					alert("Please Select your Country of Residence");
					Country.focus();
					return false;
				}else if(Source.value==-1)
				{
					alert("Where did you hear about us?");
					Source.focus();
					return false;
				}
				ValidateBlogUserflag.value="true";
		}
		return true;
}

//Validate Blog User Login
function ValidateBlogUserLogin()
{
		with(document.userloginform)
		{		
				if (txtEmail.value=="")
				{
					alert("Please Enter the Email");
					txtEmail.focus();
					return false;
				}else if(txtPassword.value=="")
				{
					alert("Please Enter the Password");
					txtPassword.focus();
					return false;
				}
				userloginformflag.value="true";
		}
	return true;
}

//Validate User Articles

function ValidateBlogArticle()
{
		with(document.articleform)
		{		
				if(CategoryID.value==-1)
				{
					alert("Please Select the Blog Category");
					CategoryID.focus();
					return false;
				}else if (CategoryID.value==-2)
				{
					if(NewCategory.value=="")
					{
						alert("Please Enter the New Suggested Category");
						NewCategory.focus();
						return false;
					}
				}else if (PostTitle.value=="")
				{
					alert("Please Enter the Post Title");
					PostTitle.focus();
					return false;
				}
				ValidateBlogArticleflag.value="true";
		}
		return true;	
}

//Validate Forgot Password

function ValidateForgotPassword()
{
		with(document.formobject)
		{		
				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;
				}
				ValidateForgotPasswordflag.value="true";
		}
		return true;	
}


//Validate Bod

function ValidateBod()
{
		with(document.formobject)
		{		
				if (Name.value=="")
				{
					alert("Please Enter the Name");
					Name.focus();
					return false;
				}else if(Designation.value=="")
				{
					alert("Please Enter the Designation");
					Designation.focus();
					return false;
				}
				ValidateBodflag.value="true";
		}
	return true;	
}

//Suggest New Category Box

function LoadNewCategoryBox()
{
		with(document.articleform)
		{
			if(CategoryID.value==-2)
			{
				document.getElementById("newcategory").style.display="";	
			}else
			{
				document.getElementById("newcategory").style.display="none";	
			}
		}
	return true;	
}

function ValidateBannerCategory()
{
		with(document.formobject)
		{		
				if(CategoryName.value=="")
				{
					alert("Please Enter the Category Name");
					CategoryName.focus();
					return false;
				}else if(URL.value=="")
				{
					alert("Please Enter the URL");
					URL.focus();
					return false;
				}else if(Effect.value==-1)
				{
					alert("Please Select the Effect");
					Effect.focus();
					return false;
				}
				ValidateBannerCategoryflag.value="true";
		}
	return true;	
}

//Update Information
function UpdateInformation()
{
	with(document.formobject)
	{		
			UpdateInformationFlag.value="true";
	}
	document.formobject.submit();
}

//Update Sequence
function UpdateSequence()
{
	with(document.formobject)
	{		
			updatesequenceflag.value="true";
	}
	document.formobject.submit();
}

function ValidateUrls()
{
		with(document.formobject)
		{		
				if(Title.value=="")
				{
					alert("Please Enter the Title");
					Title.focus();
					return false;
				}else if(Url.value=="")
				{
					alert("Please Enter the Url");
					Url.focus();
					return false;
				}
		
				ValidateUrlsflag.value="true";
		}
}

function ValidateArticles()
{
		with(document.formobject)
		{		
				if(Title.value=="")
				{
					alert("Please Enter the Title");
					Title.focus();
					return false;
				}else if(PageID.value==-1)
				{
					alert("Please Select the Page");
					PageID.focus();
					return false;
				}else if(TargetID.value==-1)
				{
					alert("Please Select the Target");
					TargetID.focus();
					return false;
				}
		
				ValidateArticlesflag.value="true";
		}
}

	


