//**************************************************************************************
// Field Edit - autocomplete functions
//**************************************************************************************

function showele(eleid,onoff){
  document.getElementById(eleid).style.display=(onoff==1?"inline":"none");
}
function cele(eleid,onoff){
  if(document.getElementById(eleid)){
    if(onoff=="1"){
      showele(eleid,onoff);
    } else {
      MessDisplay(eleid,0,0,0,"yes");
    }
  }
}

function attfromcloud(addword,word_id,ent_type_id){
  if(document.getElementById('add_attr['+(NRN-1)+']')){
    document.getElementById('add_attr['+(NRN-1)+']').value = addword;
    popcell(document.getElementById('add_attr['+(NRN-1)+']'),(NRN-1));
    fillvaluecloud(word_id,ent_type_id)
  }
}

function fillvaluecloud(word_id,ent_type_id) {
//  alert(word_id + "-"+ent_type_id)
  var div = document.createElement('DIV');
  div.className = "cloudbox";
  loadDiv("value_cloud_cell","ajax.php?incmod=includes/loadcloud.inc&word_id="+word_id+"&ent_type_id="+ent_type_id)
}

function valfromcloud(addword,munit,ent_type_id){
  if(document.getElementById('add_val['+(NRN-1)+']')){
    document.getElementById('add_val['+(NRN-1)+']').value = addword;
  }
  if(munit!="") {
    if(document.getElementById('add_meas['+(NRN-1)+']')){
      document.getElementById('add_meas['+(NRN-1)+']').value = munit;
    }
  }
}


function popcell(frele,rowNo){
//  alert(frele.value+"-"+rowNo);
  loadDiv("ajaxWindow","ajax.php?incmod=includes/getMeas.inc&val="+frele.value)
//  MessDisplay("ajaxWindow",1,100,100,"no");
  var hide="no";
  if(document.getElementById('measf')){
    if(document.getElementById('measf').value!="no"){
      var ci = "<b>Measurement</b><br>";
          ci+= "<select id='add_meas["+rowNo+"]' name='add_meas["+rowNo+"]'></select>";
      document.getElementById('mdd_'+rowNo).innerHTML = ci;
      addOptions("add_meas["+rowNo+"]","measf","","")
    } else {
      hide="y"
    }
  } else {
    hide="y";
  }
  if(hide=="y") {
    document.getElementById('mdd_'+rowNo).innerHTML = "";
  }
}

var NRN=0;
function addrow(do_pmp,do_ptm,ent_t_id){
  if(NRN>0){
    if(document.getElementById('add_attr['+(NRN-1)+']').value == "") {
      alert("Please Complete Attribute Description");
      document.getElementById('add_attr['+(NRN-1)+']').focus();
      return false;
    }
    if(document.getElementById('add_val['+(NRN-1)+']').value == "") {
      alert("Please Complete Attribute Value")
      document.getElementById('add_val['+(NRN-1)+']').focus();
      return false;
    }
  }
  var theTable = document.getElementById('dynaTbl');
  var lastRow = theTable.rows.length;
  var newR = theTable.insertRow(lastRow);
  var cellno = 0;
  var newC = newR.insertCell(cellno);
  var ci = "<b>Attribute Description</b><br>";
      ci+= "<input type='text' size='30' maxlength='30' id='add_attr["+NRN+"]' name='add_attr["+NRN+"]' onblur='cele(\"fnddiv\",0);popcell(this,"+NRN+")'";
      ci+= " onKeyUp='ajax_showOptions(this,\"x\",\"cf_attr_def\",\"attr_def_id\",\"attr_def_desc\",\"and ent_type_id = "+ent_t_id+"\",\"\",event)'>";
  newC.innerHTML = ci;
  if(do_pmp==1) {
    cellno++;
    var newC = newR.insertCell(cellno);
    var ci = "<br>";
        ci+= "<img id='add_pmp_img_"+NRN+"' src='images/pmp_0.gif'";
        ci+= " onmousemove='shpmp(\"add_pmp\","+NRN+",1)' onmouseout='shpmp(\"add_pmp\","+NRN+",0)' onclick='swpmp(\"add_pmp\","+NRN+")'>"
        ci+= "<input type='hidden' name='add_pmp["+NRN+"]' id='add_pmp["+NRN+"]' value='0'>";
  }
  if(do_ptm==1) {
        ci+= "<img id='add_ptm_img_"+NRN+"' src='images/ptm_0.gif'";
        ci+= " onmousemove='shptm(\"add_ptm\","+NRN+",1)' onmouseout='shptm(\"add_ptm\","+NRN+",0)' onclick='swptm(\"add_ptm\","+NRN+")'>"
        ci+= "<input type='hidden' name='add_ptm["+NRN+"]' id='add_ptm["+NRN+"]' value='0'>";
  }
  newC.innerHTML = ci;
  cellno++;
  var newC = newR.insertCell(cellno);
  var ci = "<b>Attribute Value</b><br>";
      ci+= "<input type='text' style='width:200px' maxlength='100' value='' id='add_val["+NRN+"]' name='add_val["+NRN+"]'>";
  newC.innerHTML = ci;
  cellno++
  var newC = newR.insertCell(cellno);
  newC.id = "mdd_"+NRN;
  NRN++;
}



/////////////////////////////////////////////////////////////////
//NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN//
//EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE//
//WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW//
/////////////////////////////////////////////////////////////////
/* Simple AJAX Code-Kit (SACK) v1.6.1 */
/* ©2005 Gregory Wild-Smith */
/* www.twilightuniverse.com */
/* Software licenced under a modified X11 licence,
   see documentation or authors website for more details */

