
function checkHash(){
if(window.location.hash)
	{	
	var currentHash = window.location.hash.substring(1,location.hash.length);
	if(currentHash != currentPage)
		{
			testlocalnameandload(currentHash);
/*			loadcontent('contentbody',currentHash);	*/
		}
	}
}


function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		var errorMsg = "Sorry, that does not seem to be a valid Email Address. Try again."
		if (str.indexOf(at)==-1){
		   alert(errorMsg)
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert(errorMsg)
		   return false
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert(errorMsg)
		    return false
		}
		 if (str.indexOf(at,(lat+1))!=-1){
		    alert(errorMsg)
		    return false
		 }
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert(errorMsg)
		    return false
		 }
		 if (str.indexOf(dot,(lat+2))==-1){
		    alert(errorMsg)
		    return false
		 }
	
		 if (str.indexOf(" ")!=-1){
		    alert(errorMsg)
		    return false
		 }

 		 return true					
	}

function hasClass(ele,cls) {
return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));}

function addClass(ele,cls) {
if (!this.hasClass(ele,cls)) ele.className += " "+cls;}

function removeClass(ele,cls) {
if (hasClass(ele,cls)) {
var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
ele.className=ele.className.replace(reg,' ');
}}



function isRightClick(e) {
if (!e)
{
var e = window.event;
}
  if (navigator.appName == 'Netscape'
           && e.which == 3) {
	return true;
      }
   else {
      if (navigator.appName == 'Microsoft Internet Explorer'
          && event.button==2)
         return true;
         }
   return false;
 }

function lcb(page){
loadcontentbody('contentbody',page,'contentbody');
return false;
/* return false for the sake of the anchor */
}

function loadcontent(localdiv, remotepage, remotediv){

$(localdiv).innerHTML = '<div id="loader" style="position:absolute; width:100%; height:100%; top:0px; left:0px;"><div style="position:absolute; width:100%; height:100%; top:0px; left:0px; background: url(images/loading.gif) no-repeat center center;"></div></div>';

var htmlRequest = new Request.HTML(
	{
        url: "contentbody.php",
        onSuccess:
        function(tree, elements, html, js){
        /*$(localdiv).style.visibility = 'visible';*/
           $(localdiv).innerHTML=html;
           window.location.hash = remotepage;
           currentPage = remotepage;
          // eval(js);
			  startupScripts();
       pageTracker._trackPageview(page);

                        }
	}).get( { 'page': remotepage, 'dest': remotediv });
}


function localpagename(namehref){
                var search = /advancedsecurityusa\.com\/(.*)\.html/;
                namehref.match(search);
                var result = RegExp.$1;
                return result; 
}

function testlocalnameandload(localaddress){
    var destsub = localaddress.split("-");
        /*                                                                                      */
        /* format will be 'localdivid-remotepage-remotedivid'                                   */
        /* if localdivid exists and remotepage and remotediv id are not null, then ajax it      */
        /*                                                                                      */
        if( destsub[1] && destsub[2] && $(destsub[0]) ) {
            loadcontent(destsub[0],destsub[1],destsub[2])
        }else{
		if(destsub[1]) 	{  loadcontent('contentbody',destsub[1], 'contentbody'); }
		else		{  loadcontent('contentbody',localaddress,'contentbody'); }
	}

}

function startupScripts(){

if(typeof AdminLoad !== "function"){
	if(navigator.appName != "Microsoft Internet Explorer") soup_up_anchors();
}else{
	dblClick_anchors();
}

if(typeof runafterload=="function"){
	runafterload();
}	

/* $('contentbody').style.visibility = 'visible'; */



}



function dblClick_anchors(){

$$('a').each(function(el){
	if(!el.onclick)	 {
		el.addEvents({
                        'dblclick' : function(){ window.location = this.href; },
			'click' : function(){ return false; }		          });

			}
			});
}

function soup_up_anchors(){
$$('a').each(function(el) {
if(!el.onclick){
el.onclick = function()
{
        var destpage = localpagename(this.href);
        if(destpage){
        var rel = this.rel;
                if(rel)
                {
                        var relsplit = rel.split("-");
                        var remotediv = (relsplit[1]) ? relsplit[1] : relsplit[0];
                        /* now if this local div even exists... then we can do it.  ...otherwise load the whole content body */
                        if( $(relsplit[0]) ) {
                                loadcontent(relsplit[0],destpage,remotediv);
                        }else{
                                loadcontent('contentbody', destpage, 'contentbody');
                        }
                }else{
                        loadcontent('contentbody', destpage, 'contentbody');
                }
		return false;
                        /* obsolete else{                                  */
                        /* test it since rel was not present, then load it */
                        /* testlocalnameandload(destpage); return false;   */
                        /* } */

        }
        /* well all of these failed.... uhh, so return true and go with the browser href page link */
        return true;
}
}
});

}
