<!--

    function ajaxRequest() {

	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
	  }
	 }
	
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}

        if (!xmlhttp)
            return false;
	    else
		    return xmlhttp;
    }




var isContentLoaded         = new Array();
var failedLoadContentParams = new Array();

function loadContent(divId, url, urlType, reloadable, overlay, data, eventOnLoad){

   //urlType = static/dynamic/remote

    var http_request = ajaxRequest();
    if(document.getElementById(divId))
	   previouscontent = document.getElementById(divId).innerHTML;
    else
	   previouscontent = '';

	if(http_request && !url == '' && (reloadable || !isContentLoaded[divId])){

        if(getElementHeight(divId) < 29)
		   countImg = 'counter13x13.gif';
        else
		   countImg = 'counter.gif';

		loading = '<'+'table border="0" align="center" width="100%" height="100%" cellpadding="4" cellspacing="0"'+'>'+
			            '<'+'tr'+'>'+
					       '<'+'td class="basic_font" width="100%" height="100%" valign="top" align="left"'+' nowrap="nowrap">'+
		                      '&nbsp;<'+'img src="'+js_images_path+'shared/'+countImg+'" border="0" align="absmiddle"'+'>&nbsp;Loading...'+
						   '<'+'/'+'td'+'>'+
						 '<'+'/'+'tr'+'>'+
			          '<'+'/'+'table'+'>';


        if(overlay)
			createDivOverlay(divId,loading);	
        else
          document.getElementById(divId).innerHTML = loading;

		http_request.onreadystatechange = function(){
             if (http_request.readyState == 4) {
			    if (http_request.status == 200){
				   response = http_request.responseText;
				   deleteDivOverlay(divId);
				   sessAction = isSessionExpired(response, divId, url);
				   if(!sessAction){
                      document.getElementById(divId).innerHTML = response;
				      checkRedirect();
                      isContentLoaded[divId] = true;
                      run_js(response, divId);
					  if(eventOnLoad != null){
						  try{
							  eval(eventOnLoad);
							 }
							 catch(err){}
					  }
					  checkIfAjaxLogIn();				  
				   }
				   else {
				      document.getElementById(divId).innerHTML = previouscontent;
					  previouscontent = '';
                      if(sessAction == 'ajaxnotice'){
						  failedLoadContentParams["divId"]       = divId;
                          failedLoadContentParams["url"]         = url;
	                      failedLoadContentParams["urlType"]     = urlType;
	                      failedLoadContentParams["reloadable"]  = reloadable;
                          failedLoadContentParams["overlay"]     = overlay;
	                      failedLoadContentParams["data"]        = data;
	                      failedLoadContentParams["eventOnLoad"] = eventOnLoad;
					      LogInDialog();
					  }
                      else	 
                         window.location.href = sessAction;
				   }
			    }   
			 }
		 };

        if(urlType == 'local')
		   content = js_domain+'ajaxloader.php?content_url='+escape(url);
		else if(urlType == 'dynamic')
		   content = url+'&ajax=true';
		else if(urlType == 'remote')
		   content = url;
        else
		   content = '';

        if(data == ''){
	       method = 'GET';
           data = null;
	    }
        else
	      method = 'POST';


        http_request.open(method, content, true);
		if(method == 'POST')
		   http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    http_request.send(data);
	  } 
}




  function isSessionExpired(response, divId, url){
     var reg      = '<div id="session_expired" url="[^>]*"></div>';
     var matchAll = new RegExp(reg, 'im');
     action       = response.match(matchAll);
	 if(action == null || action == '')
	    return false;

     action       = action.toString();
	 var reg      = '<div id="session_expired" url="|"></div>';
	 var matchAll = new RegExp (reg, 'img');
	 action       = action.replace(matchAll, "");
     
	 return action;
  }


  function checkRedirect(){
     if(document.getElementById('redirect')){
		if(document.getElementById('redirect').getAttribute('url') != '')
           window.location.href = document.getElementById('redirect').getAttribute('url');
     }
  }
  
   function checkIfAjaxLogIn(){
     if(document.getElementById('ajaxloggedin')){
		if(document.getElementById('ajaxloggedin').getAttribute('status') =="1"){
           deleteDialog('loginDialog');
		   try{loadContent(failedLoadContentParams["divId"], 
						   failedLoadContentParams["url"],
						   failedLoadContentParams["urlType"],
						   failedLoadContentParams["reloadable"],
						   failedLoadContentParams["overlay"],
						   failedLoadContentParams["data"],
						   failedLoadContentParams["eventOnLoad"]);
		     refreshUserOnlyContents();
		   }
		   catch(err){}
		}
     }
  }


  function refreshUserOnlyContents(){
	  loadContent('customer_panel',js_domain+'/?block=customer_panel','dynamic',true,false);	  
  }


  function run_js(code, id){
	  if(document.getElementById(id+'_script'))
         document.getElementsByTagName('head').item(0).removeChild(document.getElementById(id+'_script'));
	  var script = extractScripts(code);
	  if(script == null)
		 return;
      var js=document.createElement("script");
      js.setAttribute("language","JavaScript");
      js.setAttribute("type","text/javascript");
      js.setAttribute("id",id+'_script');
      js.text = script;
      document.getElementsByTagName('head').item(0).appendChild(js);
  }



  function extractScripts(text) {
    var reg      = '<script[^>]*>([\u0001-\uFFFF]*?)</script>';
    var matchAll = new RegExp(reg, 'img');
    script       = text.match(matchAll);
	if(script == null || script == '')
	   return null;

    script       = script.toString();
	var reg      = '</script>([\u0001-\uFFFF]*?)<script';
	var matchAll = new RegExp (reg, 'img');
	script       = script.replace(matchAll, "</script> <script");
    
    script       = script.toString();
	var reg      = '<script[^>]*?>|</script>';
	var matchAll = new RegExp (reg, 'img');
	script       = script.replace(matchAll, " ");

    script       = script.toString();
	var reg      = '<!--|-->';
	var matchAll = new RegExp (reg, 'img');
	script       = script.replace(matchAll, " ");

	var reg      = "'&(quot|#34);'";
	var matchAll = new RegExp (reg, 'img');
	script       = script.replace(matchAll, " ");
 	return script;
  }




