//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 Uploads

function ValidateUploads()
{
		with(document.formobject)
		{		
				ValidateUploadsflag.value="true";
		}
	return true;		
}

//Validating Uploads

function ValidateDocuments()
{
		with(document.formobject)
		{		
				ValidateDocumentsflag.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;	
}


//Loading Controls on the Basis of Link Type selected
function loadcontrolsonLinkType()
{
		with(document.formobject)
		{		
			if(LinkType.value==1)
			{
				document.getElementById("trlinktitle").style.display="";
				document.getElementById("trpagetitle").style.display="none";
				document.getElementById("trdescription").style.display="none";
				document.getElementById("trimageposition").style.display="none";
				document.getElementById("tropeningphrase").style.display="none";
				document.getElementById("trtarget").style.display="none";
				document.getElementById("trurl").style.display="none";
				document.getElementById("trfile").style.display="none";
				document.getElementById("trpredefinedpage").style.display="none";
			}else if(LinkType.value==2)
			{
				document.getElementById("trlinktitle").style.display="";
				document.getElementById("trpagetitle").style.display="";
				document.getElementById("trdescription").style.display="";
				document.getElementById("trimageposition").style.display="";
				document.getElementById("trtarget").style.display="none";
				document.getElementById("trurl").style.display="none";
				document.getElementById("trfile").style.display="none";
				document.getElementById("trpredefinedpage").style.display="none";
				document.getElementById("tropeningphrase").style.display="";
			}else if(LinkType.value==3)
			{
				document.getElementById("trlinktitle").style.display="";
				document.getElementById("trpagetitle").style.display="none";
				document.getElementById("trdescription").style.display="none";
				document.getElementById("trimageposition").style.display="none";
				document.getElementById("trtarget").style.display="";
				document.getElementById("trurl").style.display="";
				document.getElementById("trfile").style.display="none";
				document.getElementById("trpredefinedpage").style.display="none";
				document.getElementById("tropeningphrase").style.display="none";
			}else if(LinkType.value==4)
			{
				document.getElementById("trlinktitle").style.display="";
				document.getElementById("trpagetitle").style.display="none";
				document.getElementById("trdescription").style.display="none";
				document.getElementById("trimageposition").style.display="none";
				document.getElementById("trtarget").style.display="none";
				document.getElementById("trurl").style.display="none";
				document.getElementById("trfile").style.display="";
				document.getElementById("trpredefinedpage").style.display="none";
				document.getElementById("tropeningphrase").style.display="none";
			}else if(LinkType.value==5)
			{
				document.getElementById("trlinktitle").style.display="";
				document.getElementById("trpagetitle").style.display="none";
				document.getElementById("trdescription").style.display="none";
				document.getElementById("trimageposition").style.display="none";
				document.getElementById("trtarget").style.display="none";
				document.getElementById("trurl").style.display="none";
				document.getElementById("trfile").style.display="none";
				document.getElementById("trpredefinedpage").style.display="";
				document.getElementById("tropeningphrase").style.display="none";
			}else if(LinkType.value==-1)
			{
				document.getElementById("trlinktitle").style.display="none";
				document.getElementById("trpagetitle").style.display="none";
				document.getElementById("trdescription").style.display="none";
				document.getElementById("trimageposition").style.display="none";
				document.getElementById("trtarget").style.display="none";
				document.getElementById("trurl").style.display="none";
				document.getElementById("trfile").style.display="none";
				document.getElementById("trpredefinedpage").style.display="none";
				document.getElementById("tropeningphrase").style.display="none";
				alert("Please Select the Link Type");
				LinkType.focus();
			}
		}
}

//Validate Sub Pages
function ValidateMasterPages()
{
		with(document.formobject)
		{		
			if(LinkType.value==1)
			{
				if(txtLinkTitle.value=="")
				{
						alert("Please Enter the Link Title");
						txtLinkTitle.focus();
						return false;
				}
			}else if(LinkType.value==2)
			{
				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(LinkType.value==3)
			{
				if(txtLinkTitle.value=="")
				{
						alert("Please Enter the Link Title");
						txtLinkTitle.focus();
						return false;
				}else if(TargetID.value==-1)
				{
						alert("Please enter the Target");
						TargetID.focus();
						return false;
				}else if(txtExternalLink.value=="")
				{
						alert("Please Enter the External Link (For Eg http://www.uaeusedcars.ae)");
						txtExternalLink.focus();
						return false;
				}
			}else if(LinkType.value==4)
			{
				if(txtLinkTitle.value=="")
				{
						alert("Please Enter the Link Title");
						txtLinkTitle.focus();
						return false;
				}else if(FileExists.value==0)
				{
						alert("Please attach a File");
						FileName.focus();
						return false;
				}
			}else if(LinkType.value==5)
			{
				if(txtLinkTitle.value=="")
				{
						alert("Please Enter the Link Title");
						txtLinkTitle.focus();
						return false;
				}else if(PredefinedPage.value==-1)
				{
						alert("Please select a Predefined Page");
						PredefinedPage.focus();
						return false;
				}
			}else if(LinkType.value==-1)
			{
				alert("Please Select the Link Type");
				LinkType.focus();
				return false;
			}
			ValidateMasterPagesflag.value="true";
		}
	return true;	
}

function LoadParentPages(SelectedValue)
{
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null)
		{
			alert ("Your browser does not support AJAX!");
			return false;
		}
		MasterPageID=document.formobject.MasterPageID.value;	 
		if(MasterPageID==-1)
		{
			alert("Please Select the MasterPage");
			return;
		}
		document.getElementById("tdsubpages").innerHTML='<img src=images/ajaxloader.gif>';
		var url='LoadParentPages.php';
		url=url+"?MasterPageID="+MasterPageID;	
		url=url+"&SelectedValue="+SelectedValue;	
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=LoadSubPagesStateChanged;
		xmlHttp.open("GET",url,true);		
		xmlHttp.send(null);
		return false;
	
}

function LoadSubPagesStateChanged() 
{ 
		if (xmlHttp.readyState==4)
		{ 	
				document.getElementById("tdsubpages").innerHTML=xmlHttp.responseText;
		}
}



//Validate Sub Pages
function ValidateSubPages()
{
		with(document.formobject)
		{		
			if(MasterPageID.value==-1)
			{
				alert("Please Select the Master Page");
				MasterPageID.focus();
				return false;
			}
			if(LinkType.value==1)
			{
				if(txtLinkTitle.value=="")
				{
						alert("Please Enter the Link Title");
						txtLinkTitle.focus();
						return false;
				}
			}else if(LinkType.value==2)
			{
				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(LinkType.value==3)
			{
				if(txtLinkTitle.value=="")
				{
						alert("Please Enter the Link Title");
						txtLinkTitle.focus();
						return false;
				}else if(TargetID.value==-1)
				{
						alert("Please enter the Target");
						TargetID.focus();
						return false;
				}else if(txtExternalLink.value=="")
				{
						alert("Please Enter the External Link (For Eg http://www.uaeusedcars.ae)");
						txtExternalLink.focus();
						return false;
				}
			}else if(LinkType.value==4)
			{
				if(txtLinkTitle.value=="")
				{
						alert("Please Enter the Link Title");
						txtLinkTitle.focus();
						return false;
				}else if(FileExists.value==0)
				{
						alert("Please attach a File");
						FileName.focus();
						return false;
				}
			}else if(LinkType.value==5)
			{
				if(txtLinkTitle.value=="")
				{
						alert("Please Enter the Link Title");
						txtLinkTitle.focus();
						return false;
				}else if(PredefinedPage.value==-1)
				{
						alert("Please select a Predefined Page");
						PredefinedPage.focus();
						return false;
				}
			}else if(LinkType.value==-1)
			{
				alert("Please Select the Link Type");
				LinkType.focus();
				return false;
			}
			ValidateSubPagesflag.value="true";
		}
	return true;	
}


//Update Information
function UpdateInformation()
{
	with(document.formobject)
	{		
			UpdateInformationFlag.value="true";
	}
	document.formobject.submit();
}

//Update Information
function UpdateDocumentInformation()
{
	with(document.formobject)
	{		
			UpdateDocumentInformationflag.value="true";
	}
	document.formobject.submit();
}




//Update Sequence
function UpdateSequence()
{
	with(document.formobject)
	{		
			updatesequenceflag.value="true";
	}
	document.formobject.submit();
}




//Validate Solution Category
function ValidateSolutionCategories()
{
		with(document.formobject)
		{		
				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;
				}
				ValidateSolutionCategoriesflag.value="true";
		}
	return true;	
}

//Validate Solutions
function ValidateSolutions()
{
		with(document.formobject)
		{		
				if (CategoryID.value==-1)
				{
					alert("Please Select the Category");
					CategoryID.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;
				}
				ValidateSolutionsflag.value="true";
		}
	return true;	
}

//Validate Service Category
function ValidateServiceCategories()
{
		with(document.formobject)
		{		
				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;
				}
				ValidateServiceCategoriesflag.value="true";
		}
	return true;	
}

