//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 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;	
}



//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 Sequence
function UpdateSequence()
{
	with(document.formobject)
	{		
			updatesequenceflag.value="true";
	}
	document.formobject.submit();
}

//Validate News
function ValidateNews()
{
		with(document.formobject)
		{		
				if (Title.value=="")
				{
					alert("Please Enter the Title");
					Title.focus();
					return false;
				}else if (ItemDate.value=="")
				{
					alert("Please Enter the News Date");
					ItemDate.focus();
					return false;
				}
				ValidateNewsflag.value="true";
		}
	return true;		
}

//Validate Events

function ValidateEvents()
{
		with(document.formobject)
		{		
				if (Title.value=="")
				{
					alert("Please Enter the Title");
					Title.focus();
					return false;
				}else if (ItemDate.value=="")
				{
					alert("Please Enter the News Date");
					ItemDate.focus();
					return false;
				}
				ValidateEventsflag.value="true";
		}
	return true;		
}


//Validate Login Form

function ValidateLoginForm()
{
		with(document.loginform)
		{		
				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;
				}
				ValidateLoginFormflag.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(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;	
}

function ValidateVehicle()
{
		with(document.formobject)
		{		
				if (TypeID.value==-1)
				{
					alert("Please Select the Vehicle Type");
					TypeID.focus();
					return false;
				}else if (BrandID.value==-1)
				{
					alert("Please Select the Brand");
					BrandID.focus();
					return false;
				}else if(GroupID.value==-1)
				{
					alert("Please Select the Group");
					GroupID.focus();
					return false;
				}else if(Vehicle.value=="")
				{
					alert("Please Enter the Vehicle");
					Vehicle.focus();
					return false;
				}
				ValidateVehicleflag.value="true";
		}
	return true;	
}
//Reservation Forms
function ValidateReservationForm()
{
		with(document.reservationform)
		{		
				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(PickUpDate.value=="")
				{
					alert("Please Enter the Pick up Date");
					PickUpDate.focus();
					return false;
				}else if(PickUpLocation.value=="")
				{
					alert("Please Enter the Pick Up Location");
					PickUpLocation.focus();
					return false;
				}else if(ReturnDate.value=="")
				{
					alert("Please Enter the Return Date");
					ReturnDate.focus();
					return false;
				}else if(ReturnLocation.value=="")
				{
					alert("Please Enter the Return Location");
					ReturnLocation.focus();
					return false;
				}else if(VehicleType.value==-1)
				{
					alert("Please select the Vehicle Type");
					VehicleType.focus();
					return false;
				}else if(Vehicle.value==-1)
				{
					alert("Please Select the Vehicle");
					Vehicle.focus();
					return false;
				}
				reservationformflag.value="true";
		}
	return true;	
}


//Validate Quick Reservation

function ValidateQuickReservation()
{
	with(document.quickreservation)
		{		
				if(VehicleType.value==-1)
				{
					alert("Please select the Vehicle Type");
					VehicleType.focus();
					return false;
				}else if(Vehicle.value==-1)
				{
					alert("Please Select the Vehicle");
					Vehicle.focus();
					return false;
				}else if (txtName.value=="")
				{
					alert("Please Enter your Name");
					txtName.focus();
					return false;
				}else if(txtContact.value=="")
				{
					alert("Please Enter your Contact Information (Email / Contact Number)");
					txtContact.focus();
					return false;
				}
				quickreservationflag.value="true";
		}
	return true;	
}

function CallFunction(VehicleType,Group,action)
{
	document.getElementById("groupcontainer").value=Group;
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return false;
	}
	var url='CallVehicle.php';
	url=url+"?action="+action;
	url=url+"&VehicleType="+VehicleType;
	url=url+"&Group="+Group;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=CallFunctionStateChanged;
	xmlHttp.open("GET",url,true);		
	xmlHttp.send(null);
	return;
}

function CallFunctionStateChanged() 
{ 
		if (xmlHttp.readyState==4)
		{ 	
				var maincontainer='groupcontainer'+document.getElementById("groupcontainer").value;
				var nextpreviouscontainer='nextpreviouscontainer'+document.getElementById("groupcontainer").value;
				document.getElementById(maincontainer).innerHTML=xmlHttp.responseText;
				document.getElementById(nextpreviouscontainer).innerHTML=xmlHttp.responseText;
				var result=xmlHttp.responseText;
				var resultarray=result.split("----------!!!!!!________RSI_________!!!!!!!!--------");
				document.getElementById(maincontainer).innerHTML=resultarray[0];
				document.getElementById(nextpreviouscontainer).innerHTML=resultarray[1];
		}
}


//Loading Vehicles
function LoadVehicles()
{
	VehicleType=document.reservationform.VehicleType.value;
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return false;
	}
	var url='LoadVehicles.php';
	url=url+"?VehicleType="+VehicleType;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=LoadVehiclesStateChanged;
	xmlHttp.open("GET",url,true);		
	xmlHttp.send(null);
	return false;
}

function LoadVehiclesStateChanged() 
{ 
		if (xmlHttp.readyState==4)
		{ 	
				document.getElementById("vehiclecontainer").innerHTML=xmlHttp.responseText;
		}
}

//Loading Quick Vehicles
function LoadQuickVehicles()
{
	VehicleType=document.quickreservation.VehicleType.value;
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return false;
	}
	var url='LoadVehicles.php';
	url=url+"?VehicleType="+VehicleType;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=LoadQuickVehiclesStateChanged;
	xmlHttp.open("GET",url,true);		
	xmlHttp.send(null);
	return false;
}

function LoadQuickVehiclesStateChanged() 
{ 
		if (xmlHttp.readyState==4)
		{ 	
				document.getElementById("quickform_vehiclecontainer").innerHTML=xmlHttp.responseText;
		}
}


