//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 (info@capitalstreet.net)");
					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 ValidateResource()
{
		with(document.formobject)
		{		
				if (txtLinkTitle.value=="")
				{
					alert("Please Enter the Link Title");
					txtLinkTitle.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;
						}
				}
				
				ValidateResourceflag.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(Sequence.value=="")
				{
					alert("Please Enter the Sequence");
					Sequence.focus();
					return false;
				}
				ValidateNewsflag.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 (txtTagLine.value=="")
			{
				alert("Please enter the Tag Line");
				txtTagLine.focus();
				return false;
			}
			ValidateWebsiteConfigurationflag.value="true";
	}
	return true;	
}

//Validating Newsletter
function ValidateNewsletter()
{
	with(document.formobject)
	{		
		if (txtNewsLetterTitle.value=="")
		{
			alert("Please Enter the Newsletter Title");
			txtNewsLetterTitle.focus();
			return false;
		}
		ValidateNewsletterflag.value="true";
	}
	return true;	
}

//Newsletter
function noblurnewslettercontrol(control)
{
	if(control.value=="")
	{
		control.value="Subscribe to Newsletter";
	}
}

//Validating Subscriber

function ValidateSubscriber()
{
	with(document.newsletterform)
	{
		if(txtSubscriber.value=="")
		{
			alert("Please Enter the Email Address");
			txtSubscriber.focus();	
			return false;
		}else if(!(isEmail(txtSubscriber.value)))
		{
			alert("Please Enter the Email Address(info@capitalstreet.net)");
			txtSubscriber.focus();	
			return false;
		}
		newsletterflag.value="true";
	}
	document.newsletterform.submit();
}
//Validating Enquiry Form
function validateenquiry()
{
		with(document.contactusform)
		{
				if (txtName.value=="")
				{
					alert("Please Enter your Full 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 the Email Address(info@capitalstreet.net)");
					txtEmail.focus();
					return false;
				}
				if(!(TermsCondition.checked))
				{
					alert("Please read the Terms and Conditions");
					return false;
				}
				contactusflag.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;	
}

//Validating Personal Profile
function ValidatePersonalProfile()
{
		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 ((txtTelephone.value=="") && (txtMobile.value==""))
				{
					alert("Please Enter at least one Contact Number (Telephone / Mobile Number)");
					txtTelephone.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 the Email Address(info@capitalstreet.net)");
					txtEmail.focus();
					return false;
				}
				ValidatePersonalProfileflag.value="true";
	}
	return true;	
}

//Validating Newsletter

function ValidateSendNewsletter()
{
		with(document.formobject)
		{
				if (FromCompanyName.value=="")
				{
					alert("Please Enter your Company Name");
					FromCompanyName.focus();
					return false;
				}else if (FromAddress.value=="")
				{
					alert("Please Enter the From Address");
					FromAddress.focus();
					return false;
				}else if (ReplyTo.value=="")
				{
					alert("Please Enter the Reply to Address");
					ReplyTo.focus();
					return false;
				}else if (ReplyTo.value=="")
				{
					alert("Please Enter the Reply to Address");
					ReplyTo.focus();
					return false;
				}else if (txtSubject.value=="")
				{
					alert("Please Enter the Subject for Newsletter");
					txtSubject.focus();
					return false;
				}else if(Newsletter.value==-1)
				{
					alert("Please Select a Newsletter to be sent");
					Newsletter.focus();
					return false;
				}
				
				ValidateSendNewsletterflag.value="true";
		}
	return true;	
}

//Validating Jobs

function ValidateJob()
{
		with(document.formobject)
		{
				if (txtJobTitle.value=="")
				{
					alert("Please Enter the Job Title");
					txtJobTitle.focus();
					return false;
				}else if (Sequence.value=="")
				{
					alert("Please Enter the Order Sequence");
					Sequence.focus();
					return false;
				}
				ValidateJobflag.value="true";
	}
	return true;	
}

//Select All for Newsletter Contacts

function selectall()
{
	var length=document.formobject.contacts.length;
	if(length<1)
	{
		return false;
	}
	var i;
	if(document.formobject.contacts[length-1].checked)
	{
		alert("checked");
		for(i=0;i<length;i++)
		{
			document.formobject.contacts[i].checked=true;
		}
	}else
	{
		for(i=0;i<length;i++)
		{
			document.formobject.contacts[i].checked=false;
		}
	}
}

//Validating City Name

function ValidateCity()
{
		with(document.formobject)
		{		
				if (txtCityName.value=="")
				{
					alert("Please Enter the City");
					txtCityName.focus();
					return false;
				}else if(CountryID.value==-1)
				{
					alert("Please Select the Country");
					CountryID.focus();
					return false;
				}
				ValidateCityflag.value="true";
		}
	return true;	
}


//Validating Associates

