function _$(element) {
  if (typeof element == 'string')
    element = document.getElementById(element);
  return (element);
}

function hide(id){
	_$(id).style.display='none';
}

 function showEditorial(editorial){
     var editorialURL = C_BASE_URL + "&page=GenericEditorialPopUp&genericeditorial=" + editorial;
     window.open(editorialURL,'','width=680,height=550,toolbars=no,scrollbars=yes');
  }
function trim(s) {
	while (s.substring(0,1) == ' ') {
		s = s.substring(1,s.length);
	}
	while (s.substring(s.length-1,s.length) == ' ') {
		s = s.substring(0,s.length-1);
	}
	return s;
}
//For Selecting/ deselecting check boxed
function selectDeselect(field, isCheck) {
	var boxes = document.getElementsByName(field);
	var boxes_checked = anyChecked();

	if(isCheck){
		if(document.getElementsByName(isCheck)[0].checked) setChecks(true);
		else setChecks(false);			
	}else{
		if(!boxes_checked) setChecks(true);
		else setChecks(false);
	}

	function setChecks( setting ) {
		for( var i=0; i < boxes.length; i++ ) {
			boxes[ i ].checked = setting;
		}
	}
	function anyChecked() {
		for( var i=0; i < boxes.length; i++ ) {
			if( boxes[i].checked == true) {
				return (true);
			} 
		}
		return (false);
	}
}

function callblankdiv()
{
	document.getElementById('divloading').style.display='none';
}

function showloadingpag()
{
  new Ajax.Updater ('hidshowload', '/common/showloading');
  document.getElementById('divloading').style.display='block';
}

function checkMain(frm){
	var j = 0;
	for(i=0; i < frm.del.length; i++){
		if(frm.del[i].checked){
			j = j + 1;	
		}
	}
	if(frm.del.length != j){
		frm.chkNothing.checked = false;
	}else{
		frm.chkNothing.checked = true;
	}
}

function isAnySelect(form)
{
	varAllId = "";
	if(isdefined(form.del.length))
	{
		for(i=0;i<form.del.length;i++)
		{
			if(form.del[i].checked == true)
			{
				if(varAllId == "")
					varAllId = form.del[i].value
				else
					varAllId += "," + form.del[i].value
			}
		}
		if(varAllId == "")
			return false
		else
		{
			form.chkNothing.value = varAllId
			return true
		}
	}
	else
	{
		return form.del.checked;
	}
}

function openpopup(url){	
	window.open( url, "myWindow","status = 1, height = 300, width = 300, resizable = 0" );
}

function openpopup_windowvista(url){	
	window.open( url, "myWindow","status = 1, height = 500, width = 800, resizable = 0" );
}
//For checking Null values
function isNull(aStr)
{
	var index;		
	for (index=0; index < aStr.length; index++)
		if (aStr.charAt(index) != ' ')
			return false;
	return true;
}

//For checking invalid E-Mail address

function isEmail(aStr){
	var reEmail=/^[0-9a-zA-Z_\.-]+\@[0-9a-zA-Z_\.-]+\.[0-9a-zA-Z_\.-]+$/;
	if(!reEmail.test(aStr))
	{
		return false;
	}
	return true;
}

//Removing the newline character
function countChars(str){
	var reg = new RegExp("[\f\n\r\v]*","g");
	str = str.replace(reg,"");
	return str.length;   
}

function trim(s) {
	while (s.substring(0,1) == ' ') {
		s = s.substring(1,s.length);
	}
	while (s.substring(s.length-1,s.length) == ' ') {
		s = s.substring(0,s.length-1);
	}
	return s;
}

function isdefined(variable){
	//return (typeof(window[variable]) == "undefined")?  false: true;
	return (typeof(variable) == "undefined")?  false: true;
}  

function alphanumeric(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		  {
		  }
		else	{
			 return false;
		  }
		}
 return true;
}

 

function au(id, selid) {
	var _id = $(id).value;	
	if(_id>0) {
		var url = "/products/addattachproduct/"+_id+"/"+selid;
		var a = new Ajax.Updater (
			'todo', 
			url	);
	}
}

function ajaxau(id, selid) {
	var _id = id;	
	if(_id>0) {
		var url = "/products/addattachproduct/"+_id+"/"+selid;
		var a = new Ajax.Updater (
			'todo', 
			url	);
	}
}


function ad(url1) {
	var url = url1;
	var a = new Ajax.Updater (
			'todo2', 
			url	);
}

function remove_homepage_product(url1) {
	var url = url1;
	var a = new Ajax.Updater (
			'todo2', 
			url	);
}

function validateUrl(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        //fld.style.background = 'Yellow'; 
        error = "Oops!!! You missed entering the nick name.\n";
    } else if ((fld.value.length < 5) || (fld.value.length > 25)) {
        //fld.style.background = 'Yellow'; 
        error = "Your nick name must be 5 to 20 characters long.\n";
    } else if (illegalChars.test(fld.value)) {
        //fld.style.background = 'Yellow'; 
        error = "Hmm!!! Special characters not allowed. Kindly re-enter nick name.\n";
    } else {
        //fld.style.background = 'White';
    }
    return error;
}

function chgurl(url)
{
  window.location=url;
}

function ajax_categories(mainid,selid) {
	var url = "/products/ajax_getcatgories/"+mainid+"/"+selid;
	var a = new Ajax.Updater (
			'todo', 
			url	);
}

function ajax_category_delete(url1) {
	var url = url1;
	var a = new Ajax.Updater (
			'todo2', 
			url	);
}


function fillValue(str, fillName){
	var pattern =  /[^A-Za-z0-9_]/g
	str = str.toLowerCase();
	str = str.replace(pattern, "_");
	$(fillName).value = str;
	return str;
}

function show_hide(id, val) {
	_$(id).style.display = val;
}

function popup(url){
window.open(url,'mywindow','width=300,height=300,toolbar=no,location=1,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=yes,resizable=yes')
}

// Function for confirmation alert on sending mail
function confirmation(e) {
	var answer = confirm('Notice\n\nUnless you are an existing client, sending information via e-mail to Barron & Stadfeld, P.C. does not establish an attorney-client relationship and may not necessarily be kept confidential by the law firm or the attorney receiving it. If you are not a client, information you submit via e-mail could be used against you and/or disclosed to others. By clicking "Ok", you acknowledge that Barron & Stadfeld, P.C. has no obligation to keep the information that you submit via e-mail confidential unless you are already a client of Barron & Stadfeld, P.C., or the firm has already agreed to receive confidential information from you as a client or potential client.\n\nIf you are interested in becoming a client, please contact one of our attorneys to arrange a discussion on becoming a client. Once an attorney-client relationship is established, you may exchange confidential information via e-mail if you choose. Thank you for your interest in Barron & Stadfeld, P.C.')
	if (answer){
		window.location = 'mailto:'+e;
	}
}