//////////::::::::FIROZ::::::::::
//reg exp
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

	function space(txt)
		{
			var valspace = new RegExp ("^([A-Za-z]*)$")					/*([A-Za-z]) " +"/s"+"([A-Za-z])*/
			var valnum = new RegExp ("([0-9])")
			var okspace = new RegExp();
			if (valspace.test(txt))
				{
					return true;
				}
				else
				{
					return false;
				}
		}


function valnum(txt)
		{
							/*([A-Za-z]) " +"/s"+"([A-Za-z])*/
			var valnum = new RegExp ("([0-9])")
			var okspace = new RegExp();
			if (valnum.test(txt))
				{
					return true;
				}
				else
				{
					return false;
				}
		}


// ([A-Za-z])+(\s)+([A-Za-z])
//option validation
function validate_option(opt1,alerttxt)
{
		if (opt1.checked ==false)
		{
			display_error(alerttxt)
			return false;
		}
		else
		{ 
			return true;
		}
}



//first name
function validate_name(field_name,alerttxt)
{
	
	with(field_name)
	{
				if (trim(value) =="" /* || isNaN(value)==false*/ || value.length < 2 || valnum(trim(value))/*||!space(value)*/)
							{
		
								display_error (alerttxt);
								return false;
							}
			   else 
				{return true};
			
	}
}

////company
function validate_company(field_company,alerttxt)
{
	
	with(field_company)
	{
				if (trim(value) =="" /* || isNaN(value)==false*/ || value.length < 2 || valnum(trim(value)))
							{
		
								display_error (alerttxt);
								return false;
							}
			   else 
				{return true};
			
	}
}

//////contact person
		function validate_contact_pname(field_name,alerttxt)
{
	
	with(field_name)
	{
				if (trim(value) =="" /* || isNaN(value)==false*/ || value.length < 2 || valnum(trim(value)))
							{
		
								display_error (alerttxt);
								return false;
							}
			   else 
				{return true};
			
	}
}
/////////validate_DOB
function validate_DOB(field_name,alerttxt)
{
	mm=0;dd=0;yy=0;m=0;d=0;yr=0;invalid_date_format=0
with(field_name)
	{

		firstpos=value.indexOf("/")
		lastpos=value.lastIndexOf("/")
		
		
		if(trim(value) =="")
		{
			invalid_date_format=1
				display_error (alerttxt);
			return false
		}
		else if((firstpos != 2 )|| (lastpos !=5))
		{
			invalid_date_format=1
				display_error (alerttxt);
			return false
		}

		mm=value.charAt(0) + value.charAt(1)
		dd=value.charAt(3) + value.charAt(4)
		yy=value.charAt(6)  + value.charAt(7) + value.charAt(8) + value.charAt(9)

		
		if(mm>12)
		{
			m=1
		}
		if(mm==2)
		{
			if((yy%4)==0)
			{
				if(dd>30)
				{
					d=1
				}
			}
			else
			{
				if(dd > 29)
					d=2
			}
		}
		if(dd >31)
		{
			d=3
		}

		if((yy < 1910) || (yy >2008))
		{
			yr=1
		}
		if(m==1 || d==1|| d==2 || yr ==1 || invalid_date_format==1)
		{
			display_error (alerttxt);
			return false
		}
		else
			return true
	}

}

////////pob   
function validate_POB(field_name,alerttxt)
{
	
	with(field_name)
	{
				if (trim(value) =="" /* || isNaN(value)==false*/ || value.length < 2 || valnum(trim(value)))
							{
		
								display_error (alerttxt);
								return false;
							}
			   else 
				{return true};
			
	}
}

//////validate occupation   
function validate_occ(field_name,alerttxt)
{
	//alert("entered into occ");
	with(field_name)
	{
				if (trim(value) =="" /* || isNaN(value)==false*/ || value.length < 2 || valnum(trim(value)))
							{
		
								display_error (alerttxt);
								return false;
							}
			   else 
				{return true};
			
	}
}

//////validate qual
function validate_qual(field_name,alerttxt)
{
	
	with(field_name)
	{
				if (trim(value) =="" /* || isNaN(value)==false*/ || value.length < 2 || valnum(trim(value)))
							{
		
								display_error (alerttxt);
								return false;
							}
			   else 
				{;return true};
			
	}
}


//alert("hiii");
//telephone number
function validate_contact(field_tnum,alerttxt)
{
		//alert ("enterd into tel");
	with(field_tnum)
	{
		if(value=="" || isNaN(value)==true|| value.length < 2)
		{
		display_error(alerttxt);
		return false;
		}
		else 
		{return true};
	}	
		
}
////////contact time
function validate_contact_timing(field_name,alerttxt)
{
	//alert("hiiii");
	with(field_name)
	{
				if (trim(value) =="" /* || isNaN(value)==false*/ || value.length < 2 || space(trim(value)))
							{
		
								display_error (alerttxt);
								return false;
							}
			   else 
				{return true};
			
	}
}
////////address  

function validate_address(field_name,alerttxt)
{
	
	with(field_name)
	{
				if (trim(value) =="" /* || isNaN(value)==false*/ || value.length < 10 || space(trim(value)))
							{
									if(value.length<10)
								{
										display_error("Address shoul be more than 10 charcters.");
										return false;
								}
								if(space(trim(value)))
								{
									display_error("Please enter address in more than two words.");
									return false;
								}
		
								display_error (alerttxt);
								return false;
							}
			   else 
				{return true};
			
	}
}

/////////length 
function alphanum(field)
		{  //display_error("hehehha");  alert("hi");
			var eval=new RegExp(("/^([a-zA-Z0-9]+)$/"));
			if(eval.test(field)==true)
			{ 
				return true;
			}
			else
			{ 
				return false;
			}
		}

