// JavaScript Document
function isEmpty(Field, Msg)
{
	if(Field.value == ""){
		alert(Msg);
		Field.focus();
//		document.getElementById('errors').innerHTML=Msg;
		return true;
	}
	return false
}


		function isNotValidEmail(Email, Msg)
		{
			var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
			if(reg.test(Email.value) == false) 
			{
				alert(Msg);
				Email.focus();
				//document.getElementById('errors').innerHTML=Msg;
				return true
			}
			return false
		}


function isContact(Field, Msg)
{
	if (Field.value.match(/\D/g))
		{ 
			alert(Msg);
			Field.focus();
			//document.getElementById('errors').innerHTML=Msg ; 
			return true; 
		}
	else
	{
		return false;
	}
}

			function isNotNo(Field, Msg)
			{
				if(isNaN(Field.value))
				{
					document.getElementById('errors').innerHTML=Msg;
					Field.select();
					return true;
				}
				return false;
			}


function isNotSame(Field1, Field2, Msg)
{
	if(Field1.value != Field2.value)
	{
		alert(Msg)
		Field1.focus()
		return true
	}
	return false
}


function isInvalidLength(Field, Length, Msg)
{
	if(eval(Field.value.length) > eval(Length))
	{
			alert(Msg)
			Field.focus()
			return true
	}
	return false
}
	  
function Clear(Form)
{
	Form.reset
	return false
}

function isNotValidCharacters(Sec,MSG)
{
	var Spn = document.getElementById('spn').value;
	
	if(Spn=='1')
	{
		if(! ( Sec.value == "JK904" || Sec.value == "jk904" || Sec.value == "Jk904" || Sec.value == "jK904") ) 
		{
			alert(MSG)
			Sec.value=''
			Sec.focus()
			insertSpam()
			return true 
		}
		else
		{
			return false;
		}
	}
	if(Spn=='2')
	{
		if(! ( Sec.value == "WS506" || Sec.value == "Ws506" || Sec.value == "wS506" || Sec.value == "ws506") ) 
		{
			alert(MSG)
			Sec.value=''
			Sec.focus()
			insertSpam()
			return true 
		}
		else
		{
			return false;
		}
	}
	if(Spn=='3')
	{
		if(! ( Sec.value == "JE496" || Sec.value == "Je496" || Sec.value == "jE496" || Sec.value == "je496") ) 
		{
			alert(MSG)
			Sec.value=''
			Sec.focus()
			insertSpam()
			return true 
		}
		else
		{
			return false;
		}
	}
	if(Spn=='4')
	{
		if(! ( Sec.value == "ER453" || Sec.value == "Er453" || Sec.value == "eR453" || Sec.value == "er453") ) 
		{
			alert(MSG)
			Sec.value=''
			Sec.focus()
			insertSpam()
			return true 
		}
		else
		{
			return false;
		}
	}
	if(Spn=='5')
	{
		if(! ( Sec.value == "CY561" || Sec.value == "Cy561" || Sec.value == "cY561" || Sec.value == "cy561") ) 
		{
			alert(MSG)
			Sec.value=''
			Sec.focus()
			insertSpam()
			return true 
			
		}
		else
		{
			return false;
		}
	}
	if(Spn=='6')
	{
		if(! ( Sec.value == "hi421" || Sec.value == "Hi421" || Sec.value == "hI421" || Sec.value == "HI421") ) 
		{
			alert(MSG)
			Sec.value=''
			Sec.focus()
			insertSpam()
			return true 
		}
		else
		{
			return false;
		}
	}
	if(Spn=='7')
	{
		if(! ( Sec.value == "IP590" || Sec.value == "ip590" || Sec.value == "iP590" || Sec.value == "Ip590") ) 
		{
			alert(MSG)
			Sec.value=''
			Sec.focus()
			insertSpam()
			return true 
		}
		else
		{
			return false;
		}
	}
}
/************************************************************/
function ValidateEmpty(Field, ID)
{
	var Msg = document.getElementById(ID)
	if(Field.value == "")
	{
		Msg.className = "ShowError4EmptyTextField"
		
		return false
	}
	else
	{
		Msg.className = "HideError4EmptyTextField"
		return true
	}
}
function ValidateEmail(Email, ID)
{
	var Msg = document.getElementById(ID)
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   	if(reg.test(Email.value) == false) 
	{
	    Msg.className = "ShowError4EmptyTextField"
		Msg.innerHTML = "Please Enter a Valid Email Address";
	
      	return false
	}
	else
	{
		Msg.className = "HideError4EmptyTextField"
		return true
	}
}

function MatchPasswords(pass1, pass2, errMsg)
{

	if (pass1.value != pass2.value)
	{
		document.getElementById('errors').innerHTML=Msg;		
		return true;
	}
	else
	{
		return false
	}
}

