function chkempty(obj,message)
{
	if (obj.value < 1) // checking for empty field 
		{
			alert(message);
			return false;            
		}
	return true;
}
function chkComboEmpty(obj,message)
{
	if(obj.selectedIndex == 0)
	{
		alert(message);
		return false;
	}
	return true;
}
function chkNumericValue(obj,message)
{
   
	if(isNaN(obj.value))
	{
		 alert(message);
		 return false;
	}
	return true; 
}
function chkEmail(obj,message)
{
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(obj.value) == false) 
   {
	  alert(message);
	  return false;
   }

}
function chkNumeric(obj)
{
	if(isNaN(obj.value))
	{
		alert("Please enter numeric value only.");
		return false; 
	}
}

function chekImageExt(fileName,message)
{   
	if (!(fileName.value < 1))
	{
		var objRule = /^(\S*.jpeg)$|^(\S*.jpg)$|^(\S*.JPG)$|^(\S*.gif)$|^(\S*.GIF)$|^(\S*.bmp)$|^(\S*.BMP)$|^(\S*.PNG)$|^(\S*.png)$|^(\S*.JPEG)$/;
		//var objRule = /^(\*.jpeg)$|^(\*.jpg)$|^(\*.gif)$|^(\*.bmp)$|^(\*.JPEG)$/;
		var str;
		var str1;
		var lvarfile;
		str = fileName.value;
		pos = str.lastIndexOf("\\");
		lvarfile = str.substring(pos+1);
		lvarfile = lvarfile.replace(/ /g,"") //remove space 
		if (objRule.test(lvarfile))
		{
				return true;
		}
		else
		{
				alert(message);
				return false;
		}    
	}
}

function chekFlashExt(fileName,message)
{   if (!(fileName.value < 1))
	{
		var objRule = /^(\S*.SWF)$|^(\S*.swf)$/;
		//var objRule = /^(\*.jpeg)$|^(\*.jpg)$|^(\*.gif)$|^(\*.bmp)$|^(\*.JPEG)$/;
		var str;
		var str1;
		var lvarfile;
		str = fileName.value;
		pos = str.lastIndexOf("\\");
		lvarfile = str.substring(pos+1);
		lvarfile = lvarfile.replace(/ /g,"") //remove space 
		if (objRule.test(lvarfile))
			{
				return true;
			}
		else
			{
				alert(message);
				return false;
			}    
	}
} 


function chekFLVExt(fileName,message)
{   
	if (!(fileName.value < 1))
	{
		var objRule = /^(\S*.FLV)$|^(\S*.flv)$/;
		//var objRule = /^(\*.jpeg)$|^(\*.jpg)$|^(\*.gif)$|^(\*.bmp)$|^(\*.JPEG)$/;
		var str;
		var str1;
		var lvarfile;
		str = fileName.value;
		pos = str.lastIndexOf("\\");
		lvarfile = str.substring(pos+1);
		lvarfile = lvarfile.replace(/ /g,"") //remove space 
		if (objRule.test(lvarfile))
			{
				return true;
			}
		else
			{
				alert(message);
				return false;
			}    
	} 
}         


function IsValidTime(timeStr) 
{
  
// Checks if time is in HH:MM:SS AM/PM format.
// The seconds and AM/PM are optional.

	//var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
	var timePat = /^(\d{1,2}):(\d{2})$/;

	var matchArray = timeStr.match(timePat);
	if(matchArray == null)
	{
		//alert("Time is not in a valid format.Please Specify Time in hh:mm AM/PM Format Only.");
		alert("Time is not in a valid format.Please Specify Time in hh:mm  Format Only.");
		return false;
	}
	hour = matchArray[1];
	minute = matchArray[2];
   //	second = matchArray[4];
   //	ampm = matchArray[6];

  //	if (second=="") { second = null; }
   //	if (ampm=="") { ampm = null }

	if (hour < 0  || hour > 24) {
	alert("Hour must be between 1 and 24.");
	return false;
	}
   /*	if (hour <= 12 && ampm == null) 
	{
	
	alert("You must specify AM or PM.");
	return false;
	
	}*/
	if (minute<0 || minute > 59) {
	alert ("Minute must be between 0 and 59.");
	return false;
	}
	/* if (second != null && (second < 0 || second > 59)) {
	alert ("Second must be between 0 and 59.");
	return false;
	} */
   
}
function openPopUp()
{
	
}   
function contactvalidation()
{
	var obj;
	var flag;
	obj = document.getElementById("txtCPName");
	flag =   chkempty(obj,"Please do not leave the field blank. -- Your Name");
	if(flag == false)
	{
		obj.focus();
		return false;
	}
	
	obj = document.getElementById("txtCompayAddress");
	flag =   chkempty(obj,"Please do not leave the field blank. -- Address");
	if(flag == false)
	{
		obj.focus();
		return false;
	}
	
	
	obj = document.getElementById("txtCityName");
	flag =   chkempty(obj,"Please do not leave the field blank. -- City");
	if(flag == false)
	{
		obj.focus();
		return false;
	}
	
	
	obj = document.getElementById("txtStateName");
	flag =   chkempty(obj,"Please do not leave the field blank. -- State");
	if(flag == false)
	{
		obj.focus();
		return false;
	}
	
	obj = document.getElementById("txtCountryName");
	flag =   chkempty(obj,"Please do not leave the field blank. -- Country");
	if(flag == false)
	{
		obj.focus();
		return false;
	}
	
	obj = document.getElementById("txtPhone");
	if(obj.value == "")
	{
		var obj2 = document.getElementById("txtMobile");
		flag =   chkempty(obj2,"Either Phone or Mobile should not be blank.");
		if(flag == false)
		{
			obj.focus();
			return false;
		}
	}
	else
	{
		if(isNaN(obj.value))
		{
			alert("Please enter numeric values only. -- Phone");
			obj.focus();
			return false;
		}
	}
	
	var obj2 = document.getElementById("txtMobile");
	if(obj2.value != "")
	{
		if(isNaN(obj2.value))
		{
			alert("Please enter numeric values only. -- Mobile");
			obj2.focus();
			return false;
		}
		else
		{
			if(obj2.value.length != 10)
			{
				alert("Please enter valid mobile no.");
				obj2.focus();
				return false;
			}
		}
	}
	
	obj = document.getElementById("txtEmail");
	flag =   chkempty(obj,"Please do not leave the field blank. -- E-mail");
	if(flag == false)
	{
		obj.focus();
		return false;
	}
	else
	{
		flag =  chkEmail(obj,"Please enter valid email address. -- E-mail");
		if(flag == false)
		{
			obj.focus();
			return false;
		}
		
	}
	obj = document.getElementById("txtComments");
	if(obj.value == "")
	{
		alert("Please do not leave the field blank. -- Your Message");
		obj.focus();
		return false;
	}
	return true;
}