function sack(file) {
  this.xmlhttp = null;
  this.resetData = function() {
    this.method = "POST";
    this.queryStringSeparator = "?";
    this.argumentSeparator = "&";
    this.URLString = "";
    this.encodeURIString = true;
    this.execute = false;
    this.element = null;
    this.elementObj = null;
    this.requestFile = file;
    this.vars = new Object();
    this.responseStatus = new Array(2);
  };
  
  this.resetFunctions = function() {
    this.onLoading = function() { };
    this.onLoaded = function() { };
    this.onInteractive = function() { };
    this.onCompletion = function() { };
    this.onError = function() { };
    this.onFail = function() { };
  };

  this.reset = function() {
    this.resetFunctions();
    this.resetData();
  };

  this.createAJAX = function() {
    try {
      this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e1) {
      try {
        this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
        this.xmlhttp = null;
      }
    }

    if (! this.xmlhttp) {
      if (typeof XMLHttpRequest != "undefined") {
        this.xmlhttp = new XMLHttpRequest();
      } else {
        this.failed = true;
      }
    }
  };

  this.setVar = function(name, value){
    this.vars[name] = Array(value, false);
  };

  this.encVar = function(name, value, returnvars) {
    if (true == returnvars) {
      return Array(encodeURIComponent(name), encodeURIComponent(value));
    } else {
      this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
    }
  }

  this.processURLString = function(string, encode) {
    encoded = encodeURIComponent(this.argumentSeparator);
    regexp = new RegExp(this.argumentSeparator + "|" + encoded);
    varArray = string.split(regexp);
    for (i = 0; i < varArray.length; i++){
      urlVars = varArray[i].split("=");
      if (true == encode){
        this.encVar(urlVars[0], urlVars[1]);
      } else {
        this.setVar(urlVars[0], urlVars[1]);
      }
    }
  }

  this.createURLString = function(urlstring) {
    if (this.encodeURIString && this.URLString.length) {
      this.processURLString(this.URLString, true);
    }

    if (urlstring) {
      if (this.URLString.length) {
        this.URLString += this.argumentSeparator + urlstring;
      } else {
        this.URLString = urlstring;
      }
    }

    // prevents caching of URLString
    this.setVar("rndval", new Date().getTime());

    urlstringtemp = new Array();
    for (key in this.vars) {
      if (false == this.vars[key][1] && true == this.encodeURIString) {
        encoded = this.encVar(key, this.vars[key][0], true);
        delete this.vars[key];
        this.vars[encoded[0]] = Array(encoded[1], true);
        key = encoded[0];
      }

      urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
    }
    if (urlstring){
      this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
    } else {
      this.URLString += urlstringtemp.join(this.argumentSeparator);
    }
  }

  this.runResponse = function() {
    eval(this.response);
  }

  this.runAJAX = function(urlstring) {
    if (this.failed) {
      this.onFail();
    } else {
      this.createURLString(urlstring);
      if (this.element) {
        this.elementObj = document.getElementById(this.element);
      }
      if (this.xmlhttp) {
        var self = this;
        if (this.method == "GET") {
          totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
          this.xmlhttp.open(this.method, totalurlstring, true);
        } else {
          this.xmlhttp.open(this.method, this.requestFile, true);
          try {
            this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
          } catch (e) { }
        }

        this.xmlhttp.onreadystatechange = function() {
          switch (self.xmlhttp.readyState) {
            case 1:
              self.onLoading();
              break;
            case 2:
              self.onLoaded();
              break;
            case 3:
              self.onInteractive();
              break;
            case 4:
              self.response = self.xmlhttp.responseText;
              self.responseXML = self.xmlhttp.responseXML;
              self.responseStatus[0] = self.xmlhttp.status;
              self.responseStatus[1] = self.xmlhttp.statusText;
              if (self.execute) {
                self.runResponse();
              }

              if (self.elementObj) {
                elemNodeName = self.elementObj.nodeName;
                elemNodeName.toLowerCase();
                if (elemNodeName == "input"
                || elemNodeName == "select"
                || elemNodeName == "option"
                || elemNodeName == "textarea") {
                  self.elementObj.value = self.response;
                } else {
                  self.elementObj.innerHTML = self.response;
                }
              }
              if (self.responseStatus[0] == "200") {
                self.onCompletion();
              } else {
                self.onError();
              }

              self.URLString = "";
              break;
          }
        };

        this.xmlhttp.send(this.URLString);
      }
    }
  };
  this.reset();
  this.createAJAX();
}

/************************************************************************************************************
(C) www.dhtmlgoodies.com, April 2006

This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.

Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.

Thank you!

www.dhtmlgoodies.com
Alf Magne Kalleland

************************************************************************************************************/

var ajaxBox_offsetX = 0;
var ajaxBox_offsetY = 0;
var minimumLettersBeforeLookup = 1; // Number of letters entered before a lookup is performed.

var ajax_list_objects = new Array();
var ajax_list_cachedLists = new Array();
var ajax_list_activeInput = false;
var ajax_list_activeItem;
var ajax_list_optionDivFirstItem = false;
var ajax_list_currentLetters = new Array();
var ajax_list_id_field = "";
var ajax_optionDiv = false;
var ajax_optionDiv_iframe = false;

var ajax_list_MSIE = false;
if(navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('Opera')<0)ajax_list_MSIE=true;

var currentListIndex = 0;

function ajax_getTopPos(inputObj){
  var returnValue = inputObj.offsetTop;
  while((inputObj = inputObj.offsetParent) != null){
    returnValue += inputObj.offsetTop;
  }
  return returnValue;
}
function ajax_list_cancelEvent(){
  return false;
}

function ajax_getLeftPos(inputObj){
  var returnValue = inputObj.offsetLeft;
  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
  return returnValue;
}

function ajax_option_setValue(e,inputObj){
  if(!inputObj)inputObj=this;
  var tmpValue = inputObj.innerHTML;
  if(ajax_list_MSIE)tmpValue = inputObj.innerText;else tmpValue = inputObj.textContent;
  if(!tmpValue)tmpValue = inputObj.innerHTML;
  ajax_list_activeInput.value = tmpValue;
  //alert(inputObj.id);
  //alert(inputObj.textContent);
  if(document.getElementById(ajax_list_activeInput.name + '_hidden'))document.getElementById(ajax_list_activeInput.name + '_hidden').value = inputObj.id;
  if(document.getElementById(ajax_list_id_field))document.getElementById(ajax_list_id_field).value = inputObj.id;
    //var f1=setTimeout('ajax_list_activeInput.focus()',1);
    //var f2=setTimeout('ajax_list_activeInput.value = ajax_list_activeInput.value',1);
  ajax_options_hide();
}

