function rand(){return String(Math.floor(Math.random()*10000000000));}
function rand2(){return rand()+rand()+rand()+rand()+rand();}
function checkIt(b,c){if(b){b.checked=!c;b.click();b.checked=c;}}
function showIt(sId,v){var x=$(sId);if(x)x.style.display=(v?'block':'none');}
function togView(sId){var el=$(sId);if(el){el.style.display=el.style.display=='none'?'':'none';}}
function checkAllBoxes(form,fieldName,chkVal){formObj=$(form);if(!formObj)return false;var checkBoxes=formObj.getElementsByTagName('input');for(var i=0;i<checkBoxes.length;i++){if(checkBoxes[i].name==fieldName&&!checkBoxes[i].disabled){checkBoxes[i].checked=chkVal;}}}
function countCheckedBoxes(form,fieldName){formObj=$(form);if(!formObj)return false;var checkBoxes=formObj.getElementsByTagName('input');var checkedBoxes=0;for(var i=0;i<checkBoxes.length;i++){checkedBoxes+=(checkBoxes[i].name==fieldName&&!checkBoxes[i].disabled&&checkBoxes[i].checked)?1:0;}return checkedBoxes;}
function pInt(oF){if(oF){oF.value=parseInt(oF.value);if(oF.value=='NaN'){oF.value=0;}}}
function pop(sURL){return!window.open(sURL);}
function go(url){if(url.substr(0,7)!='http://')url=base_url+url;window.location=url;return false;}
function htmlspecialchars(s){var t={'&':'&amp;','"':'&quot;',"'":'&#039;','<':'&lt;','>':'&gt;'};for(var k in t){rx=new RegExp(k,'g');s=s.replace(rx,t[k]);}return s;}
function addslashes(s){s=s.replace(/'/gi,"&#039;");s=s.replace(/"/gi,"&quot;");return s;}
function alternateRowColor(obj,el,c1,c2){if(obj){var els=obj.getElementsByTagName(el);var j=0;for(var i=0;i<els.length;i++)if(!els[i].getAttribute('skip_alternate')){els[i].style.backgroundColor=(j&1?c2:c1);j++;}}}
function basename(s){var p=-1;for(var i=0;i<s.length;i++){if( s.charAt(i)=='\\'||s.charAt(i)=='/')p=i;}if(p<0)return s;return s.substr(p+1,s.length-p);}
function dirname(s){var p=-1;for(var i=0;i<s.length;i++){if( s.charAt(i)=='\\'||s.charAt(i)=='/')p=i;}if(p<0)return s;return s.substr(0,p+1);}
function togImage(im,n){if(!im)return false;var alt=im.getAttribute('alternateImage');if(!alt)alt=dirname(im.src)+'/'+n;var cur=im.src;im.src=alt;im.setAttribute('alternateImage',cur);}
function get_extension(n){n=n.substr(n.lastIndexOf('.')+1);return n.toLowerCase();}
function str_slice(s,l){if(s.length>l)return s.substr(0,l/2)+'...'+s.substr(s.length-(l/2));return s;}
function str_preview(s,l){return s.length>l?s.substr(0,l)+'...':s;}
function setStyles(obj,styles){if(!obj)return false;for(var k in styles)obj.style[k]=styles[k];}
function number_format(n){n+='';x=n.split('.');x1=x[0];x2=x.length>1?'.'+x[1]:'';var rgx=/(\d+)(\d{3})/;while(rgx.test(x1)){x1 = x1.replace(rgx,'$1'+','+'$2');}return x1+x2;}
function setParentSize(i,s){if(!s)s=2;i.parentNode.parentNode.style.width=i.width+s+'px';i.parentNode.parentNode.style.height=i.height+s+'px';}
function set_border(i,p,s){if(typeof s=='undefined')s=2;p.style.width=i.width+s+'px';p.style.height=i.height+s+'px';}
function trim(v,p){var t=Math.pow(10,p);return Math.round(v*t)/t;}
function deleteNode(n){return n.parentNode.removeChild(n);}
function confirmGo(s,url){if(confirm(s))go(url);return false;}

function toggleMenu(id) {
    var menu = $('menu_' + id);
    var expander = $('menu_expander_' + id);
    if(!menu || !expander)
        return;
    menu.blind('toggleY', {duration: 100, fps: 100});
    expander.innerHTML = menu.blindDir() == 'up' ? '+' : '&ndash;';
}


function open_resizable_window(location, height, width, scroll_resize) {

	if(!scroll_resize)	scroll_resize='scrollbars=no, resizable=no';
	window.open(location, 'newwindow', config='top=250, left=250, height=' + height + ', width=' + width + ', toolbar=no, menubar=no, '+ scroll_resize +', location=no, directories=no, status=no');		
}

function in_array( what, where ){	var a=false;	for(var i=0;i<where.length;i++){	  if(what == where[i]){	    a=true;        break;	  }	}	return a;}


function limitChars(textarea, limit, infodiv) {

	var text = textarea.value; 
	var textlength = text.length;
	var info = document.getElementById(infodiv);

	if(textlength > limit) {
		info.innerHTML = 'You cannot write more than '+limit+' characters.!';
		textarea.value = text.substr(0,limit);
		return false;
	}
	else {
	info.innerHTML = 'You have '+ (limit - textlength) +' characters left.';
	return true;
	}
}


function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
			IsNumber = false;
         }
      }

	   return IsNumber;
   
   }


function validate_email(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/i;
   if(reg.test(email) == false)
	  return false;
   else
	   return true;
}


function validate_form_fields_odr()
{
	var product = document.online_demo_form.product.value;
	var email	= document.online_demo_form.email.value;

	if(!product)
	{
		alert("Please choose Barracuda Networks Product");
		return false;
	}

	if(!email)
	{
		alert("Please enter your Email");
		return false;
	}
	else
	{
		if(!validate_email(email))
		{
			alert("Please enter valid Email");
			return false;
		}
		else
		{
			// Not allowing below email domains
			if(email.match(/gmail.com/i) || email.match(/yahoo.com/i) || email.match(/hotmail.com/i) || email.match(/aol.com/i) || email.match(/lycos.com/i) || email.match(/rediff.com/i) || email.match(/rediff.com/i) || email.match(/hushmail.com/i) || email.match(/gmx.com/i) || email.match(/inbox.com/i) || email.match(/mail.com/i) || email.match(/rock.com/i) || email.match(/in.com/i) || email.match(/kaxy.com/i) || email.match(/comcast.net/i) || email.match(/cox.net/i))
			{
				alert("Invalid Email");
				return false;
			}
		}
	}

	return true;
}



function printPage()
{
	document.getElementById('divPrint').style.display = ''; 
	document.getElementById('backup_login_link').style.display = 'none'; 
	document.getElementById('top').style.display = 'none'; 
	document.getElementById('content_left').style.display = 'none'; 

	window.print();

	document.getElementById('backup_login_link').style.display = ''; 
	document.getElementById('top').style.display = ''; 
	document.getElementById('content_left').style.display = ''; 
}


// simple, nothing fancy :(
Element.showTip = function(element, container) {
    element = $(element);
    container = $(container);
    var offset = Position.cumulativeOffset(element);
    Element.setStyle(container, {
        left: offset[0] + 'px',
        top: (offset[1] - container.getHeight() - 5) + 'px',
        display: 'block'
    });
    var hide = function() {
        container.hide();
        //element.stopObserving(hide); // was giving error so commented
    };
    element.observe('mouseout', hide);
}