//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)
		{ 	
				document.getElementById("usernamecheck").innerHTML=xmlHttp.responseText;
				if(xmlHttp.responseText=="Username Available")
				{
					document.formobject.usernamehiddencheck.value=1;
				}else if(xmlHttp.responseText=="Username Unavailable")
				{
					document.formobject.usernamehiddencheck.value=0;
				}
				alert(document.formobject.usernamehiddencheck.value);
		}
}
//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(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)
	{		
				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;	
}

//Changing Tab

function changeTab(divcount,maxlength)
{
	alert(divcount);
	var i;
	for(i=1;i<=maxlength;i++)
	{
		document.getElementById(i).style.display="block";
	}
}

//Validate Products

function ValidateProducts()
{
		with(document.formobject)
		{		
				if (txtProductTitle.value=="")
				{
					alert("Please Enter the Product Title");
					txtProductTitle.focus();
					return false;
				}else if(Sequence.value=="")
				{
					alert("Please Enter the 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;
						}
				}
				ValidateProductsflag.value="true";
		}
	return true;	
}

//Validate Services

function ValidateServices()
{
		with(document.formobject)
		{		
				if (txtServiceTitle.value=="")
				{
					alert("Please Enter the Service Title");
					txtServiceTitle.focus();
					return false;
				}else if(Sequence.value=="")
				{
					alert("Please Enter the 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;
						}
				}
				ValidateServicesflag.value="true";
		}
	return true;	
}


//Validating Banners

function ValidateBanner()
{
		with(document.formobject)
		{		
				if (txtURL.value=="")
				{
					alert("Please Enter the Destination URL");
					txtURL.focus();
					return false;
				}else if(Sequence.value=="")
				{
					alert("Please Enter the Sequence");
					Sequence.focus();
					return false;
				}else if(flag.value==0)
				{
						if(BannerFile.value.length<5)
						{
							alert("Please Upload the Banner");
							BannerFile.focus();
							return false;
						}
				}
				ValidateBannerflag.value="true";
		}
	return true;	
}

//Validating Jobs

function ValidateJobs()
{
		with(document.formobject)
		{		
				if(JobRef.value=="")
				{
					alert("Please Enter the Job Reference");
					JobRef.focus();
					return false;
				}else if(Sequence.value=="")
				{
					alert("Please Enter the Sequence");
					Sequence.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;
				}
				ValidateJobsflag.value="true";
		}
	return true;	
}

//Validate Enquiry

function validatecustomerservice()
{
		with(document.formobject)
		{		
				if(txtName.value=="")
				{
					alert("Please enter your Full Name");
					txtName.focus();
					return false;
				}else if(txtCompanyName.value=="")
				{
					alert("Please Enter your company name");
					txtCompanyName.focus();
					return false;
				}else if(txtContactNumber.value=="")
				{
					alert("Please Enter your contact number");
					txtContactNumber.focus();
					return false;
				}else if(txtEmail.value=="")
				{
					alert("Please Enter your Email Address");
					txtEmail.focus();
					return false;
				}else if(!(isEmail(txtEmail.value)))
				{
					alert("Please Enter a Valid Email Address (abc@abc.com)");
					txtEmail.focus();
					return false;
				}else if(txtSubject.value=="")
				{
					alert("Please Enter the Subject of your enquiry");
					txtSubject.focus();
					return false;
				}else if(Description.value=="")
				{
					alert("Please enter a breif summary of your enquiry");
					Description.focus();
					return false;
				}
				validatecustomerserviceflag.value="true";
		}
	return true;	
}
//Validate Projects
function ValidateProjects()
{
		with(document.formobject)
		{		
				if(txtProjectTitle.value=="")
				{
					alert("Please enter the Project Title");
					txtProjectTitle.focus();
					return false;
				}
				ValidateProjectsflag.value="true";
		}
	return true;	
	
}

//Validate Documents
function ValidateDocuments()
{
		with(document.formobject)
		{
				if(ProjectID.value==-1)
				{
					alert("Please Select the Project");
					ProjectID.focus();
					return false;
				}
			
				ValidateDocumentsflag.value="true";
		}
	return true;		
}