function ajax_options_hide() {
  if(ajax_optionDiv)ajax_optionDiv.style.display='none';
  if(ajax_optionDiv_iframe)ajax_optionDiv_iframe.style.display='none';
}

function ajax_options_rollOverActiveItem(item,fromKeyBoard) {
  if(ajax_list_activeItem)ajax_list_activeItem.className='optionDiv';
  item.className='optionDivSelected';
  ajax_list_activeItem = item;
  if(fromKeyBoard){
    if(ajax_list_activeItem.offsetTop>ajax_optionDiv.offsetHeight){
      ajax_optionDiv.scrollTop = ajax_list_activeItem.offsetTop - ajax_optionDiv.offsetHeight + ajax_list_activeItem.offsetHeight + 2 ;
    }
    if(ajax_list_activeItem.offsetTop<ajax_optionDiv.scrollTop)
    {
      ajax_optionDiv.scrollTop = 0;
    }
  }
}

function ajax_option_list_buildList(letters,paramToExternalFile) {
  ajax_optionDiv.innerHTML = '';
  ajax_list_activeItem = false;
  if(ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()].length<=1){
    ajax_options_hide();
    return;
  }
  ajax_list_optionDivFirstItem = false;
  var optionsAdded = false;
  for(var no=0;no<ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()].length;no++){
    if(ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()][no].length==0)continue;
    optionsAdded = true;
    var div = document.createElement('DIV');
    var items = ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()][no].split(/###/gi);
    if(ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()].length==1 && ajax_list_activeInput.value == items[0]){
      ajax_options_hide();
      return;
    }
    div.innerHTML = items[items.length-1];
    div.id = items[0];
    div.className='optionDiv';
    div.onmouseover = function(){ ajax_options_rollOverActiveItem(this,false) }
    div.onclick = ajax_option_setValue;
    if(!ajax_list_optionDivFirstItem)ajax_list_optionDivFirstItem = div;
    ajax_optionDiv.appendChild(div);
  }
  if(optionsAdded){
    ajax_optionDiv.style.display='block';
    if(ajax_optionDiv_iframe)ajax_optionDiv_iframe.style.display='';
    ajax_options_rollOverActiveItem(ajax_list_optionDivFirstItem,true);
  }

}

function ajax_option_list_showContent(ajaxIndex,inputObj,paramToExternalFile,whichIndex){
  if(whichIndex!=currentListIndex)return;
  var letters = inputObj.value;
  var content = ajax_list_objects[ajaxIndex].response;
  var elements = content.split('|');
  ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()] = elements;
  ajax_option_list_buildList(letters,paramToExternalFile);
}

function ajax_option_resize(inputObj) {
  ajax_optionDiv.style.top = (ajax_getTopPos(inputObj) + inputObj.offsetHeight + ajaxBox_offsetY) + 'px';
  ajax_optionDiv.style.left = (ajax_getLeftPos(inputObj) + ajaxBox_offsetX) + 'px';
  if(ajax_optionDiv_iframe){
    ajax_optionDiv_iframe.style.left = ajax_optionDiv.style.left;
    ajax_optionDiv_iframe.style.top = ajax_optionDiv.style.top;
  }
}

function ajax_showOptions(inputObj,paramToExternalFile,tbl,unq,fld,whr,id_field,e) {
  if(e.keyCode==13 || e.keyCode==9)return;
  if(ajax_list_currentLetters[inputObj.name]==inputObj.value)return;
  if(!ajax_list_cachedLists[paramToExternalFile])ajax_list_cachedLists[paramToExternalFile] = new Array();
  ajax_list_id_field=id_field;
  ajax_list_currentLetters[inputObj.name] = inputObj.value;
  if(!ajax_optionDiv){
    ajax_optionDiv = document.createElement('DIV');
    ajax_optionDiv.id = 'ajax_listOfOptions';
    document.body.appendChild(ajax_optionDiv);
    if(ajax_list_MSIE){
      ajax_optionDiv_iframe = document.createElement('IFRAME');
      ajax_optionDiv_iframe.border='0';
      ajax_optionDiv_iframe.style.width = ajax_optionDiv.clientWidth + 'px';
      ajax_optionDiv_iframe.style.height = ajax_optionDiv.clientHeight + 'px';
      ajax_optionDiv_iframe.id = 'ajax_listOfOptions_iframe';
      document.body.appendChild(ajax_optionDiv_iframe);
    }
    var allInputs = document.getElementsByTagName('INPUT');
    for(var no=0;no<allInputs.length;no++){
      if(!allInputs[no].onkeyup)allInputs[no].onfocus = ajax_options_hide;
    }
    var allSelects = document.getElementsByTagName('SELECT');
    for(var no=0;no<allSelects.length;no++){
      allSelects[no].onfocus = ajax_options_hide;
    }
    var oldonkeydown=document.body.onkeydown;
    if(typeof oldonkeydown!='function'){
      document.body.onkeydown=ajax_option_keyNavigation;
    }else{
      document.body.onkeydown=function(){
        oldonkeydown();
      ajax_option_keyNavigation() ;}
    }
    var oldonresize=document.body.onresize;
    if(typeof oldonresize!='function'){
      document.body.onresize=function() {ajax_option_resize(inputObj); };
    }else{
      document.body.onresize=function(){oldonresize();
      ajax_option_resize(inputObj) ;}
    }
  }
  if(inputObj.value.length<minimumLettersBeforeLookup){
    ajax_options_hide();
    return;
  }
  ajax_optionDiv.style.top = (ajax_getTopPos(inputObj) + inputObj.offsetHeight + ajaxBox_offsetY) + 'px';
  ajax_optionDiv.style.left = (ajax_getLeftPos(inputObj) + ajaxBox_offsetX) + 'px';
  if(ajax_optionDiv_iframe){
    ajax_optionDiv_iframe.style.left = ajax_optionDiv.style.left;
    ajax_optionDiv_iframe.style.top = ajax_optionDiv.style.top;
  }
  ajax_list_activeInput = inputObj;
  ajax_optionDiv.onselectstart =  ajax_list_cancelEvent;
  currentListIndex++;
  if(ajax_list_cachedLists[paramToExternalFile][inputObj.value.toLowerCase()]){
    ajax_option_list_buildList(inputObj.value,paramToExternalFile,currentListIndex);
  }else{
    var tmpIndex=currentListIndex/1;
    ajax_optionDiv.innerHTML = '';
    var ajaxIndex = ajax_list_objects.length;
    ajax_list_objects[ajaxIndex] = new sack();
  var parms="";
  parms+="&fnd="+inputObj.value;
  parms+="&tbl="+tbl;
  parms+="&unq="+unq;
  parms+="&fld="+fld;
  parms+="&whr="+whr;
  var d=new Date();
  parms+="&tst="+d.getTime();
    var url = "ajax.php?incmod=includes/auto_comp.inc"+parms;
    ajax_list_objects[ajaxIndex].requestFile = url; // Specifying which file to get
    ajax_list_objects[ajaxIndex].onCompletion = function(){ ajax_option_list_showContent(ajaxIndex,inputObj,paramToExternalFile,tmpIndex); }; // Specify function that will be executed after file has been found
    ajax_list_objects[ajaxIndex].runAJAX();   // Execute AJAX function
  }
}

