// Author: Amol Nirmala Waman
// Email: amolnw2778@gmail.com
// Date: Wednesday, 23 April 2008

//To check combo box is selected or not
	function checkComboBox(cmbValidted)
	{
		if(cmbValidted.length > 0 && cmbValidted.value == '')
		{
			return false;
		}
		else
			return true;
	}

	// To check special charcter occurence in string but allow spaces
	function checkSpecialCharNotSpaces(obj)
	{	
		var iChars ="!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
		
		for (var i = 0; i < obj.value.length; i++)
		{
			if (iChars.indexOf(obj.value.charAt(i)) != -1)
			{
				return i;
			}
		}		
		return -1;
	}
	
	// For User Name Validation
	function validateUserName(obj, message)
	{
		strValid = parseInt(checkSpecialChar(obj));

		if(strValid != -1)
		{
			alert (message);
			obj.value	= obj.value.substr(0,strValid);
			return false;
		}
		else
			return true;		
	}
	
	// Validate Email added by Avinash Chougule.	
	function EmailValidation(emailAddress)
	{
		try{
			var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
			var regex = new RegExp(emailReg);
			
			if (regex.test(emailAddress))
			{
				return true;
			}
			else
			{
				return false;  
			}
		}
		catch (e) {
			alert(e.description);
		}
	}

	// To check special charcter occurence in string
	function checkSpecialChar(obj)
	{	
		var iChars ="!@ # $ % ^ & * ()+ = - []\\\';,./{}|\":<>?";
		
		for (var i = 0; i < obj.value.length; i++)
		{
			if (iChars.indexOf(obj.value.charAt(i)) != -1)
			{
				return i;
			}
		}
		
		return -1;
	}
	
	//To check empty field and show alert if empty
	function isEmpty(obj, message)
	{
		if(obj.value == "")
		{
			alert(message);
			obj.focus();
			return false;
		}
		else
			return true;
	}
	
	//Validate zip code
	function checkForNumericCharacter (obj, message){
		if( /[^0-9\-]|-{2,}/gi.test(obj.value) )
		{
			alert(message)
			obj.value = ""; // line added to clear textbox value
			obj.focus();
			return false;
		}
		return true;
	}
	
	// To reset all text fields on form
	function clearForm(form)
	{
		for(var iIndex = 0; iIndex < form.elements.length ; ++iIndex)
		{
			var elem 	= form.elements[iIndex];
			if(elem.type == "text")
			{
				elem.value	= "";
			}
		}
	}
	
	// To check all text fields length on form
	function checkLength(form)
	{
		for(var iIndex = 0; iIndex < form.elements.length ; ++iIndex)
		{
			var elem 	= form.elements[iIndex];
			if(elem.type == "text")
			{
				alert('Name '+elem.name +' length '+elem.value.length);
			}
		}
	}
	
	function validatePassword(password, repassword) 
	{
		var invalid = " "; // Invalid character is a space
		var minLength = 5; // Minimum length
		// check for minimum length
		if (password.value.length < minLength) {
			alert('Your password must be at least ' + minLength + ' characters long. Try again.');
			password.focus();			
			return false;
		}
		// check for spaces
		if (password.value.indexOf(invalid) > -1) 
		{
			alert("Sorry, spaces are not allowed.");
			return false;
		}
		else 
		{
			if (password.value != repassword.value) {
				alert ("You did not enter the same new password twice. Please re-enter your password.");
				repassword.focus();
				return false;
			}
			else 
			{
				return true;
			}
		}
	}
	
// Show-Hide divs
function showDiv(id){
	document.getElementById(id).style.display = 'block';
}
function hideDiv(id){
	document.getElementById(id).style.display = 'none';
}

/* Contact us validation */
function valContact(){
	with (document.contact_frm){
		var msg1 = "Please enter your ";
		var empSpace = " "; // Blank space is invalid character
		var msg2 = "Spaces are not allowed!";
		if(Name.value == ""){
			alert(msg1+"First Name!");
			Name.focus();
			return false;
		}
		if(Address.value == ""){
			alert(msg1+"Address!");
			Address.focus();
			return false;
		}
		if(CompanyName.value == ""){
			alert(msg1+"Company Name!");
			CompanyName.focus();
			return false;
		}
		if(City.value == ""){
			alert(msg1+"City!");
			City.focus();
			return false;
		}
		if(Email.value == ""){
			alert(msg1+"Email!");
			Email.focus();
			return false;
		}
		if(Email.value.indexOf(empSpace) > -1){
			alert(msg2);
			Email.focus();
			return false;
		}
		if(Phone.value == ""){
			alert(msg1+"Phone!");
			Phone.focus();
			return false;
		}
		return true;
	}
}
/* Contact us validation ends */