/* use as general function reference */

function Len(me){
    var lValue = Trim(me.value);
    
    return lValue.length;
}

function Trim(str){
   return str.replace(/^\s*|\s*$/g,"");
}

//onKeyPress="return keyRestrict(event,'1234567890');"
function getKeyCode(e){
	if (window.event)
	   return window.event.keyCode;
	else if (e)
	   return e.which;
	else
	   return null;
}
function keyRestrict(e, validchars){ 
	var key='', keychar='';
	key = getKeyCode(e);
	if (key == null) return true;
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	validchars = validchars.toLowerCase();
	if (validchars.indexOf(keychar) != -1)
		return true;
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
		return true;
	return false;
}

function PhoneFormat(me){
	if (me.value.length > 0) {
		var tValue = me.value.replace(new RegExp("-", "gi"), "");
		
		tValue = tValue.substring(0, 3) + '-' + tValue.substring(3, 6) + '-' + tValue.substring(6);
		me.value = tValue;
	}
}

//valid = true
function CheckEmail(email){
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) {
		return true
	}	
	return (false)
}

function SetCookie(name, value){
    var exp = new Date();
    
    exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 30));    
	document.cookie = name + "=" + value + "; path=/" + ((exp == null) ? "" : "; expires=");
}

function GetCookie(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	
	for(var i = 0; i < ca.length; i++) {
		var c = ca[i];
		
		while (c.charAt(0) == " ") c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
	
	return null;
}

function DelCookie(name){
    document.cookie = name + "=; path=/; expires=Thu, 01-Jan-70 00:00:01 GMT"; 
}

function GetActiveRadio(formName, radioName){
	var rdButton = document.forms[formName].elements[radioName];
	
	for (cntr = 0; cntr < rdButton.length; cntr++)
	{
		if (rdButton[cntr].checked) {
			return rdButton[cntr].value;
		}
	}
}

function checkAll(form,id){

	var chkCareer = document.forms[myform].elements[myid];
	//var dvCheckAll = document.getElementById("dvCheckAll");
	//var chkAll = document.getElementById("chkAll");
	
	for (cntr = 0; cntr < chkCareer.length; cntr++)
	{
		chkCareer[cntr].checked = true;
	}	
}

function uncheckAll(form,id){

var chkCareer = document.forms[myform].elements[myid];
	//var dvCheckAll = document.getElementById("dvCheckAll");
	//var chkAll = document.getElementById("chkAll");
	
	for (cntr = 0; cntr < chkCareer.length; cntr++)
	{
		chkCareer[cntr].checked = false;
	}
}

function logout(){
    if(confirm ("Are you sure you want to logout?")){
		return true
	}
}

//onkeyup="count_chars(frm,msg,cntr,len);"
//frm=form,msg=textarea,cntr=counter,mylen=lenght
function count_chars(frm,msg,cntr,mylen){

	var myForm = document.frm;
	var meseg = myForm.msg;
		counter = meseg.value
		left = (mylen - (counter.length))
   alert(mylen)
	if ( left < 0 ) { 
		myForm.cntr.value = 0 
		meseg.value = meseg.value.substr(0,mylen) 
	} else { 
		myForm.cntr.value = left 
	}
  
}

function bookmarksite(){
var myloc = location.href;
var title = "Cantwell’s Market & Deli - Summerland I State Street I Figueroa";
// check if active
// alert (title+"\r\n"+myloc);
if (document.all)
  window.external.AddFavorite(myloc,title);
else if (window.sidebar)
  window.sidebar.addPanel(title, myloc,"");
}