function ajax_option_keyNavigation(e) {
  if(document.all)e = event;
  if(!ajax_optionDiv)return;
  if(ajax_optionDiv.style.display=='none')return;
  if(e.keyCode==38){  // Up arrow
    if(!ajax_list_activeItem)return;
    if(ajax_list_activeItem && !ajax_list_activeItem.previousSibling)return;
    ajax_options_rollOverActiveItem(ajax_list_activeItem.previousSibling,true);
  }
  if(e.keyCode==40){  // Down arrow
    if(!ajax_list_activeItem){
      ajax_options_rollOverActiveItem(ajax_list_optionDivFirstItem,true);
    }else{
      if(!ajax_list_activeItem.nextSibling)return;
      ajax_options_rollOverActiveItem(ajax_list_activeItem.nextSibling,true);
    }
  }
  if(e.keyCode==13 || e.keyCode==9){  // Enter key or tab key
    if(ajax_list_activeItem && ajax_list_activeItem.className=='optionDivSelected')ajax_option_setValue(false,ajax_list_activeItem);
    if(e.keyCode==13)return false; else return true;
  }
  if(e.keyCode==27){  // Escape key
    ajax_options_hide();
  }
}

document.documentElement.onclick = autoHideList;

function autoHideList(e) {
  if(document.all)e = event;

  if (e.target) source = e.target;
    else if (e.srcElement) source = e.srcElement;
    if (source.nodeType == 3) // defeat Safari bug
      source = source.parentNode;
  if(source.tagName.toLowerCase()!='input' && source.tagName.toLowerCase()!='textarea')ajax_options_hide();

}



//**************************************************************************************
// Script specifics
//**************************************************************************************
//* bus_invite.inc
function validate_Invite_Bulk(){
  for(x=1; x<5; x++) {
    if( (document.getElementById('inv_name['+x+']').value !="")
      ||(document.getElementById('inv_surn['+x+']').value !="")
      ||(document.getElementById('inv_comp['+x+']').value !="")
      ||(document.getElementById('inv_mail['+x+']').value !="")
      ) {
      if(ChkVal('inv_name['+x+']',"Contact's Name")==false){return false}
      if(ChkVal('inv_surn['+x+']',"Contact's Surname")==false){return false}
      if(ChkVal('inv_comp['+x+']',"Contact's Business")==false){return false}
      if(ChkVal('inv_mail['+x+']',"Contact's e-Mail Address")==false){return false}
    }
  }
  return true;
}

//* ent_view.inc
function getLogo(){
  window.location.href="index.php?mod=pub&f=logo_upd";
}

//* logo_upd.inc
function validate_Logo(){
  document.getElementById('fakefile_Logo').value = document.getElementById('userfile_Logo').value;
  if(document.getElementById('userfile_Logo').value!="") {
    var filArr = document.getElementById('userfile_Logo').value.split(".");
    var ext = filArr[((filArr.length)-1)].toLowerCase(); 
    if(
        (document.getElementById('userfile_Logo').value.indexOf("&") > 0) 
      ||(document.getElementById('userfile_Logo').value.indexOf(",") > 0) 
      ||(document.getElementById('userfile_Logo').value.indexOf("(") > 0) 
      ||(document.getElementById('userfile_Logo').value.indexOf(")") > 0) 
      ) {
      alert("No special Characters like '&,()' allowed in filenames");
      document.getElementById('userfile_Logo').value = ""
      document.getElementById('fakefile_Logo').value = "";
      return false;
    }
    if( (ext !="jpg")
      &&(ext !="jpeg") 
      &&(ext !="gif")
      ) {
      alert("Only .jpg, .jpeg or .gif files allowed");
      document.getElementById('userfile_Logo').value = "";
      document.getElementById('fakefile_Logo').value = "";
      return false;
    } 
    document.getElementById('FileForm_Logo').submit();
    document.getElementById('upld_anim_Logo').style.display="inline";
    setTimeout("logo_checkUpld('"+ext+"')",1000);
  }
}

function logo_checkUpld(ext){
  var runagain= "y";
  if(document.getElementById('userfile_Logo').style.display!="none"){
    if(window.frames['iframe_Logo'].document){
      if(window.frames['iframe_Logo'].document.getElementById('upl')){
        document.getElementById('upld_anim_Logo').style.display="none";
        if(document.getElementById('disknam').value.indexOf(".")>0){
          document.getElementById('disknam').value = document.getElementById('disknam').value.split(".")[0];
        }
        document.getElementById('disknam').value+="."+ext;
        var d=new Date();
        document.getElementById('comp_logo').src = "null.php?incmod=includes/loadimg.inc&img=logos/"+document.getElementById('disknam').value+"&w=350&h=200&tst="+d.getTime();
        document.getElementById('updform').style.display = "inline";
        document.getElementById('userfile_Logo').value = "";
        document.getElementById('fakefile_Logo').value = "";
        
        runagain = "n";
      }
    }
  }
  if(runagain=="y") {
    setTimeout("logo_checkUpld('"+ext+"')",500)
  }
}


