var reqObj10 = new ajaxObject('functions.asp', processData);

var artOff = new Array();

// artoff is an array for articles. Any div name that shows up here will not be displayed
// via controlArt

artOff = ['art1'];

function controlArt(){
  for (var i=0; i < artOff.length; i++){
    //alert(i);
    document.getElementById(artOff[i]).style.display='none';
  }
}

function newPage(name){

  var obj = document.getElementById(name);
  if(obj.value!=""){
     reqObj10.update("a=createPage&page="+obj.value,"POST");
  }
}

function setPublish(name){
  var obj = document.getElementById(name);
  if(obj.selectedIndex!=0){
     reqObj10.update("a=publish&page="+obj.options[obj.selectedIndex].value,"POST");
  }
}

function loginClient(){
  var objU=document.getElementById("u");
  var objP=document.getElementById("p");

  if(objU.value!="" && objP.value!=""){
    reqObj10.update("a=login&u="+objU.value+"&p="+objP.value,"POST");
  } else {
    alert("Sorry - UserID and Password is required. Please try again!");
    objU.focus();
  }
  
}

function retrievepage(obj){

  if(obj.selectedIndex > 0){     
     document.getElementById("content").style.display = "block";
     //prompt("","a=getHTML&page="+obj.options[obj.selectedIndex].value);
     reqObj10.update("a=getHTML&page="+obj.options[obj.selectedIndex].value,"POST");
  }
}

//---------------------------------------------------------------------------------------------------------------------------
//New AJAX functions to handle multiple requests better
//---------------------------------------------------------------------------------------------------------------------------
function ajaxObject(url, callbackFunction) {
  var that=this; 
  this.updating = false;
  this.abort = function() { 
   if (that.updating) { 
     that.updating=false;
     that.AJAX.abort();
     that.AJAX=null;
    }
  } 
 this.update = function(passData,postMethod) {    
    if (that.updating) { return false; }
    that.AJAX = null;  
    if (window.XMLHttpRequest) {
      that.AJAX=new XMLHttpRequest(); 
    } else { 
      that.AJAX=new ActiveXObject("Microsoft.XMLHTTP"); 
   } 
   if (that.AJAX==null) { 
    return false;
   } else { 
     that.AJAX.onreadystatechange = function() { 
      if (that.AJAX.readyState==4) { 
        that.updating=false; 
        that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);
        that.AJAX=null; 
     } 
  } 
  that.updating = new Date();
  if (/post/i.test(postMethod)) { 
   var uri=urlCall+'?'+passData; 
   //alert(uri);
   that.AJAX.open("POST", uri, true); 
   //that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
   //that.AJAX.setRequestHeader("Content-Length", passData.length);
   that.AJAX.send(null); 
  } else { 
    var uri=urlCall+'?'+passData+'&timestamp='+(that.updating.getTime()); 
    that.AJAX.open("GET", uri, true); 
    that.AJAX.send(null); 
  } 
  return true;  
 } 
} 
var urlCall = url;
this.callback = callbackFunction || function () { };
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------


function processData(responseText, responseStatus) {   
  if (responseStatus==200) {
   arResults = responseText.split("|"); 
   //alert(responseText);

                // check clearadbuilder status 
               if (arResults[0] == 'getHTML' && arResults[1] == "True" ){   
                 //alert(arResults[2]); 
                 var theeditor = document.getElementById('CE_Editor1_ID');
                 theeditor.SetHTML("");
                 theeditor.PasteHTML(arResults[2]);
                if(arResults[3]== "True"){
                 document.getElementById("publish").checked=true;     
                }else{
                 document.getElementById("publish").checked=false; 
                }                        
               }  

  } else { 
   //alert(responseStatus + ' -- Error Processing Request');
  }
}


function changeClass(a,id,fldType,fldName) 
{ 
var obj = document.getElementById(id);
obj.className='onAttn'; 
a.onmouseout = function(){obj.className='offAttn';} 
a.onblur = function(){obj.className='offAttn';valField(id,fldType,fldName)}
} 


function valEmail(name) {
var errorMessage = '';
var obj = document.getElementById(name);
addr = obj.value;
if (addr == '') {
   errorMessage = "- email address is missing\n";       
}
var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
for (i=0; i<invalidChars.length; i++) {
   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
      errorMessage = errorMessage + "-email address contains invalid characters\n";	     
   }
}
for (i=0; i<addr.length; i++) {
   if (addr.charCodeAt(i)>127) {
      errorMessage = errorMessage + "-email address contains unprintable characters\n";	       
   }
}

var atPos = addr.indexOf('@',0);
if (atPos == -1) {
   errorMessage = errorMessage + "-email address must contain an @\n";     
}
if (atPos == 0) {
   errorMessage = errorMessage + "-email address must not start with @\n";   
}
if (addr.indexOf('@', atPos + 1) > - 1) {
   errorMessage =  errorMessage + "-email address must contain only one @\n";      
}
if (addr.indexOf('.', atPos) == -1) {
   errorMessage =  errorMessage + "-email address must contain a period in the domain name\n";     
}
if (addr.indexOf('@.',0) != -1) {
   errorMessage =  errorMessage + "-period must not immediately follow @ in email address\n";    
}
if (addr.indexOf('.@',0) != -1){
   errorMessage =  errorMessage + "-period must not immediately precede @ in email address\n";   
}
if (addr.indexOf('..',0) != -1) {
   errorMessage =  errorMessage + "-two periods must not be adjacent in email address\n";   
}
var suffix = addr.substring(addr.lastIndexOf('.')+1);
if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
   errorMessage =  errorMessage + "-invalid domain in email address";
      }
if (errorMessage != '') {
 alert("This email address is not formatted properly. Here are the email format guidelines:\n" + errorMessage);
 obj.focus();
 return(false);
 }
}