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 '+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)
{
	//alert("hello");
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 : "Ooops!! A broken link!" + link.status;
	}
}

function set_loading_message(msg) {
 	please_wait = msg;
}


///######## contact us  form validation #######

function is_email(email)
	{
		if(!email.match(/^[A-Za-z0-9\._\-+]+@[A-Za-z0-9_\-+]+(\.[A-Za-z0-9_\-+]+)+$/))
			return false;
		return true;
	}

function is_empty(str)
	{
  		 str=trim(str);
		 if ((str.length==0)||(str==null))
			return true;
		 return false;
	}

	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 == " ") { // 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 is_number(number)
	{
		if(!number.match(/^[\-\+0-9e1-9]+$/))
			return false;
		return true;
	}

function is_alpha(str)
	{
		if(!str.match(/^[A-Za-z ]+$/))
			return false;
		return true;
	}

//Phone Validation
function isValidPhoneNo(strng)
{
//strip out acceptable non-numeric characters
var stripped = strng.replace(/[\(\)\.\+\-\ ]/g, '');
	return !isNaN(stripped);
}

//##  contact us form validation ####/
function validation()
{
    if(is_empty(document.ContactForm.name.value))
	{
     document.ContactForm.name.value="";  
     alert("Please enter your name.");
	 document.ContactForm.name.focus();
	 return false;

	}
	
	if(!is_alpha(document.ContactForm.name.value))
	{
	 document.ContactForm.name.value="";  
     alert("Please enter a valid name.");
	 document.ContactForm.name.focus();
	 return false;
	}
	
    if(is_empty(document.ContactForm.email.value))
	{
	 document.ContactForm.email.value="";
     alert("Please enter your email address.");
	 document.ContactForm.email.focus();
	 return false;
	}

	if(!is_email(document.ContactForm.email.value))
	{
     alert("Please enter a valid email address.");
	 document.ContactForm.email.focus();
	 return false;

	}
	
	if(is_empty(document.ContactForm.address.value))
	{
	 document.ContactForm.address.value="";
     alert("Please enter your address.");
	 document.ContactForm.address.focus();
	 return false;
	}
	
	if(is_empty(document.ContactForm.question.value))
	{
	 document.ContactForm.question.value="";
     alert("Please enter your questions.");
	 document.ContactForm.question.focus();
	 return false;
	}

}
//##  spacial offer validation us form validation ####/
function validationoffer()
{
    if(is_empty(document.spacialoffer.name.value))
	{
     document.ContactForm.name.value="";  
     alert("Please enter your name.");
	 document.spacialoffer.name.focus();
	 return false;
	}
	if(!is_alpha(document.spacialoffer.name.value))
	{
	 document.ContactForm.name.value="";  
     alert("Please enter a valid name.");
	 document.spacialoffer.name.focus();
	 return false;
	}
	
    if(is_empty(document.spacialoffer.email.value))
	{
	 document.ContactForm.email.value="";
     alert("Please enter your email address.");
	 document.spacialoffer.email.focus();
	 return false;
	}
	if(!is_email(document.spacialoffer.email.value))
	{
     alert("Please enter a valid email address.");
	 document.spacialoffer.email.focus();
	 return false;
	}
	if(is_empty(document.spacialoffer.phone.value))
	{
	 document.spacialoffer.phone.value="";
     alert("Please enter your phone no.");
	 document.spacialoffer.phone.focus();
	 return false;
	}
	if(is_empty(document.spacialoffer.address.value))
	{
	 document.spacialoffer.address.value="";
     alert("Please enter your address.");
	 document.spacialoffer.address.focus();
	 return false;
	}
	if(is_empty(document.spacialoffer.address.value))
	{
	 document.spacialoffer.city.value="";
     alert("Please enter your city.");
	 document.spacialoffer.city.focus();
	 return false;
	}
	if(is_empty(document.spacialoffer.state.value))
	{
	 document.spacialoffer.state.value="";
     alert("Please enter your state.");
	 document.spacialoffer.state.focus();
	 return false;
	}
	if(is_empty(document.spacialoffer.zip.value))
	{
	 document.spacialoffer.zip.value="";
     alert("Please enter your address.");
	 document.spacialoffer.zip.focus();
	 return false;
	}
}