//* adm_comp.inc
function compCh(ele){
  chkMemb(ele.value)
  if(document.getElementById('comp_tst').value != ele.value){
    alert("You have not yet been confirmed as a member")
  }
  window.location.reload();
}
//* adm_dprt.inc
function validDprt(){
  if(ChkVal("dprt_name","Department Name")==false) {return false}
  document.getElementById('dprt_add').submit();
}
//* comp_dprt_list.inc
function addDprt(id,comp_id){
  var parms="";
  parms+="&id="+id;
  parms+="&comp_id="+comp_id;
  var d=new Date();
  parms+="&tst="+d.getTime();
  loadDiv("ajaxWindow","ajax.php?incmod=mods/pub/adm_dprt.inc"+parms);
  MessDisplay("ajaxWindow",1,"x-1","y-20","yes");
}
//* lin_lines.inc
function chkMemb(comp_id) {
  var parms="";
  parms+="&comp_id="+comp_id;
  var d=new Date();
  parms+="&tst="+d.getTime();
  loadDiv("ajaxWindow","ajax.php?incmod=mods/pub/adm_comp_chk_memb.inc"+parms);
//  MessDisplay("ajaxWindow",1,"x-250","y-50","yes");
}
//* comp_memb_list.inc
function adm_memb(id,comp_id){
  var parms="";
  parms+="&id="+id;
  parms+="&comp_id="+comp_id;
  var d=new Date();
  parms+="&tst="+d.getTime();
  loadDiv("ajaxWindow","ajax.php?incmod=mods/pub/adm_memb.inc"+parms);
  MessDisplay("ajaxWindow",1,"x-250","y-50","yes");
}
function close_Adm_memb(){
  MessDisplay("ajaxWindow",0,0,0,"yes");
  document.getElementById('ajaxWindow').innerHTML = "";
}
//* adm_memb.inc
function validate_User(){
  if(document.getElementById('email')){
    if(ChkVal("email", "e-Mail Address") == false ) {return false}
  }
  if(document.getElementById('uname')){
    if(ChkVal("uname", "User Name") == false ) {return false}
  }
  if(document.getElementById('passw')){
    if(ChkVal("passw", "Password") == false ) {return false}
  }
}
//* stat_howto and stat_faq
function expdtl(ele){
  var img = ele.getElementsByTagName("IMG");
  var dtlbox = ele.getElementsByTagName("DIV");
  if(dtlbox[0].style.display=="none"){
    dtlbox[0].style.display="inline";
    img[0].src="images/minus.gif";
  } else {
    dtlbox[0].style.display="none";
    img[0].src="images/plus.gif";
  }
}

//* srchdiv.inc (includes)
function sval(){
  if(ChkVal("sstr","Search Criteria")==false) {return false;}
}
//* login.inc
function lval(){
  if(document.getElementById("loginform").action == "index.php?mod=pub&f=register") {
    return true
  }
  if(ChkVal("unam","e-Mail Address")==false) {return false;}
  if(ChkVal("pswd","Password"     )==false) {return false;}
}
function setActionReg() {
  document.getElementById("loginform").action = "index.php?mod=pub&f=register";
}
function relocateToReminder(){
  document.getElementById('loginform').action='index.php?mod=pub&f=pwd_rem';
  document.getElementById('loginform').submit();
}
//* adv_search.inc (includes)
function subSearch(){
  document.getElementById('SForm').submit();
}
function tagItem(ent,ent_id){
  var parms="";
  parms+="&ent="+ent;
  parms+="&ent_id="+ent_id;
  var d=new Date();
  parms+="&tst="+d.getTime();
  loadDiv("ajaxWindow","ajax.php?incmod=mods/pub/tag_add.inc"+parms)
//  MessDisplay("ajaxWindow",1,100,100,"yes")
  window.location.reload();
}
//* tag_lines
function Untag(tag_id){
  var parms="";
  parms+="&tag_id="+tag_id;
  var d=new Date();
  parms+="&tst="+d.getTime();
  loadDiv("ajaxWindow","ajax.php?incmod=mods/pub/tag_remove.inc"+parms)
//  MessDisplay("ajaxWindow",1,100,100,"yes")
  window.location.reload();
}
//* sres.inc
function addS(ele){
  document.getElementById('sstr').value+=" "+ele.innerHTML;
  document.getElementById('srchBtn').click();
}
function newS(ele){
  document.getElementById('sstr').value = ele.innerHTML;
  document.getElementById('srchBtn').click();
}
//*rhmenu.inc
function validInvForm(){
  if(ChkVal("inv_name","Contact's Name"          )==false) {return false};
  if(ChkVal("inv_surn","Contact's Surname"       )==false) {return false};
  if(ChkVal("inv_comp","Contact's Business' Name")==false) {return false};
  if(ChkVal("inv_mail","Contact's e-Mail"        )==false) {return false};
  return true;  
}
//*register.inc
function reg_valid(){
  if(ChkVal("unam","e-Mail Address")==false) {return false;}
  if(ChkVal("name","Name"          )==false) {return false;}
  if(ChkVal("sname","Surname"      )==false) {return false;}
  if(ChkVal("pswd","Password"      )==false) {return false;}
  if(!document.getElementById('reg_tc_chk').checked){
    alert("Please Accept the Terms and Conditions of use before registering");
    return false;
  }
  return true;
}
//*relat_list.inc
function confRel(comp_id,ntyp_id,rel_id) {
  var parms="";
  parms+="&comp_id="+comp_id;
  parms+="&ntyp_id="+ntyp_id;
  parms+="&rel_id="+rel_id;
  var d=new Date();
  parms+="&tst="+d.getTime();
  loadDiv("ajaxWindow","ajax.php?incmod=mods/pub/relat_conf_x.inc"+parms)
//  MessDisplay("ajaxWindow",1,100,100,"yes")
  window.location.reload();
}
//*accnt_paym.inc
function paym_do_click(ele_id){
  document.getElementById(ele_id).click();
  document.getElementById('td_s').style.borderColor = "#CCCCCC";
  document.getElementById('td_c').style.borderColor = "#CCCCCC";
  document.getElementById('td_s').style.backgroundColor = "#FFFFFF";
  document.getElementById('td_c').style.backgroundColor = "#FFFFFF";
  document.getElementById('td_'+ele_id).style.borderColor = "#006600";
  document.getElementById('td_'+ele_id).style.backgroundColor = "#EEFFEE";
  if(ele_id=="c"){
    document.getElementById('dd_s').value="";
    document.getElementById('dd_s').disabled = true;
    document.getElementById('dd_c').disabled = false;
  } else {
    document.getElementById('dd_c').value="";
    document.getElementById('dd_c').disabled = true;
    document.getElementById('dd_s').disabled = false;
  }
  setupPrice()
}