var nsDivOverlayImg = new Image();
nsDivOverlayImg.src = js_images_path+'shared/transparent1.png';
function createDivOverlay(id, content){

     var div = document.createElement('div');
     div.setAttribute('id',id+'_overlay');
     document.body.appendChild(div);
     document.getElementById(id+'_overlay').style.position = 'absolute';

     showHideIE6Selects(id, 'hidden');
     showHideFlashObjects(id, 'hidden');

     var width  = getElementWidth(id);
	 var height = getElementHeight(id);
	 var top    = getElementTop(id);
	 var left   = getElementLeft(id);
	 
     var objDiv = document.getElementById(id+'_overlay');
	 objDiv.style.overflow  =  'hidden';
	 objDiv.style.zIndex    =  getNextZIndex();
     objDiv.style.top       =  top   +'px';
     objDiv.style.left      =  left  +'px';
     objDiv.style.width     =  width +'px';
     objDiv.style.height    =  height+'px';
     objDiv.style.padding   =  '0px';
     objDiv.style.margin    =  '0px';
     objDiv.innerHTML       =  content;
     objDiv.className       = 'trans_box' ;
}



function deleteDivOverlay(id){
     if(document.getElementById(id+'_overlay')){
	    deleteDiv(id+'_overlay');
        showHideIE6Selects(id, 'visible');
        showHideFlashObjects(id, 'visible');
	 }
}



function getFormData(id){
  formobj   = document.forms[id];
  request   = "";
  separator = "";
  for(index=0; index < formobj.length; index++) {
    itemobj=formobj.elements[index];
    if(itemobj.name=="") continue;
    if(itemobj.type=="checkbox" && !itemobj.checked) continue;
    if(itemobj.type=="radio"    && !itemobj.checked) continue;
    request+=separator+itemobj.name+"="+encodeURIComponent(itemobj.value);
    separator="&";
  }
  return request;
}


function sessionExpiredWindow(divId, url){
	loadUrl = js_domain+'?mod=customers&modfile=login&ajax_load_content_to=offline_notice_content&expired_div='+divId+'&next_page='+escape(url);
	text    = '<font class="basic_font"><br>You must be logged in to use this feature.<br>&nbsp;You are currently not logged in or your session has expired.&nbsp;<br><br>Please <b>'+
	          '<a href="'+js_domain+'?mod=customers&modfile=login" style="text-decoration:underline" '+
		      //'onclick="loadContent(\'offline_notice_content\', \''+loadUrl+'\', \'dynamic\', true, true, \'\'); return false;"'+
			  '>'+
		      'Log-In</a></b> or <b>'+
		      '<a href="'+js_domain+'?mod=customers&modfile=login" style="text-decoration:underline" '+
		      //'onclick="loadContent(\'offline_notice_content\', \''+loadUrl+'\', \'dynamic\', true, true, \'\'); return false;"'+ 
			  '>'+
		      'Register</a></b><br>It takes just a few seconds.</font><br><br>';

    createDialog('offline_notice','center','center','Please Log-In',text,true,'center', true);
}

function LogInDialog(){
    createDialog('loginDialog','center',getBodyScrollTop()+20,'PLEASE LOG-IN','',true,'center', true, 700);
	loadContent('loginDialog_content', js_domain+'?mod=customers&modfile=login&ajax_load_content_to=loginDialog_content&next_page=ajaxlogin','dynamic',true,false);
}


-->