//Validate Website Users

function ValidateWebsiteUser(flag)
{	
		with(document.formobject)
		{		
				if (UserType.value==-1)
				{
					alert("Please Select the User Type");
					UserType.focus();
					return false;
				}else if (txtUserName.value=="")
				{
					alert("Please Enter the User Name");
					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(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;
						}
				}
				ValidateWebsiteUserflag.value="true";
		}
	return true;	
	
}



function validateenquiryform()
{
		with(document.formobject)
		{		
				if(txtName.value=="")
				{
					alert("Please enter your Full Name");
					txtName.focus();
					return false;
				}else if(txtCompanyName.value=="")
				{
					alert("Please Enter your company name");
					txtCompanyName.focus();
					return false;
				}else if(txtContactNumber.value=="")
				{
					alert("Please Enter your contact number");
					txtContactNumber.focus();
					return false;
				}else if(txtEmail.value=="")
				{
					alert("Please Enter your Email Address");
					txtEmail.focus();
					return false;
				}else if(!(isEmail(txtEmail.value)))
				{
					alert("Please Enter a Valid Email Address (abc@abc.com)");
					txtEmail.focus();
					return false;
				}else if(Description.value=="")
				{
					alert("Please enter the description");
					Description.focus();
					return false;
				}
				validateenquiryformflag.value="true";
		}
	return true;	
}

//Validate Login

function validateLogin()
{
		with(document.loginform)
		{		
				if(txtUserName.value=="")
				{
					alert("Please enter your Username");
					txtUserName.focus();
					return false;
				}else if(txtPassword.value=="")
				{
					alert("Please Enter your password");
					txtPassword.focus();
					return false;
				}
				loginflag.value="true";
		}
	return true;	
}

//Validate Message

function ValidateMessage()
{
	with(document.formobject)
		{		
				if(txtSubject.value=="")
				{
					alert("Please enter the Subject");
					txtSubject.focus();
					return false;
				}else if(Description.value=="")
				{
					alert("Please Enter the message");
					Description.focus();
					return false;
				}
				ValidateMessageflag.value="true";
		}
	return true;	
}

//Validate Floor Plans


function ValidateFloorPlanType()
{
		with(document.formobject)
		{		
				ValidateFloorPlanTypeflag.value="true";
		}
		return true;	
}


//Validate Floor Plan Details

function ValidateFloorplanDetails()
{
		with(document.formobject)
		{		
				ValidateFloorplanDetailsflag.value="true";
		}
		return true;	
}

//Validate Search
function validatesearch()
{
		with(document.searchform)
		{		
				if(txtSearch.value=="")
				{
					alert("Please enter the value to search");
					txtSearch.focus();
					return false;
				}
					PageType.value="search";
		}
		return true;	
}

//Validate Client Document Upload

function ValidateClientDocumentUpload()
{
	
		with(document.formobject)
		{		
				if(ImageFile1.value.length<5)
				{
					alert("Please Select the File");
					ImageFile1.focus();
					return false;
				}
					ValidateClientDocumentUploadflag.value="true";
		}
		return true;	
}


//Validate Showroom Banners

function ValidateTopBanners()
{
		with(document.formobject)
		{		
			if(BannerType.value==-1)
			{
				alert("Please Select the Banner Type");
				BannerType.focus();
				return false;
			}else if(Sequence.value=="")
			{
				alert("Please enter the Sequence");
				Sequence.focus();
				return false;
			}
			ValidateTopBannersflag.value="true";
	}
	return true;
}

//Update Sequence
function UpdateSequence()
{
	with(document.formobject)
	{		
			updatesequenceflag.value="true";
	}
	document.formobject.submit();
}

//Pop up Window
var win = null;
function OpenImageManager(mypage,myname,w,h,scroll)
{
w=screen.width;
h=screen.height;
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
win = window.open(mypage,myname,settings)
}