function setupPrice(){
  var parms ="";
  parms+="&curr_id="+document.getElementById('curr_id').value;
  var d=new Date();
  parms+="&tst="+d.getTime();
  if(!document.getElementById('dd_c').disabled){
    parms+="&paym_id="+document.getElementById('dd_c').value;
  } else {
    if(!document.getElementById('dd_s').disabled){
      parms+="&paym_id="+document.getElementById('dd_s').value;
    }
  }
  loadDiv("costDiv","ajax.php?incmod=mods/pub/paym_amt.inc"+parms);
}

//*accnt_paym.inc
function setMonth(month){
  document.getElementById('month').value=month;
  document.getElementById('monthform').submit();
}

//*cred_use_chck.inc
function use_cred(type_id,ent_id,ent_type_id,dtl_ent_id,dtl_ent_type_id){
  var parms ="";
  parms+="&type_id="+type_id;
  parms+="&ent_id="+ent_id;
  parms+="&ent_type_id="+ent_type_id;
  parms+="&dtl_ent_id="+dtl_ent_id;
  parms+="&dtl_ent_type_id="+dtl_ent_type_id;
  var d=new Date();
  parms+="&tst="+d.getTime();
  loadDiv("ajaxWindow","ajax.php?incmod=mods/pub/cred_use.inc"+parms)
  MessDisplay("ajaxWindow",1,1,1,"yes");
  window.location.reload();
}

//* user_upd.inc
function validEmail(){
  if(document.getElementById('new_email').value!=document.getElementById('ret_email').value) {
    alert("New e-Mail Address and Retyped e-Mail Address do not match");
    document.getElementById('ret_email').focus();
    return false;
  }
  if(ChkVal("passwd","Password") == false) {return false};
  document.getElementById('DetForm').submit();
}

//others
function mapclick(key){
  document.getElementById("mapkey").value=key;
  document.getElementById("mapsubmit").submit();
}

//***************************************************************************************/
//Field Validation 
//***************************************************************************************/
String.prototype.trim = function() {
  return this.replace(/(^\s*)|(\s*$)/g, "");
}

function ChkVal(fld_name,fld_descr) {
  document.getElementById(fld_name).value = document.getElementById(fld_name).value.trim();
  if (document.getElementById(fld_name).value == '') {
    alert (fld_descr + " is compulsory");
    document.getElementById(fld_name).focus();
    return false;
  }
}

function ChkNum(fld_name,fld_descr) {
  document.getElementById(fld_name).value = document.getElementById(fld_name).value.trim();
  if (isNaN(document.getElementById(fld_name).value)) {
    alert (fld_descr + " should be numeric");
    document.getElementById(fld_name).select();
    return false;
  }
}

//***************************************************************************************/
//Static Pages Scripts
//***************************************************************************************/
function getDimen() {
  var frameWidth;
  var frameHeight;
  if (self.innerWidth) {
    frameWidth = self.innerWidth;
    frameHeight = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientWidth) {
    frameWidth = document.documentElement.clientWidth;
    frameHeight = document.documentElement.clientHeight;
  } else if (document.body) {
    frameWidth = document.body.clientWidth;
    frameHeight = document.body.clientHeight;
  }
  return(Array(frameWidth,frameHeight));
}

function loadstat(pagename){
  frameWidth = getDimen()[0];
  var cntrpos = (frameWidth-770)/2;
  loadDiv("ajaxWindow","ajax.php?incmod="+pagename+"&pop=yes");
  MessDisplay("ajaxWindow",1,cntrpos,150,"yes");
}

function hidestat(){
  MessDisplay("ajaxWindow",0,0,0,"yes");
  document.getElementById("ajaxWindow").innerHTML="";
}

function doInvite(ele){
  if(document.getElementById("inv_box").style.display=="inline") {
    document.getElementById("inv_arr").src="images/rarr.gif";
    document.getElementById("inv_box").style.display="none";
  } else {
    document.getElementById("inv_arr").src="images/darr.gif";
    document.getElementById("inv_box").style.display="inline";
  }
}

function checkStat(){
  if(document.getElementById('stat_text')){
    frameHeight = getDimen()[1];
    var boxhght = frameHeight-250
    document.getElementById('stat_text').style.height = boxhght;
  }
}

