
function isExist(cstr,tocheck)
{
			var regex1
			regex1=new RegExp(tocheck,"gi")
			if(regex1.test(cstr))
				return true
			else
				return false

}


function  isEmpty(cntname)
{
	cnt=document.all(cntname)
	if(cnt.value=="")
		return true
	else
		return false
	
}

function getFocus(cstr)
{
	cnt=document.all(cstr)
	cnt.focus()
}


function replaceit(str,replacechar,replacewith)
{
	var regstr=new RegExp(replacechar,"gi")
	str=str.replace(regstr,replacewith)
	return str
}
function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
//   while (ch == " ") { // Check for spaces at the beginning of the string
  //    retValue = retValue.substring(1, retValue.length);
    //  ch = retValue.substring(0, 1);
   //}
   ch = retValue.substring(retValue.length-1, retValue.length);

   while (ch == " " || (ch.charCodeAt(0)==10) || (ch.charCodeAt(0)==9) || (ch.charCodeAt(0)==13)) { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
//   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
  //    retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
//   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function



function validateContestName()
{	
	var contestName=document.all("contestName")
	if(contestName.value=="") 
		{
		alert("Name can't be left blank")
		contestName.focus()
		return 0
		}
	document.all("contestName").value=replaceit(document.all("contestName").value,"[\x22]","'")
	document.all("contestName").value=replaceit(document.all("contestName").value,"'","''")
		return 1
		
}
function validateAnswer()
{
	var Answer
	Answer=document.addquestion.Answer
	if(isEmpty("Answer"))
		{
			alert("can't left blank")
			Answer.focus()
			return 0
		}
	msg=Answer.value
	msg=trim(msg)
	msg=replaceit(msg,"'","''")
	msg=replaceit(msg,"\x22","''")
	msglen=msg.length
	if(msglen >8000 )
		{
			alert("Can't have more than 7000 characters")
			Answer.focus()
			return 0
		}
Answer.value=msg
	return 1
}

function validateto(cnt)
{
	var Name
	Name=document.all(cnt)
	if(isEmpty(cnt))
		{
			alert(cnt + " Can't left blank")
			getFocus(cnt)
			return 0
		}
	return 1
}

function validateDesignation()
{
	var Designation
	Designation=document.all("Designation")
	if(isEmpty("Designation"))
		{
			alert("Designation can't left blank")
			getFocus("Designation")
			return 0
		}
	if(checkspecial(Designation.value,"[/:*?\x22<>|]"))
		{
			alert("should not contain characters  \\/:*?\"<>|")
			getFocus("Designation")
		  	return 0
		}

	msg=Designation.value
	msg=trim(msg)
	msg=replaceit(msg,"'","''")
	msg=replaceit(msg,"\x22","''")
	Designation.value=msg
	return 1
}

function validateFirstName()
{
	var firstname
	firstname=document.all("firstname")
	if(isEmpty("firstname"))
		{
			alert("First Name can't left blank")
			getFocus("firstname")
			return 0
		}
	if(checkspecial(firstname.value,"[/:*?\x22<>|]"))
		{
			alert("should not contain characters  \\/:*?\"<>|")
			getFocus("firstname")
		  	return 0
		}

	msg=firstname.value
	msg=trim(msg)
	msg=replaceit(msg,"'","''")
	msg=replaceit(msg,"\x22","''")
	firstname.value=msg
	return 1
}
function validateLastName()
{
	var lastname
	lastname=document.all("lastname")
	if(isEmpty("lastname"))
		{
			alert("Last Name can't left blank")
			getFocus("lastname")
			return 0
		}
	if(checkspecial(lastname.value,"[/:*?\x22<>|]"))
		{
			alert("should not contain characters  \\/:*?\"<>|")
			getFocus("lastname")
		  	return 0
		}

	msg=lastname.value
	msg=trim(msg)
	msg=replaceit(msg,"'","''")
	msg=replaceit(msg,"\x22","''")
	lastname.value=msg
	return 1
}
function validateCompany()
{
	var company
	company=document.all("company")
	if(isEmpty("company"))
		{
			alert("Company  Name can't left blank")
			getFocus("company")
			return 0
		}
		if(checkspecial(company.value,"[/:*?\x22<>|]"))
		{
			alert("should not contain characters  \\/:*?\"<>|")
			getFocus("company")
		  	return 0
		}

	msg=company.value
	msg=trim(msg)
	msg=replaceit(msg,"'","''")
	msg=replaceit(msg,"\x22","''")
	company.value=msg
	return 1
}

function validateAddress()
{
	var Address
	Address=document.all("Address")
	if(isEmpty("Address"))
		{
			alert("Address can't left blank")
			getFocus("Address")
			return 0
		}
	if(checkspecial(Address.value,"[/:*?\x22<>|]"))
		{
			alert("should not contain characters  \\/:*?\"<>|")
			getFocus("Address")
		  	return 0
		}
	
	
	msg=Address.value
	msg=trim(msg)
	msg=replaceit(msg,"'","''")
	msg=replaceit(msg,"\x22","''")
	Address.value=msg
	return 1
}

function validateDescription1()
{
	var Description1
	Description1=document.all("Description1")
	if(isEmpty("Description1"))
		{
			alert("Description can't left blank")
			getFocus("Description1")
			return 0
		}
	if(checkspecial(Description1.value,"[/:*?\x22<>|]"))
		{
			alert("should not contain characters  \\/:*?\"<>|")
			getFocus("Description1")
		  	return 0
		}
	
	
	msg=Description1.value
	msg=trim(msg)
	msg=replaceit(msg,"'","''")
	msg=replaceit(msg,"\x22","''")
	Description1.value=msg
	return 1
}

function validateUsername()
{
	var username
	username=document.all("username")
	if(isEmpty("username"))
		{
			alert("User ID can't left blank")
			getFocus("username")
			return 0
		}
	if(checkspecial(username.value,"[/:*?\x22<>|]"))
		{
			alert("should not contain characters  \\/:*?\"<>|")
			getFocus("username")
		  	return 0
		}
	
	
	msg=username.value
	msg=trim(msg)
	msg=replaceit(msg,"'","''")
	msg=replaceit(msg,"\x22","''")
	username.value=msg
	return 1
}
function validatemailto(cnt)
{
	var useremail
	useremail=document.all(cnt)
	if(isEmpty(cnt))
		{
			alert("Email  can't left blank")
			getFocus(cnt)
			return 0
		}
		if(checkspecial(useremail.value,"[/:*?\x22<>|]"))
		{
			alert("should not contain characters  \/:*?\"<>|")
			getFocus(cnt)
		  	return 0
		}
		if(checkspecial(useremail.value,"[^a-zA-Z0-9\x2d\x5F\x40\.]"))
			{
					alert("\n Not a valid E-mail Address")
					getFocus(cnt)
					return 0
			}
		else
			{
				if(!isExist(useremail.value,"@"))
					{
					alert("\n Not a valid E-mail Address")
					useremail.focus()
					return 0
					}
		
			}
	
	return 1
}

function validateEmail()
{
	var Email
	Email=document.all("Email")
	if(isEmpty("Email"))
		{
			alert("Email  can't left blank")
			getFocus("Email")
			return 0
		}
		if(checkspecial(Email.value,"[/:*?\x22<>|]"))
		{
			alert("should not contain characters  \/:*?\"<>|")
			getFocus("Email")
		  	return 0
		}
		if(checkspecial(Email.value,"[^a-zA-Z0-9\x2d\x5F\x40\.]"))
			{
					alert("\n Not a valid E-mail Address")
					getFocus("Email")
					return 0
			}
		else
			{
				if(!isExist(Email.value,"@"))
					{
					alert("\n Not a valid E-mail Address")
					Email.focus()
					return 0
					}
		
			}
	
	return 1
}

function validatealtemail()
{
	var altemail
	altemail=document.all("altemail")
	if(!isEmpty("altemail"))
		{
			if(checkspecial(altemail.value,"[/:*?\x22<>|]"))
			{
			alert("should not contain characters  \\/:*?\"<>|")
			getFocus("altemail")
			return 0
			}
		if(checkspecial(altemail.value,"[^a-zA-Z0-9\x2d\x5F\x40\.]"))
			{
					alert("\n Not a valid E-mail Address")
					altemail.focus()
					return 0
			}
		else
			{
				if(!isExist(altemail.value,"@"))
					{
					alert("\n Not a valid E-mail Address")
					altemail.focus()
					return 0
					}
		
			}
		}
	
	return 1
}
function validatewebsite()
{
	var website
	website=document.all("website")
	if(!isEmpty("website"))
		{
			if(checkspecial(website.value,"[*?\x22<>|]"))
			{
			alert("should not contain characters  *?\"<>|")
			getFocus("website")
			return 0
			}
		}
	
	return 1
}


function validatecuseremail()
{
	var cuseremail
	cuseremail=document.all("cuseremail")
	if(isEmpty("cuseremail"))
		{
			alert("Confirm Email  can't left blank")
			getFocus("cuseremail")
			return 0
		}
	if(cuseremail.value!=document.all("useremail").value)
		{
			alert("Confirm Email  is not Same !!")
			getFocus("cuseremail")
			return 0
		}
	return 1
}

function validateconfirmpassword()
{
	var cuserpassword
	cuserpassword=document.all("cuserpassword")
	if(isEmpty("cuserpassword"))
		{
			alert("Confirm Password can't left blank")
			getFocus("cuserpassword")
			return 0
		}
	if(cuserpassword.value!=document.all("userpassword").value)
		{
		alert("Confirm Password is not same !!")
		getFocus("cuserpassword")
	  	return 0
		}

	return 1
}

function validateuserpassword()
{
	var userpassword
	userpassword=document.all("userpassword")
	if(isEmpty("userpassword"))
		{
			alert("userpassword can't left blank")
			getFocus("userpassword")
			return 0
		}
	if(checkspecial(userpassword.value,"[/:*?\x22<>|]"))
		{
		alert("userpassword should not contain characters  \\/:*?\"<>|")

		getFocus("userpassword")
	  	return 0
		}
		var passlength
		passlength=userpassword.value

	if(passlength.length <6)  
		{
		alert("Password should be between 6 and 12 characters")
		getFocus("userpassword")
		return 0
		}
	if(passlength.length > 12) 
		{
		alert("Password should be between 6 and 12 characters")
		getFocus("userpassword")
		return 0
		}
		
	return 1
}
function validateCountry()
{
	var Country
	Country=document.all("Country")
	if(!isEmpty("Country"))
		{
		if(checkspecial(Country.value,"[/:*?\x22<>|]"))
			{
			alert("Country should not contain characters  \\/:*?\"<>|")
			getFocus("Country")
		  	return 0
			}
		}
	return 1
}

function validateCity()
{
	var City
	City=document.all("City")
	if(!isEmpty("City"))
		{
		if(checkspecial(City.value,"[/:*?\x22<>|]"))
			{
			alert("City should not contain characters  \\/:*?\"<>|")
			getFocus("City")
		  	return 0
			}
		}
	return 1
}
function validateState()
{
	var State
	State=document.all("State")
	if(!isEmpty("State"))
		{
		if(checkspecial(State.value,"[/:*?\x22<>|]"))
			{
			alert("State should not contain characters  \\/:*?\"<>|")
			getFocus("State")
		  	return 0
			}
		}
	return 1
}

function validatealtcontact()
{
	var altcontact
	altcontact=document.all("altcontact")
	if(!isEmpty("altcontact"))
		{
		if(checkspecial(altcontact.value,"[/:*?\x22<>|]"))
			{
			alert("altcontact should not contain characters  \\/:*?\"<>|")
			getFocus("altcontact")
		  	return 0
			}
		}
	return 1
}

function validateOrganisation()
{
	var Organisation
	Organisation=document.all("Organisation")
	if(!isEmpty("Organisation"))
		{
		if(checkspecial(Organisation.value,"[/:*?\x22<>|]"))
			{
			alert("Organisation should not contain characters  \\/:*?\"<>|")
			getFocus("Organisation")
		  	return 0
			}
		}
	return 1
}

function validatecountry()
{
	var country
	country=document.all("country")
	if(country.options.selectedIndex==0)
		{
			alert("Select a country ")
			getFocus("country")
			return 0
		}
		return 1
}

function validateTelephone()
{
	telephone=document.all("telephone")
	if(isEmpty("telephone"))
		{
		alert("Telephne Number Can't left blank")
		getFocus("telephone")
		return 0
		}
	cstr=telephone.value
	if(checkspecial(cstr,"[^0-9-]"))
		{
		alert("should be numberic Seperated by - if any")
		getFocus("telephone")
	  	return 0
		}
	return 1
}

function validatePhone()
{
	Phone=document.all("Phone")
	if(isEmpty("Phone"))
		{
		alert("Telephne Number Can't left blank")
		getFocus("Phone")
		return 0
		}
	cstr=Phone.value
	if(checkspecial(cstr,"[^0-9-]"))
		{
		alert("should be numberic Seperated by - if any")
		getFocus("Phone")
	  	return 0
		}
	return 1
}

function validateFax()
{
	Fax=document.all("Fax")
	if(!isEmpty("Fax"))
		{
		cstr=Fax.value
		if(checkspecial(cstr,"[^0-9-]"))
			{
			alert("should be numberic Seperated by - if any")
			getFocus("Fax")
	  		return 0
			}
		}
	return 1
}

function validatealtelephone()
{
	alttelephone=document.all("alttelephone")
	if(!isEmpty("alttelephone"))
		{
		cstr=alttelephone.value
		if(checkspecial(cstr,"[^0-9-]"))
			{
			alert("should be numberic Seperated by - if any")
			getFocus("alttelephone")
	  		return 0
			}
		}
	return 1
}

function validateExtension()
{
	extension=document.all("extension")
	if(!isEmpty("extension"))
		{
		cstr=extension.value
		if(checkspecial(cstr,"[^0-9-]"))
			{
			alert("should be numberic Seperated by - if any")
			getFocus("extension")
		  	return 0
			}
		}
	return 1
}


function validatewordlimit()
{
	wordlimit=document.all("wordlimit")
	if(isEmpty("wordlimit"))
		{
		alert("Can't left blank")
		getFocus("wordlimit")
		return 0
		}
	cstr=wordlimit.value
	if(checkspecial(cstr,"[^0-9]"))
		{
		alert("should be integer numberic")
		getFocus("wordlimit")
	  	return 0
		}
	if(parseInt(cstr)>1000)
		{
		alert("should be less then 1000 ")
		getFocus("wordlimit")
	  	return 0
		}
		
		
	return 1
}
function checkspecial(cstr,tocheck)
{
			var regex1
			regex1=new RegExp(tocheck,"gi")
			if(regex1.exec(cstr)==null)
				return false
			else
				return true
			
}