function validate_length(field_tnum,alerttxt)
{
		//alert ("hiii");
	with(field_tnum)
	{
		
		if(value=="" || alphanum(field_tnum)==true || value.length < 1)
		{
		display_error(alerttxt);
		return false;
		}
		else 
		{return true};
	}	
		
}


////////////////////dances 
function validate_history(field_name,alerttxt)
{
	
	with(field_name)
	{
				if (trim(value) =="" /* || isNaN(value)==false*/ || value.length < 2 || space(trim(value)))
							{
									if(value.length<2)
								{
										display_error("Please enter Details in more than two characters.");
										return false;
								}
								if(space(trim(value)))
								{
									display_error("Please enter Details in more than two words.");
									return false;
								}
		
								display_error (alerttxt);
								return false;
							}
			   else 
				{return true};
			
	}
}

//////validate_landmark
function validate_landmark(field_name,alerttxt)
{
	//alert ("hii..");
	with(field_name)
	{
				if (trim(value) =="" /* || isNaN(value)==false*/ || value.length < 5)
							{
		
								display_error (alerttxt);
								return false;
							}
			   else 
				{return true};
			
	}
}



/////choreo    
function validate_choreo(field_name,alerttxt)
{
	
	with(field_name)
	{
				if (trim(value) =="" /* || isNaN(value)==false*/ || value.length < 2 || space(trim(value)))
							{
					if(value.length<2)
								{
										display_error("Please enter choreographer details in more than two characters.");
										return false;
								}
								if(space(trim(value)))
								{
									display_error("Please enter choreographer details in more than two words.");
									return false;
								}
		
								display_error (alerttxt);
								return false;
							}
			   else 
				{return true};
			
	}
}


//////////validate_participants
function validate_participants(field_tnum,alerttxt)
{
		
	with(field_tnum)
	{
		if(value=="" || isNaN(value)==true|| value.length < 0)
		{
		display_error(alerttxt);
		return false;
		}
		else 
		{return true};
	}	
		
}

//////////validate_micro
function validate_micro(field_tnum,alerttxt)
{
		
	with(field_tnum)
	{
		if(value=="" || isNaN(value)==true|| value.length < 0)
		{
		display_error(alerttxt);
		return false;
		}
		else 
		{return true};
	}	
		
}
//gender
/*function validate_gender(field_gen1,alerttxt)
{ alert(field_gen1)
alert(field_gen1.checked)
		if (field_gen1.checked == false)
		{  alert("checked")
			display_error(alerttxt)
			return false;
		}
		else
		{ 
			return true;
		}
}*/

function validate_option(field_gen1,alerttxt)
{ 
	var flag=0

	for(var i=0;i<field_gen1.length;i++)
 {
   if(!field_gen1[i].checked)
   {
     flag++;
	 continue;
   }
 }
 if(flag>1)
	{
	 display_error(alerttxt)
		 return false;
	}
	else
	{
		return true;
	}

}

/////////////validate_act
function validate_act(field_name,alerttxt)
{
	
	with(field_name)
	{
				if (trim(value) =="" /* || isNaN(value)==false*/ || value.length < 2 || space(trim(value)))
							{
					if(value.length<2)
								{
										display_error("Please enter description of act details in more than two characters.");
										return false;
								}
								if(space(trim(value)))
								{
									display_error("Please enter description of acts details in more than two words.");
									return false;
								}
		
								display_error (alerttxt);
								return false;
							}
			   else 
				{return true};
			
	}
}

//date
function validate_date(fd,fm,fy,alerttxt)
{
if(document.getElementById("date1").selectedIndex==0 || document.getElementById("month1").selectedIndex==0 || document.getElementById("year1").selectedIndex==0 )
		{
		display_error(alerttxt);
		return false;
		}
		else 
		{return true};
	}	
		









//email validation
function validate_email(field,alerttxt)
{
//alert("hiii");
	with (field)
		{
			apos=value.indexOf("@");
			aapos=value.lastIndexOf("@");
			dotpos=value.lastIndexOf(".");
			var eval= new RegExp("^([a-zA-Z0-9]+)(.*)(_*)([a-zA-Z0-9]+)(@+)([a-zA-Z0-9]+)(.+)([a-zA-Z]+)$")

if (apos<1||dotpos-apos<2|| value.length < 6 ||apos!=aapos||eval.test(trim(value))==false) 
  {alert(alerttxt);return false;}
else {return true;}
}
}




////////trying error list...
function display_error(errorlist)
	{alert(errorlist);	}
 


function validate_form(thisform)
{
	//alert("entered");
	
   with(thisform)
   {
		
		//name
		if(validate_name(name,"Enter Name")==false)
				{	name.focus();
					return false;
				}

		///contact number
			if(validate_contact(Contact,"Enter Proper Telephone Number")==false)
				{	Contact.focus();
					return false;
				}
		/////////email
			if(validate_email(Email,"Enter Valid Email")==false)
				{	Email.focus();
					return false;
				}
		//history 
		if(validate_name(country,"Enter country")==false)
				{	country.focus();
					return false;
				}
		
   }
}

function validate_chkitems()
{
	flag = 0
	//alert(document.makeenq.chkitem.length)
	for(var i=0; i < document.makeenq.chkitem.length; i++)
		{
			
		if(document.makeenq.chkitem[i].checked)
		{
			//alert(document.makeenq.chkitem[i].value)
			flag = flag + 1
		}
		}
		if(flag >= 0)
		{
			return true;
		}
		else
		{
			return false;
		}

}