//Validate Services
function ValidateServices()
{
		with(document.formobject)
		{		
				if (CategoryID.value==-1)
				{
					alert("Please Select the Category");
					CategoryID.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;
				}
				ValidateServicesflag.value="true";
		}
	return true;	
}


//Validate news

function ValidateNews()
{
		with(document.formobject)
		{		
				if(txtNewsTitle.value=="")
				{
					alert("Please Enter the News Title");
					txtNewsTitle.focus();
					return false;
				}
				ValidateNewsflag.value="true";
		}
	return true;	
}


//Loading File Controls
function LoadFileControls()
{
		with(document.formobject)
		{		
			if(FileType.value==1)
			{
				document.getElementById("trfile").style.display="none";
				document.getElementById("trwidth").style.display="";
				document.getElementById("trheight").style.display="";
			}else if(FileType.value==-1)
			{
				document.getElementById("trfile").style.display="none";
				document.getElementById("trwidth").style.display="none";
				document.getElementById("trheight").style.display="none";
				alert("Please Select the File Type");
				FileType.focus();
			}else
			{
				document.getElementById("trfile").style.display="";
				document.getElementById("trwidth").style.display="none";
				document.getElementById("trheight").style.display="none";
			}
		}
}
function ValidateFiles()
{
		with(document.formobject)
		{		
			if(FileType.value==-1)
			{
				alert("Please Select the File Type");
				FileType.focus();
				return false;
			}
			if(FileType.value==1)
			{
				if(txtTitle.value=="")
				{
						alert("Please Enter the File Title");
						txtTitle.focus();
						return false;
				}else if(Width.value=="")
				{
						alert("Please Enter the Width");
						Width.focus();
						return false;
				}else if(Height.value=="")
				{
						alert("Please Enter the Height");
						Height.focus();
						return false;
				} 
			}else if(FileType.value==-1)
			{
				alert("Please Select the Link Type");
				LinkType.focus();
				return false;
			}else
			{
				if(txtTitle.value=="")
				{
						alert("Please Enter the File Title");
						txtTitle.focus();
						return false;
				}else if((Trigger.value=="add") && (File.value.length<5))
				{
						alert("Please upload a File");
						return false;
				}
			}
			ValidateFilesflag.value="true";
		}
	return true;	
}