function ValidateAssociate()
{
		with(document.formobject)
		{		
				if (txtAssociateName.value=="")
				{
					alert("Please enter the Associate Name");
					txtAssociateName.focus();
					return false;
				}else if(txtWebsite.value=="http://")
				{
					alert("Please Enter the Website");
					txtWebsite.focus();
					return false;
				}else if(flag.value==0)
				{
					if(txtLogo.value.length<5)
					{
							alert("Please Upload the Logo");
							txtLogo.focus();
							return false;
					}
				}
				ValidateAssociateflag.value="true";
		}
	return true;	
}

//Validating Deal

function validatedeal()
{
	with(document.dealform)
	{
			if(txtName.value=="")
			{
				alert("Please Enter your Name");
				txtName.focus();
				return false;
			}else if (country.value==-1)
			{
				alert("Please Select the Country");
				country.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 the Email Address(info@capitalstreet.net)");
				txtEmail.focus();
				return false;
			}else if(description.value=="")
			{
				alert("Please Enter the Description");
				description.focus();
				return false;
			}else if (buyercategory.value==-1)
			{
				alert("Please Select the Buyer's Category");
				buyercategory.focus();
				return false;
			}
			var i=0;
			var flag=0;
			for(i=0;i<industries.length;i++)
			{
				if(flag==1)
				{
					continue;	
				}
				if(industries[i].checked)
				{
					flag=1;	
				}
			}
			if(flag==0)
			{
				alert("Please Select the Industry Interest");
				return false;
			}
			validatedealflag.value="true";
	}
	return true;	
}

//Validating Seller Dear

function validatesellerdeal()
{
	with(document.dealform)
	{
			if (txtName.value=="")
			{
				alert("Please Enter your Name");
				txtName.focus();
				return false;
			}else if (country.value==-1)
			{
				alert("Please Select the Country");
				country.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 the Email Address(info@capitalstreet.net)");
				txtEmail.focus();
				return false;
			}else if(description.value=="")
			{
				alert("Please Enter the Description");
				description.focus();
				return false;
			}
			var i=0;
			var flag=0;
			for(i=0;i<industries.length;i++)
			{
				if(flag==1)
				{
					continue;	
				}
				if(industries[i].checked)
				{
					flag=1;	
				}
			}
			if(flag==0)
			{
				alert("Please Select the Industry Interest");
				return false;
			}
			validatedealflag.value="true";
	}
	return true;	
}
function ValidateAdminPanelDeal()
{
	with(document.formobject)
	{
			if (DealNumber.value=="")
			{
				alert("Please Enter the Deal Number");
				DealNumber.focus();
				return false;
			}else if (DealTitle.value=="")
			{
				alert("Please Enter the Deal Title");
				DealTitle.focus();
				return false;
			}else if (Address1.value=="")
			{
				alert("Please Enter the Address");
				Address1.focus();
				return false;
			}else if (Email.value=="")
			{
				alert("Please Enter the Email Address");
				Email.focus();
				return false;
			}else if (!(isEmail(Email.value)))
			{
				alert("Please Enter the Email Address(info@capitalstreet.net)");
				Email.focus();
				return false;
			}else if (Country.value==-1)
			{
				alert("Please Select the Country");
				Country.focus();
				return false;
			}else if (Referral.value==-1)
			{
				alert("Please Select the Referral");
				Referral.focus();
				return false;
			}else if(AskingPrice.value=="")
			{
				alert("Please Enter the Asking Price");
				AskingPrice.focus();
				return false;
			}else if(BookValue.value=="")
			{
				alert("Please Enter the Book Value");
				BookValue.focus();
				return false;
			}else if(NetProfit.value=="")
			{
				alert("Please Enter the Net Profit");
				NetProfit.focus();
				return false;
			}else if(YearlyRevenue.value=="")
			{
				alert("Please Enter the Yearly Revenue");
				YearlyRevenue.focus();
				return false;
			}else if(Sequence.value=="")
			{
				alert("Please Enter the Sequence");
				Sequence.focus();
				return false;
			}
			ValidateAdminPanelDealflag.value="true";
	}
	return true;	
}


//View All
function viewall()
{
	window.location="deal_listing.html";	
}

//Searching
function ValidateSearchForm()
{
	with(document.searchform)
	{
			if (country.value==-1)
			{
				alert("Please Select the Country");
				country.focus();
				return false;
			}else if (industry.value==-1)
			{
				alert("Please Select the Industry");
				industry.focus();
				return false;
			}			
		ValidateSearchFormflag.value="true";
	}
return true;	
}

//Validating Deal Upload

function ValidateDealUploads()
{
	with(document.formobject)
	{
		ValidateDealUploadsflag.value="true";	
	}
}

//Update Deal Sequence

function updateSequence()
{
	with(document.formobject)
	{
		updatesequenceflag.value="true";	
	}
}
