function checkAll(frm,checked)
{
	var a=frm['items'].length
	for(var i=0;i<frm['items'].length;i++)
	  {  
		 	var e = frm.items[i];
			if(e.type == "checkbox") 
					e.checked = checked;
	  } 
}
function SetAction(action,frm)
	{
	    var i=0;
	    var check=false;
        if(frm['items'].length){
		for(i=0;i<frm['items'].length;i++)
		{
	    	 if(frm.items[i].checked==true)	
			  {
			  	 check=true;
			     break;	
			   } 	   	
		}	}
		else 
		{
				if(frm.items.checked==true)
					check=true;
		}
		
	   if(check==false)
		  document.getElementById("Error").innerHTML="Error : Please check any checkbox before continue!<br /><br />";
		else
		{
		    frm.Action.value=action;
			var conf=confirm('Are you sure to want to '+action+' selected?');
			if(conf)
				frm.submit();
		}	
	}


function isValidEmail(emailid)	// Email Validation
{		
var email=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	return email.test(emailid);
}


function isValidURL(url_name)    	// URL Validation
	{
	var url_format=/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/;
	return url_format.test(url_name);
	}
// Alpha Numeric Validation
function isAlphaNumeric(str)	// Returns true if string only contains characters A-Z, a-z or 0-9

{
  var re = /[^a-zA-Z0-9]/g
	  return (re.test(str));
}
function isNumeric(str) //Numeric Validation
{
  var re = /[\D]/g
	  return (re.test(str));
}

function isWhiteSpaceOnly(str)	// Cannot check a password type input for whitespace
{
  var re = /[\S]/g
  return (re.test(str))
}

//illegal characters
function isIllegalChars(strng)
{
var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
	return (strng.match(illegalChars));
}

//Phone Validation
function isValidPhoneNo(strng)
{
//strip out acceptable non-numeric characters
var stripped = strng.replace(/[\(\)\.\+\-\ ]/g, '');
	return !isNaN(stripped);
}

//Open popUpWindow
var pop='';
function openwin(nm,width,height,w_per,h_per)
{
	var name=nm;
	var screen_h=window.screen.height;
	var screen_w=window.screen.width;
	var x_cor=parseInt((w_per/100)*screen_w);
	var y_cor=parseInt((h_per/100)*screen_h);
if (pop && !pop.closed)
			pop.close();

pop=eval("window.open('"+name+"','NewWIN','chrome[4],toolbar=no,left=5,top=5,width="+width+",height="+height+",directories=no,menubar=no,SCROLLBARS=yes,left='+x_cor+',top='+y_cor+'')");
	
pop.moveTo(x_cor,y_cor);

if (!pop.opener)
	popUpWin.opener = self;
	
if(window.focus)
		pop.focus();
}

/*************Validate the forms--------------------------------------*/
function check(frm, fld_arr)
{
	var msg=Array();
    var count=0;

	for (var word in fld_arr)
    {
		 if(frm[word].value=="")
		 {
			if(count==0) 
				frm[word].focus(); 
			 msg[count] = fld_arr[word];		
    		 count++;
          } 	
	} 

	return msg;
}

function display_message(arr_msg)
{	
	var msg='Please review the following error message before continue:<br>';
	for (var word in arr_msg)
    {
		msg+="&bull; "+arr_msg[word]+'<br>';
	}
	msg+="<br>";
	return msg;
}
function ShowSubMenu(v,img)
 {
var div=document.getElementById(v);
var img=document.getElementById(img);
	
		var aDiv=document.getElementsByTagName("img");
		for(var i=0;i<aDiv.length;i++)
		{
		if(aDiv[i].id.indexOf('img')>=0)
			{
		if(aDiv[i].id==img.id)
			{
			aDiv[i].src="images/down-arrow.gif";
			}
			else
			{
			aDiv[i].src="images/arrow1.gif";
			}
			}
		}
if(div!=null)
		{
			if(div.style.display=="none")
			{
				div.style.display="";
				img.src="images/down-arrow.gif";
				
			}
			else
			{
				div.style.display="none";
				img.src="images/arrow1.gif";
			}
		}
		
		var aDiv=document.getElementsByTagName("tr");
		for(var i=0;i<aDiv.length;i++)
		{
			if(aDiv[i].id!=v && aDiv[i].id.indexOf('menu')>=0)
			{
				aDiv[i].style.display="none";
			}
		}
}
//-----------------funtion to open URL--------------------------------------
var please_wait = null;
function open_url(url, target)
{

if ( ! document.getElementById) {
  		return false;
 	}

 	if (please_wait != null) {
  		document.getElementById(target).innerHTML = please_wait;
 	}

 	if (window.ActiveXObject) {
  		link = new ActiveXObject("Microsoft.XMLHTTP");
 	} else if (window.XMLHttpRequest) {
  		link = new XMLHttpRequest();
 	}

 	if (link == undefined) {
  		return false;
 	}
 	link.onreadystatechange = function() { response(url, target); }
 	link.open("GET", url, true);
 	link.send(null);
}

function response(url, target) {
 	if (link.readyState == 4) {
	 	document.getElementById(target).innerHTML = (link.status == 200) ? link.responseText : "" + link.status;
	}
}

function set_loading_message(msg) {
 	please_wait = msg;
}