function MatchEmails(Email1, Email2, ID)
{
	var Msg = document.getElementById(ID)
	if(Email2.value == "")
	{
		Msg.innerHTML = "Please Enter a Valid Confirm Email Address";
		Msg.className = "ShowError4EmptyTextField"
		
		return false	
	}
	else if(Email1.value != Email2.value)
	{
		Msg.innerHTML = "Email and Confirm Email are not Same";
		
		Msg.className = "ShowError4EmptyTextField"
		return false
	}
	else
	{
		Msg.className = "HideError4EmptyTextField"
		return true
	}
}
function ValidateRadio(RadioFields, ID)
{
	var Msg = document.getElementById(ID)
	var nRadios = RadioFields.length
	var Marked = 0;
	for(i=0; i<nRadios; i++){
		if(RadioFields[i].checked)
			Marked++;
	}
	if(Marked == 0){
		Msg.className = "ShowError4EmptyTextField"
		return false
	}else{
		Msg.className = "HideError4EmptyTextField"
		return true
	}
}
function ValidateZipCode(Zip, ID)
{
	var Msg = document.getElementById(ID)
	var reg =  /^\d{5}([\-]\d{4})?$/;
	
   	if(reg.test(Zip.value) == false) 
	{
	    Msg.className = "ShowError4EmptyTextField"
		Msg.innerHTML = "Please Enter a Valid Zipcode";
	
      	return false
	}
	else
	{
		Msg.className = "HideError4EmptyTextField"
		return true
	}
}
function MatchFields(Field1, Field2, ID)
{
	var Msg = document.getElementById(ID)
	if(Field1.value != Field2.value)
	{
		Msg.className = "ShowError4EmptyTextField"
		return false
	}
	else
	{
		Msg.className = "HideError4EmptyTextField"
		return true
	}
}
function isNotNo(Field, Msg)
{
	var Msg = document.getElementById(ID)
	if(isNaN(Msg.value))
	{
		Msg.className = "ShowError4EmptyTextField"
		return false
	}
	else
	{
	Msg.className = "HideError4EmptyTextField"
		return true
	}
}
function ValidateCheckboxes(CheckBoxFields, ID, nChecks)
{  

	var Msg = document.getElementById(ID)
	var Marked = 0;
	
	if(nChecks == 1){
		if(CheckBoxFields.checked)
			Marked++;
	}
	else if(nChecks > 1)
	{
		for(i=0; i < nChecks; i++){
			if(CheckBoxFields[i].checked)
				Marked++;
		}
	}
	if(Marked == 0){
		Msg.className = "ShowError4EmptyTextField"
		return false
	}else{
		Msg.className = "HideError4EmptyTextField"
		return true
	}
}
function ValidateCheckBox(CheckBox, Msg)
{
	if(CheckBox.checked)
	{
		return false;
	}
	else
	{	
		document.getElementById('errors').innerHTML=Msg;
		return true;
	}
}
function valid(form)
	{
	 if(form.code.value == "" || isNaN(form.code.value))
	
		{
		alert("Please provide 3 digit (numerics) comapny code");
		form.code.focus();
		return false;
	   }
	}
function checkUncheckAll(theElement) {
     var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++){
      if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
	  theForm[z].checked = theElement.checked;
	  }
     }
    }
function insertSpam()
{
var randomnumber=Math.floor(Math.random()*6)
randomnumber++;
document.getElementById('spam2').value=randomnumber;
if(randomnumber=='1')
	{
		document.getElementById('code').innerHTML='<img src="images/spam1.jpg" width="50" height="19" border="0"><input type="hidden" value="1" name="spn" id="spn">';
	}
if(randomnumber=='2')
	{
		
		document.getElementById('code').innerHTML='<img src="images/spam2.jpg" width="50" height="19" border="0"><input type="hidden" value="2" name="spn"  id="spn">';
	}
	if(randomnumber=='3')
	{
		
		document.getElementById('code').innerHTML='<img src="images/spam3.jpg" width="50" height="19" border="0"><input type="hidden" value="3" name="spn" id="spn">';
	}
	if(randomnumber=='4')
	{
		
		document.getElementById('code').innerHTML='<img src="images/spam4.jpg" width="50" height="19" border="0"><input type="hidden" value="4" name="spn" id="spn">';
	}
	if(randomnumber=='5')
	{
		
		document.getElementById('code').innerHTML='<img src="images/spam5.jpg" width="50" height="19" border="0"><input type="hidden" value="5" name="spn" id="spn">';
	}
	if(randomnumber=='6')
	{
		
		document.getElementById('code').innerHTML='<img src="images/spam6.jpg" width="50" height="19" border="0"><input type="hidden" value="6" name="spn" id="spn">';
	}
	if(randomnumber=='7')
	{
		
		document.getElementById('code').innerHTML='<img src="images/spam7.jpg" width="50" height="19" border="0"><input type="hidden" value="7" name="spn" id="spn">';
	}
}