/* 
Return true is string is empty (null , "     " )
*/
function Isempty(s)
{
	var regexpWhitespace = /^\s+$/;
	return  ((s == null) || (s.length == 0) || regexpWhitespace.test(s));
}
/*
To check Alpha Numeric
*/
function IsAlphaNum(s)
{
	var validChars = /^[\w\s]+$/;
	return validChars.test(s);
}
/*
To check Alpha 
*/
function IsAlpha(s) {
	var regexpAlphabetic = /^[a-zA-Z\s]+$/; // Add ' and - ?
	return regexpAlphabetic.test(s);
}
/*
To check Date 
*/
function IsDate(s) {
	var testDate = new Date(s);
	return !isNaN(testDate);
}
/*
To check Isemail
*/
function IsEmail(s) {
	var regexpEmail = /\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
	return regexpEmail.test(s);
}
/*
To check Integer 
*/
function IsInteger(s){
	var regexp = /^[+]?\d+$/;
	return regexp.test(s);
}
/*
To check Is float  
*/
function IsFloat(s) {		
	return !isNaN(parseFloat(s));
}
/*  
To ask for confirmation Image 
*/
function confirmmsg(msg)
{
	if(confirm(msg))
	{	return true; 	}
	else
	{	return false;	}
}
/* 
To show Hide block
*/
function showhide(obj1,obj2,condition)
{
	if(obj1 == 'Yes'){
		obj2.style.display='';
		taxdetails.style.display='';
	}
	else{
		obj2.style.display='none';
		taxdetails.style.display='none';
	}
}
/* 
To show Hide Tax detail block
*/
function showhidetaxdata(obj1,obj2,obj3,condition)
{
	if(obj1 == 'Yes' && obj2 == 'Yes'){
		obj3.style.display='';		
	}
	else{
		obj3.style.display='none';
	}
}
/*
To Validate Key Tags 
*/
function  ValidateKeytag(Key1,Key2)
{
	var k1 = Key1.value;
	if(Isempty(k1)){
		alert("StartKeytag is required.");
		Key1.focus();
		return false;
	}
	else if(k1.length < 10)	{
		alert("Enter Valid 10 digit StartKeytag.");
		Key1.focus();
		return false;
	}
	else if(!IsAlphaNum(k1.substring(0,2))){
		alert("Enter Valid  AlphaNumeric StartKeytag's First 2 lettres.");
		Key1.focus();
		return false;
	}
	else if(!IsInteger(k1.substring(2))){
		alert("Enter Valid  Numeric StartKeytag's Last 8 lettres.");
		Key1.focus();
		return false;
	}
	if(Key2){
		var k2 = Key2.value;
		if(Isempty(k2)){
			alert("EndKeytag is required.");
			Key2.focus();
			return false;
		}
		else if(k2.length < 10)	{
			alert("Enter Valid 10 digit EndKeytag.");
			Key2.focus();
			return false;
		}
		else if(!IsAlphaNum(k2.substring(0,2))){
			alert("Enter Valid  AlphaNumeric StartKeytag's First 2 lettres.");
			Key2.focus();
			return false;
		}
		else if(!IsInteger(k2.substring(2))){
			alert("Enter Valid  Numeric EndKeytag's Last 8 lettres.");
			Key2.focus();
			return false;
		}
		else if	(k2.length < 10){
			alert("Enter Valid 10 digit EndKeytag.");
			Key2.focus();
			return false;
		}
	}
}
/*
To Validate Inventory Surch Options
*/
function validatesearch(Key1)
{
	var k1 = Key1.value;
	if(Isempty(k1)){
		alert("Search For is required.");
		Key1.focus();
		return false;
	}
	else if(!IsAlphaNum(k1)){
			alert("Enter Valid Search For Option.");
			Key1.focus();
			return false;
	}
	return true;
}
/*
*To Assign values .... from one block to another ....
*(Required) Arrfrom = Copy data from this Array Objects
*(Required) Arrto = Copy data to this Array Objects
*(Optional) Obj = Check-box object
*/
function Assignblock(Arrfrom,Arrto,Obj)
{
	if(Arrfrom.length == Arrto.length)
	{
		if(Obj &&!Obj.checked)
		{
			for (i=0; i < Arrfrom.length ; i++) 
			{
				var to = document.getElementById(eval('Arrto[i]'));
				to.value='';
			}
		}
		else
		{
			for (i=0; i < Arrfrom.length ; i++) 
			{
				var from = document.getElementById(eval('Arrfrom[i]'));
				var to = document.getElementById(eval('Arrto[i]'));
				to.value=from.value;
			}
		}
	}
}
/* 
*Alternate state of check boxes. 
*/
function Altercheck(check1,check2)
{
	if(check1 && check1.checked)
	{
		check2.checked=false;
	}

}