//**************************************************************************************
//  ON the fly dropdown builders
//**************************************************************************************
function addOptions(totarget,criteria,defVal,blankOpt){
  for(var i=(document.getElementById(totarget).options.length-1);i>=0;i--){
    document.getElementById(totarget).options[i] = null;
  }
//  alert ("1 - " + totarget + " = " + criteria + " = " + defVal + " = " + blankOpt);
  if (  (criteria=="")||(criteria=="_")
      ||  (!document.getElementById(criteria))
      ||  (  (document.getElementById(criteria))
           &&(document.getElementById(criteria).value==""))) {
    if (blankOpt){
      document.getElementById(totarget).options[0] = new Option( blankOpt, "", false, false);
    } else {
      document.getElementById(totarget).options[0] = new Option( "Select ...", "", false, false);
    }
    document.getElementById(totarget).disabled = true;
    return false;
  }
  Alloption = document.getElementById(criteria).value.split("|");
  document.getElementById(totarget).disabled = false;
  var selIndex=0;
  var index=0;
  if (blankOpt){
    document.getElementById(totarget).options[index] = new Option( blankOpt, "", false, false);
    index++;
  }
  for(var i=0;i<Alloption.length;i++){
    var o = Alloption[i];
    curOption = o.split("_");
    optVal = curOption[0];
    if (curOption[2]) {
      optDesc="";
      for (o=1;o<curOption.length;o++) {
        if (o>1) {
          optDesc+="_";
        }
        optDesc+=curOption[o]
      }
    } else {
      optDesc = curOption[1];
    }
    if (!defVal) {
      valSel = false;
    } else {
      if (String(optVal)== String(defVal)) {
        selIndex = index;
      }
    }
    document.getElementById(totarget).options[index] = new Option( optDesc, optVal, false, false);
    index++;
  }
  document.getElementById(totarget).options.selectedIndex = selIndex;
}

function initLoad(name,getSql,defVal,blankOpt) {
  var parms="";
  var d=new Date();
  parms+= "&tst="+d.getTime();
  parms+= "&name="  + "temp_"+name;
  parms+= "&getSql=" + getSql;
  loadDiv("ajaxWindow","ajax.php?incmod=includes/selVal.inc" + parms) 
  addOptions(name,"temp_"+name,defVal,blankOpt)
}
//**************************************************************************************

//*****************************************************************************************
// Message Functions
//*****************************************************************************************

function loadMsg(msg_id,dir) {
  window.location.href="index.php?mod=pub&f=comm_view&dir="+dir+"&msg_id="+msg_id;
}

function comm_add_validate(){
  if(document.getElementById('co_id_to').value=="") {
    alert("Business not Found")
    document.getElementById('co_name').select();
    return false;
  }
  if(ChkVal("subj"   ,"Subject"   )==false) {return false}
//  if(ChkVal("msgre"  ,"Regarding" )==false) {return false}
//  if(ChkVal("msg"    ,"Message"   )==false) {return false}
  if(document.getElementById('cred_use')){
    if(document.getElementById('cred_use').checked==false){
      document.getElementById('cred_use_span').className = "highbox";
      alert("Please accept the usage of one Credit");
      return false;
    }
  }  
  area.update()
  document.getElementById('Defform').submit();
}

function msg_changeSubj(){
  document.getElementById('subj').className="";
  document.getElementById("subj").readOnly=false;
  document.getElementById('subj').select();
}

function arch(msg_id,onoff,dir) {
  loadDiv("ajaxWindow","ajax.php?incmod=includes/arcmsg.inc&msg_id="+msg_id+"&onoff="+onoff)
  //MessDisplay("ajaxWindow",1,1,1,"yes");
  window.location.href="index.php?mod=pub&f=comm_list&dir="+dir;
}

var msg_att_proc="n"

function msg_att_validateFld(fldno){
  //alert(fldno)
  document.getElementById('addbtn').style.display="inline";
  document.getElementById('fakefile_'+fldno).value = document.getElementById('userfile_'+fldno).value;
  if(document.getElementById('userfile_'+fldno).value!="") {
    if(
        (document.getElementById('userfile_'+fldno).value.indexOf("&") > 0) 
      ||(document.getElementById('userfile_'+fldno).value.indexOf(",") > 0) 
      ||(document.getElementById('userfile_'+fldno).value.indexOf("(") > 0) 
      ||(document.getElementById('userfile_'+fldno).value.indexOf(")") > 0) 
      ) {
      alert("No special Characters like '&,()' allowed in filenames");
      return false;
    }
    document.getElementById('FileForm_'+fldno).submit();
    document.getElementById('rembtn_'+fldno).style.display="none";
    document.getElementById('upld_anim_'+fldno).style.display="inline";
//    document.getElementById('progressBox_'+fldno).style.display="inline";
    if(msg_att_proc=="n"){
      msg_att_proc="y";
      setTimeout("msg_att_checkUpld()",1000);
      var upld_id = (document.getElementById('UPLOAD_IDENTIFIER_'+fldno).value)
      setTimeout("msg_att_setProg("+upld_id+","+fldno+")",1000);
    }
  }
}

function msg_att_checkUpld(){
  var lastRow = document.getElementById('attachments').rows.length;
  var busyrow = "n";
  for(r=0; r<lastRow; r++) {
    if(document.getElementById('userfile_'+r).style.display!="none"){
//      try {
      if(window.frames['iframe_'+r].document){
        if(window.frames['iframe_'+r].document.getElementById('upl')){
//          alert(2);
          msg_att_setup_Row(r)
        } else {
          busyrow = "y"
        }
//      } catch(err) {
//        alert(1);
//        msg_att_setup_Row(r)
//      }
      }
    }
  }
  if(busyrow=="y") {
    setTimeout("msg_att_checkUpld()",500)
  } else {
    msg_att_proc = "n"
    document.getElementById('val_btn').style.display="inline";
  }
}

function msg_att_setProg(upld_id,fldno){
  loadDiv("progInfo_"+fldno,"ajax.php?incmod=includes/upl_info.inc&ID="+upld_id);
  setTimeout("msg_att_setProg("+upld_id+","+fldno+")",100);
}