//Search Files

function SearchFiles()
{
		document.getElementById("searchresult").innerHTML='<img src=images/ajaxloader.gif>';
		with(document.formobject)
		{		
			KeywordValue=txtKeyword.value;
			FileTypeValue=FileType.value;
			PageTitleValue=PageTitle.value;
		}
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null)
		{
			alert ("Your browser does not support AJAX!");
			return false;
		}
		var url='SearchFiles.php';
		url=url+"?Keyword="+KeywordValue;	
		url=url+"&FileType="+FileTypeValue;	
		url=url+"&PageTitle="+PageTitleValue;	
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=SearchFilesStateChanged;
		xmlHttp.open("GET",url,true);		
		xmlHttp.send(null);
		return false;
}

function SearchFilesStateChanged() 
{ 
		if (xmlHttp.readyState==4)
		{ 	
				document.getElementById("searchresult").innerHTML=xmlHttp.responseText;
		}
}

//Validating Contact Us Form
function ValidateContactUs()
{
		with(document.contactusform)
		{		
				if (txtName.value=="")
				{
					alert("Please Enter your Name");
					txtName.focus();
					return false;
				}else if(txtTelephone.value=="")
				{
					alert("Please Enter your Contact Number");
					txtTelephone.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(txtSubject.value=="")
				{
					alert("Please Enter the Subject of this Inquiry");
					txtSubject.focus();
					return false;
				}else if(inquiry.value=="")
				{
					alert("Please Enter the inquiry Details");
					inquiry.focus();
					return false;
				}
				contactusformflag.value="true";
		}
	return true;	
}


//Validating Support Form
function ValidateSupportForm()
{
		with(document.SupportForm)
		{		
				if (txtName.value=="")
				{
					alert("Please Enter your Name");
					txtName.focus();
					return false;
				}else if (txtCompany.value=="")
				{
					alert("Please Enter your Company Name");
					txtCompany.focus();
					return false;
				}else if (txtContactPerson.value=="")
				{
					alert("Please Enter your Contact Person");
					txtContactPerson.focus();
					return false;
				}else if(txtTelephone.value=="")
				{
					alert("Please Enter your Contact Number");
					txtTelephone.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(txtProduct.value=="")
				{
					alert("Please Enter the Product Name for which you are seeking Support");
					txtProduct.focus();
					return false;
				}else if(inquiry.value=="")
				{
					alert("Please Enter the Details");
					inquiry.focus();
					return false;
				}
				SupportFormflag.value="true";
		}
	return true;	
}

function ValidateRecentWins()
{
		with(document.formobject)
		{		
				if (txtLinkTitle.value=="")
				{
					alert("Please Enter the Title");
					txtLinkTitle.focus();
					return false;
				}
				ValidateRecentWinsflag.value="true";
		}
	return true;	
}

function ValidateCaseStudies()
{
		with(document.formobject)
		{		
				if (txtLinkTitle.value=="")
				{
					alert("Please Enter the Title");
					txtLinkTitle.focus();
					return false;
				}
				ValidateCaseStudiesflag.value="true";
		}
	return true;	
}

function LoadParentRecords(SelectedValue)
{
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
			alert ("Your browser does not support AJAX!");
			return false;
		}
		CategoryID=document.formobject.CategoryID.value;
		TableName=document.formobject.TableName.value;
		if(CategoryID==-1)
		{
			alert("Please Select the Category");
			return;
		}
		document.getElementById("tdresult").innerHTML='<img src=images/ajaxloader.gif>';
		var url='LoadRecords.php';
		url=url+"?CategoryID="+CategoryID;	
		url=url+"&SelectedValue="+SelectedValue;	
		url=url+"&TableName="+TableName;	
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=LoadParentRecordsStateChanged;
		xmlHttp.open("GET",url,true);		
		xmlHttp.send(null);
		return false;
	
}

function LoadParentRecordsStateChanged() 
{ 
		if (xmlHttp.readyState==4)
		{ 	
				document.getElementById("tdresult").innerHTML=xmlHttp.responseText;
		}
}	

//Newsletter
function searchcontrol(control)
{
	if(control.value=="")
	{
		control.value="Enter here to Search";
	}
}


function ValidateSiteSearch()
{
		with(document.searchform)
		{		
			if(SearchValue.value=="Enter here to Search")
			{
				alert("Please Enter a Search Term");
				SearchValue.focus();
				return false;
			}else if(SearchValue.value=="")
			{
				alert("Please Enter a Search Term");
				SearchValue.focus();
				return false;
			}
			searchformflag.value="true";
		}
	document.searchform.submit();
}



