// JavaScript Document
imgDIR = "images"
var theImages = new Array()
theImages[0] = imgDIR+'/code-01.gif'
theImages[1] = imgDIR+'/code-02.gif'
theImages[2] = imgDIR+'/code-03.gif'
theImages[3] = imgDIR+'/code-04.gif'
var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
   preBuffer[i] = new Image()
   preBuffer[i].src = theImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));
function codeimages(){
document.write('<img src="'+theImages[whichImage]+'">');
//document.getElementById('codes').innerHTML="<img src="'+theImages[whichImage]+'">"
}


function txtcheck()
{
		var Fname=document.getElementById('Name')
			if(Fname.value == ""||Fname.value == null)
				{
					alert("Please enter the name.");
					Fname.focus();
					return false
				}
		var emailID=document.getElementById('Email')
				if ((emailID.value==null)||(emailID.value==""))
					{
							alert("Please enter your email id.");
							emailID.focus()
						return false
					}
				if (echeck(emailID.value)==false)
					{
						emailID.value=""
						emailID.focus()
						return false
					}
		var Phone=document.getElementById('tel')
			if(Phone.value == ""||Phone.value == null)
				{
					alert("Enter the telephone number.");
					Phone.focus();
					return false
				}
		var Message=document.getElementById('Message')
			if(Message.value == ""||Message.value == null)
				{
					alert("Please enter the message.");
					Message.focus();
					return false
				}
		var Scode=document.getElementById('Security')
			if(Scode.value == ""||Scode.value == null || Scode.value != "%N#Am" && Scode.value != "!K$*N" && Scode.value != "W)T^A" && Scode.value != "7Y@L3")
				{
					alert("Type the code shown");
					document.getElementById('Security').value="";
					Scode.focus();
					
					return false
				}
		return true
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		  alert("Invalid E-mail ID");
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		    alert("Invalid E-mail ID");
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		     alert("Invalid E-mail ID");
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		     alert("Invalid E-mail ID");
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		     alert("Invalid E-mail ID");
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		     alert("Invalid E-mail ID");
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		     alert("Invalid E-mail ID");
		    return false
		 }

 		 return true					
	}



function checkForInvalid(obj) 
	{
		obj.value = obj.value.replace(/[^0-9\-]|(-{2,})/gi, (RegExp.$1.indexOf("-") > -1) ? "-" : "");
	}