function msg_att_setup_Row(r){
  document.getElementById('row_'+r).style.display="none";
  var fnameArr = document.getElementById('userfile_'+r).value.split("\\");
  var fname = fnameArr[(fnameArr.length-1)];
  repname = fname.replace(/ /gi,"_");
  var newfil="";
  if(!document.getElementById('upl_id['+r+']')){
    newfil+= "<table><tr class="+(r%2==0?"evens":"odds")+"><td style='padding:2px'>UPLOADED <b>"+repname+"</b></td>";
    newfil+= "<td><input type='hidden' id='upl_id["+r+"]' name='upl_id["+r+"]' value='"+document.getElementById('UPLOAD_IDENTIFIER_'+r).value+"'>&nbsp;</td>";
    newfil+= "<td><input type='checkbox' id='attach["+r+"]' name='attach["+r+"]' checked>&nbsp;Untick to Remove</td>";
    newfil+= "</tr></table>";
    document.getElementById('uploaded_files').innerHTML+=newfil;
    document.getElementById('att_tbl').style.display ="inline";
  }
}

function msg_att_delRow(rowno){
  document.getElementById('addbtn').style.display="inline";
  var tbl = document.getElementById('attachments');
  tbl.deleteRow(rowno)
  msg_att_checkUpld()
}

function msg_att_addAttach(){
  var parms="";
  var d=new Date();
  parms+="&tst="+d.getTime();
  var loadme = new sack("ajax.php?incmod=includes/get_upld_id.inc"+parms);
  loadme.method = "GET";
  loadme.element = "ajaxWindow";
  loadme.onCompletion = function(){ msg_att_addAttach2(); };
  loadme.runAJAX();   // Execute AJAX function
}

function msg_att_addAttach2(){
  var tbl = document.getElementById('attachments');
  var lastRow = tbl.rows.length;
  var incr = lastRow;
  if(incr>0) {
    if(document.getElementById('userfile_'+(incr-1)).value=="") {
      alert("You have not used the previous Attachment box")
      return false;
    }
  }
  var row = tbl.insertRow(lastRow);
  row.id = "row_"+incr;
  var cellLeft = row.insertCell(0);
  cellLeft.id = "upld_"+incr;
  cellLeft.style.height="20px";
  var newform = document.getElementById('sample').innerHTML;
  newform = newform.replace(/XX/g,incr);
  cellLeft.innerHTML = newform;

  var parms = "&fldr=uploads/";
  parms+= "&upld_id="+document.getElementById('upld_id').value;
  parms+= "&diskn="+document.getElementById('diskn').value;
  var d=new Date();
  parms+= "&tst="+d.getTime();
  document.getElementById('UPLOAD_IDENTIFIER_'+incr).value = document.getElementById('upld_id').value
  document.getElementById('FileForm_'+incr).action="ajax.php?incmod=includes/upl.inc"+parms
  document.getElementById('val_btn').style.display="none";
  document.getElementById('addbtn').style.display="none";
}

function saveAtt(fname,dname){
  var dnArr = fname.split(".");
  document.getElementById('dname').value=dname;
  document.getElementById('fname').value=fname;
  document.getElementById('dldoc').submit();
}

function extMsg(msg_id,r_or_f){
  var parms="";
  parms+="&r_or_f="+r_or_f;
  parms+="&msg_id="+msg_id;
  var d=new Date();
  parms+="&tst="+d.getTime();
  window.location.href="index.php?mod=pub&f=comm_add"+parms;
}

function checkRem(eleid){
  if(document.getElementById('attach["'+eleid+'"]').checked){
    document.getElementById('remove["'+eleid+'"]').value="";
  } else {
    document.getElementById('remove["'+eleid+'"]').value="remove";
  }
}

//*****************************************************************************************
// Help Functions
//*****************************************************************************************
function hlpdisp(onoff,eleid){
  MessDisplay("hlp_"+eleid,onoff,"x-20","y+10","yes")
}

//*****************************************************************************************
// Relationship functions
//*****************************************************************************************

function rel_setupCoId(session_comp){
//  loadDiv("ajaxWindow","ajax.php?incmod=includes/get_co_id.inc&conam="+document.getElementById('co_name').value);
//  var co_id="";
//  if(document.getElementById('co_id__f')){
//    if(document.getElementById('co_id__f').value!=""){
//      var co_id = document.getElementById('co_id__f').value;
//    }
//  }
  //MessDisplay("ajaxWindow",1,100,100,"yes");
  var co_id = document.getElementById('id').value
  if(co_id==""){
    alert("Business NOT found \n\n You may Invite this business to join Confluxes\n\nusing the Invite a Business option on the right-hand side");
    doInvite(document.getElementById('invtbl'));
    document.getElementById('inv_comp').value = document.getElementById('co_name').value
  } else {
    if(co_id==session_comp){
      alert("Your Business may not have a Relationship with itself");
    } else {
      window.location.href='index.php?mod=pub&f=relat_create&id='+co_id;
    }
  }
}
//*****************************************************************************************

function shpmp(attr_pref,attr_def_id,onoff){
  cur_pmp = (attr_def_id=="x"?"x":document.getElementById(attr_pref+'['+attr_def_id+']').value);
  MessDisplay("div_pmp_"+cur_pmp,onoff,"x+10","y-20","no");
}

function shptm(attr_pref,attr_def_id,onoff){
  cur_ptm = document.getElementById(attr_pref+'['+attr_def_id+']').value;
  MessDisplay("div_ptm_"+cur_ptm,onoff,"x+10","y-20","no");
}

function swpmp(attr_pref,attr_def_id){
  cur_pmp = document.getElementById(attr_pref+'['+attr_def_id+']').value;
  MessDisplay("div_pmp_"+cur_pmp,0,0,0,"no");
  new_pmp = (cur_pmp<2?Number(cur_pmp)+1:0);
  document.getElementById(attr_pref+'['+attr_def_id+']').value=new_pmp;
  document.getElementById(attr_pref+'_img_'+attr_def_id).src="images/pmp_"+new_pmp+".gif"
}

function swptm(attr_pref,attr_def_id){
  cur_ptm = document.getElementById(attr_pref+'['+attr_def_id+']').value;
  MessDisplay("div_ptm_"+cur_ptm,0,0,0,"no");
  new_ptm = (cur_ptm<2?Number(cur_ptm)+1:0);
  document.getElementById(attr_pref+'['+attr_def_id+']').value=new_ptm;
  document.getElementById(attr_pref+'_img_'+attr_def_id).src="images/ptm_"+new_ptm+".gif"
}
