function tpage(){if(document.getElementById("rpquery").value="page name"){document.getElementById("rpquery").value="";document.getElementById("rpquery").style.color="#000000";}}
function pagesel(value,data){var md=data.split("/");location.href=siteurl+md[1];}
function initauto(){j$('#rpquery').autocomplete({serviceUrl:siteurls+'edinc/xmlxferq',minChars:2,maxHeight:400,width:300,queryType:'sitepages',onSelect:pagesel});}

function hpmen(m){
   if((omen!=null && autocopen==false) || (omen!=null && m!=null))
      j$("#"+omen).fadeOut("fast");
   if(m!=null)
      j$("#"+m).fadeIn("fast");

   if(autocopen==false || m!=null)
      omen=m;

   if(m!=null){
      var e=j$("#"+m).get(0);
      if(e.innerHTML.length==0)
         j$.get(siteurls+"edinc/edtool/menu-header?menu="+m+"&dt="+new Date().valueOf(),hpmenLoad);
   }
   else
      inithmen(m);
}

function inithmen(m)
{
  if(m=="stmstore")
    document.getElementById("ecsrch").focus();
  if(m=="stmedit")
    document.getElementById("rpquery").focus();
}

function hpmenLoad(m){var p=m.indexOf("-");var mn=m.substring(0,p); m=m.substring(p+1);
if(mn=="pagelist.recent")
{
   var ot="<ul>";
   pdata=eval('(' + m + ')');
   for(t=0;t<pdata.length;t++)
   {
      var p=pdata[t];
      ot=ot+'<li><a href="javascript:gopg(\''+p.pg+'\');">'+p.name+'</a></li>';

   }
   ot=ot+"</ul>";
   document.getElementById("pagelist.recent").innerHTML=ot;
   window.setTimeout("initauto()",100)
   return;
}
if(mn=="stmedit")
   j$.get(siteurls+"edinc/edtool/menu-header?menu=pagelist.recent&dt="+new Date().valueOf(),hpmenLoad);

j$("#"+mn).html(m); inithmen(mn);}

var lover=null;
function movv(e)
{
   if(omen!=null && lover!=e)
      hpmen(null);
   if(lover!=null)
      document.getElementById(lover).style.display="none";
   var e2=document.getElementById(e);
   if(e2!=null){e2.style.display="block";lover=e;}
}

function LTrim( value ) {var re = /\s*((\S+\s*)*)/;return value.replace(re, "$1");}
function RTrim( value ) {var re = /((\s*\S+)*)\s*/;return value.replace(re, "$1");}
function Trim( value ) {return LTrim(RTrim(value));}


function ecfind(p)
{
   var e=document.getElementById("ecsrch");
   if(e!=null)
      {
      var sval=e.value;
      sval=Trim(sval);

      if(p==false)
         {
         if(!isNaN(sval))
            gopg("inc/ss?page=storeOrders/"+sval+"/detail");
         else
            gopg("storecustomers?s="+sval+"*");
         }
      else
         gopg("storesettings/searchresults?s="+sval);

      return;
      }

}
function pgkey(c, e)
{
   if(c.value=='goto page name'){c.value='';}
   var cc;
   if(e && e.which)
       {cc = e.which;}
   else if(window.event)
      {e = window.event;cc=e.keyCode;}
   if(cc == 13) {gopg(c.value.replace(" ","_"));}
}

function ecenter(f, e)
{
   var cc;
   if(e && e.which)
       {cc = e.which;}
   else if(window.event)
      {e = window.event;cc=e.keyCode;}
   if(cc == 13) {ecfind(false);}}



function setipageurl(url,style){
location.href=url;}

function setipageurlcmp(url,style,wix,hix){
if(ipageed==2){
if(wix==null)
   wix=950;
bgw=document.getElementById("bgrw");
bg=document.getElementById("abgr");
fullwidth=document.body.offsetWidth;
ssleft=(fullwidth-wix)/2;
fullheight=document.body.clientHeight;

ssh=document.body.scrollTop;
if(hix==null)
   hix=fullheight-32;
else
   {
   ssh=(fullheight-hix)/2;
   ssh=ssh+document.body.scrollTop;
   }


bg.style.left = ssleft+"px";
bg.style.top = ssh+"px";
bg.style.height=hix;
bg.style.width=wix;

bgw.style.left=0;
bgw.style.display="block";
bgw.style.width=fullwidth;
bgw.style.top=0;
bgw.style.visibility="visible";

bg.style.visibility="visible";
bg.style.display="block";

var inn='<iframe id="axyz" name="preview" src="'+url+'" width=99% height=100% border=0 frameborder=0></iframe>';
document.getElementById("dvaxyz").innerHTML=inn;
//dd=document.getElementById("axyz");
//dd.contentWindow.location.href=url;

setScrollbars(false);
//document.body.style.overflowX="hidden";
return;}
location.href=url;
}

function setScrollbars(v)
{
   //alert(document.body.clientHeight);
//   alert(document.body.clientHeight +" - "+ document.body.scrollHeight);
   var rems=false;
   if(document.body.clientHeight<document.body.scrollHeight)
      rems=true;
   if(v){
      document.body.scroll="yes"
      document.body.style.marginRight="0px";
      document.documentElement.style.overflow = 'auto';   // firefox, chrome
   }
   else {
   if(rems){
   var scw=scwid();
   document.body.style.marginRight=scw+"px";
   document.documentElement.style.overflow = 'hidden';    // firefox, chrome
   document.body.scroll = "no";  // ie only
   }
   }
}


var edpopclick=false;
function edpopclose(po)
{
   if((po && po==true) || location.href.indexOf("parent=true")>0)
      window.parent.edpop('popw',false);
   else
      window.close();
}
function edpopfunc()
{
   if(location.href.indexOf("parent=true")>0)
      return window.parent;
   else
      return window.opener;
}
function edpopcce(e){code=e.keyCode ? e.keyCode : e.which; if(code==27){j$(document).unbind("keypress"); edpopcc();}}
function edpopcc()
{
   if(window.location.href.indexOf("#")<0)
      {
      edpop('popw',false);
      }
   else
      window.setTimeout("edpopcc()",100);
}
function bkchk()
{
   if (location.href.indexOf("#bk")<0)
   {  edpop('popw',false);
      closebldg2();
      window.clearInterval(bkck);
   }
}

var bkurl=null;
var bkck=null;
function startbk()
{
   bkurl=location.href;
   location.href=location.href+"#bk";
   bkck=window.setInterval("bkchk()",100);
}

function scwid() {
  var s = null;
  var i = null;
  var wns = 0;
  var ws = 0;
  s = document.createElement('div');
  s.style.position='absolute';
  s.style.top='100px';
  s.style.left='100px';
  s.style.width='200px';
  s.style.height='150px';
  i = document.createElement('div');
  i.style.width='100%';
  i.style.height='200px';
  s.appendChild(i);
  document.body.appendChild(s);
  s.style.overflow='hidden';
  wns = i.offsetWidth;
  s.style.overflow='scroll';
  ws = i.offsetWidth;
  if (wns == ws) ws = s.clientWidth;
  document.body.removeChild(document.body.lastChild);
  var a = (wns - ws);
  return a;
 }


function edpop(divid,state,url,settings){
edpopclick=true;
bg=document.getElementById(divid);
showbgrw(state,0)
if(state)
   {
   //check for settings width/height
   if(url!=null)
      {
      var exu="&";
      if(url.indexOf("?")<0)
         exu="?"
      url=url+exu+"parent=true";
      var bgi=document.getElementById(divid+"-inner");
      var w=800;
      var h=600;
      if(settings.size!=null && settings.size=="lib"){w=800;h=700;}

      if(settings.w!=null){w=settings.w;h=settings.h;}
      if(h>document.body.clientHeight || document.body.clientHeight<800)
         h=document.body.clientHeight-130;

      //set to true to so that you can click the background to close the popup
      edpopclick=true;
      if(url.charAt(0)!="/")
         url=siteurl+url;
      bgi.innerHTML='<iframe src="'+url+'" style="width:'+w+'px;height:'+h+'px" border=0 frameborder=0></iframe>';
      }

   //setup the escpae key
   //document.body.onKeyPress=edpopcce;
   j$("body").keypress(edpopcce);

   bg.style.display="block";
   fw=document.body.offsetWidth-20;
   ssleft=(fw-bg.clientWidth)/2;
   fh=document.body.clientHeight;
   ssh=(fh-bg.clientHeight)/2;
   ssh+=document.body.scrollTop;
   bg.style.left=ssleft;
   bg.style.top=ssh;
   bg.style.visibility="visible";
   }
else
   {
   document.body.scroll="yes"
   }
}


function showedwin(){
bg=document.getElementById("bgr");
if(bg.style.display=="block" || bg.style.display==""){closebldg();return;}
if(bg.style.display=="block" || bg.style.display==""){closebldg();return;}
fw=document.body.offsetWidth-20;
ssleft=fw/2-400;
fh=document.body.clientHeight;
ssh=(fh-700)/2;
ssh=document.body.scrollTop;
bg.style.left=ssleft;
bg.style.top=ssh;
bg.style.height=document.body.offsetHeight;
bg.style.width=900;
bg.style.visibility="visible";
document.getElementById("bgr").style.display="block";
//Effect.SlideDown("bgr",{duration:.8});
}

function showbgrw(val,t){
edpopclick=false;
bgw=document.getElementById("bgrw");
if(val==true){
setScrollbars(false);
bgw.style.left=0;
//bgw.style.display="block";
bgw.style.width="100%";
bgw.style.top=t;
bgw.style.visibility="visible";
//bgw.style.display="block";
j$(bgw).fadeIn("fast");
}
else{
   //bgw.style.display="none";
   setScrollbars(true);
   bg.style.display="none";

   j$(bgw).fadeOut("fast");
//bgw.style.visibility="hidden";
//bgw.style.display="none";
}
}

function closebldgw(){showbgrw(false,0);
j$("#comp"+ez_lastcomp).effect("highlight",{},2000);
}
function closebldg(){bg=document.getElementById("bgr");document.getElementById("bgr").style.display="none";
closebldgw();
setScrollbars(true);
}

function closebldg2(){bg=document.getElementById("abgr");
if(bg && bg.style.display=="block")
   {
   setScrollbars(true);
   bg.style.display="none";
   closebldgw();
   }
};

function closemsg(){document.getElementById('edmsg').style.visibility='hidden';}
function togprops(sec){d=document.getElementById("qmenu");if(d.style.display!="none"){togpropsclose();return;};showbgrw(true,90);document.getElementById('wpprops').src=siteurl+"edinc/pageprops/"+sec;
if(d.style.display!="")
   j$("#qmenu").show("blind",{direction:"vertical"},"slow");}
function togpropsex(sec){d=document.getElementById("qmenu");if(d.style.display!="none"){togpropsclose();return;};showbgrw(true,90);document.getElementById('wpprops').src=sec;
if(d.style.display!="")
   j$("#qmenu").hide("blind",{direction:"vertical"},"slow");
}

function togpropsclose(){
j$("#qmenu").slideUp("slow");
showbgrw(false,0);}
function togqm(){d=document.getElementById("qmenu");if(d.style.display=="block")d.style.display="none";else d.style.display="block"; }
function togq(A){d=document.getElementById("qprops");if(d.style.visibility=="hidden")d.style.visibility="visible";else d.style.visibility="hidden"; }
function togql(A){d=document.getElementById("qlayout");if(d.style.visibility=="hidden")d.style.visibility="visible";else d.style.visibility="hidden"; }

function lo2(){
   dem=document.getElementById("edmsg");
   if(dem.style.visibility!="hidden")
      window.open(siteurl+'inc/timeout','_self');}

function locontf(r,c){}

function locont(){
   dem=document.getElementById("edmsg");
   dem.style.visibility="hidden";
   ajaxSend(siteurl+"edinc/xmlxfer?rtype=hb",{"onComplete":locontf});
   window.setTimeout('lo()',timout);}

function lo(){
   window.setTimeout('lo2()',1000*60*30);
   var d=new Date();
   dem=document.getElementById("edmsg");
   dem.style.visibility="visible";
   fw=document.body.offsetWidth;
   fh=document.body.clientHeight;
   ml=(fw-650)/2;
   mt=(fh-300)/2-100;
   mt=mt+document.body.scrollTop;
   dem.style.left = ml;
   dem.style.top = mt;
   de=document.getElementById("edmsgtxt");
   de.innerHTML="<div style='background-color:#444444;color:#ffffff;padding:5px'><b>"+propSysName+" : SESSION TIMEOUT : SOON</b></div><div style='padding:3px'><P>Your session is about to time out.  To prevent your session from timing out and continue working on your site, click link below.<P>The time is "+d.getHours()+":"+d.getMinutes()+". Your browser has been inactive for 60 minutes.  Sessions timeout after 90 minutes at which point you are automatically logged out of your site editor.  If you are working on your site, be sure to save your work now.</div>";}

function iedtitle1start(c){document.write('<div class="'+c+'"><table border=0 width="100%" cellspacing=0><tr><td  nowrap class="s1" width="1%">');}
function iedtitle1stop(){document.write('&nbsp;&nbsp;</td><td class="s2" width="50%">&nbsp;</td><td class="s3" width="49%">&nbsp;&nbsp;</td></tr></table></div>');}

var dmenuov=false;
function showdesignm(){d=document.getElementById("dmenu");d.style.visibility="visible";}
function hidedesignm(){window.setTimeout("dohidedesignm()",300);}
function dohidedesignm(){
if(dmenuov==false){
d=document.getElementById("dmenu");
d.style.visibility="hidden";}
}
function ipagetitle(txt){document.write('<div class="pagetitle1"><table cellpadding=0 border=0 cellspacing=0 width=100%><tr><td class="s1" width="1%"></td><td width="98%" class="s2">'+txt+'</td><td class="s3" width="1%">&nbsp;</td></tr></table></div>');}

function overedbtn(b){b.style.backgroundColor="#dfdfdf";b.style.borderColor="#000000";}
function outedbtn(b){b.style.backgroundColor="";b.style.borderColor="";}

function prowover(b,pid){
   if(moving==false && b && b.issel!=true)
      {
      b.style.backgroundColor="#efefef";
      b.style.borderColor="#000000";
      if(b.mdiv==null){
        c=document.getElementById("pdiv"+pid);
        b.mdiv=c;
        }
      b.mdiv.style.visibility="visible";}
}
var lastsel=null;
function prowout(b,pid)
{if(moving==false && b && b.issel!=true){
      b.style.backgroundColor="";
      b.style.borderColor="";
      if(b.mdiv==null){
        c=document.getElementById("pdiv"+pid);
        b.mdiv=c;}
      b.mdiv.style.visibility="hidden";
      }
}

function clearsel(pid){
if(lastsel!=null && lastsel!=pid){
  r=document.getElementById("prow"+lastsel);
  r.issel=false;
  prowout(r,pid); }
   lastsel=null;
}

var lastpage=null;
var lastparent=null;
var moving=false;

function showmaction(ev,b,parent,pid){
   d=document.getElementById("maction");
   d.style.visibility="visible";
   x=ev.clientX;
   y=ev.clientY;
   d.style.top=(y+document.body.scrollTop)+"px";
   d.style.left=x+"px";
   lastpage=pid;
   lastparent=parent;}
function movepage(to){
   d=document.getElementById("maction");
   d.style.visibility="hidden";
   from=document.getElementById("plist"+lastparent);
   too=document.getElementById("plist"+to);
   e=document.getElementById("prow"+lastpage);
   window.open(thispage+"?mpid="+lastpage+"&fr="+lastparent+"&to="+to,'_self');}
function showgroup(gr){
   window.open(thispage+"?mview="+gr,'_self');}
function rowhighlight(b,clr){
   if(clr==null)
      clr="dfdfdf";
   b.style.backgroundColor='#'+clr}
function rownormal(b){ b.style.backgroundColor='';}
function mover(b){}
function mout(b){}
function pup(pid){
   clearsel(pid);
   r=document.getElementById("prow"+pid);
   r.issel=true;
   lastsel=pid;
   r.style.backgroundColor="#b0e6f1";
   if(r.previousSibling!=null)
      r.swapNode(r.previousSibling);
   moving=true;
   window.setTimeout("clearpmove()",2500);}

function pdn(pid){
   clearsel(pid);
   r=document.getElementById("prow"+pid);
   r.issel=true;
   lastsel=pid;
   r.style.backgroundColor="#b0e6f1";
   if(r.nextSibling!=null)
      r.swapNode(r.nextSibling);
   moving=true;
   window.setTimeout("clearpmove()",2500);
}
function clearpmove(){
   r=document.getElementById("prow"+lastsel);
   if(r){
   r.issel=false;
   lastsel=null;
   moving=false;
   prowout(r,lastsel)}
}
function goe(u){location.href=u;}
function overedbtn(b,c){if(c=="editbtn"){b.className="editbtn editbtno"}}
function outedbtn(b,c){b.className=c;}
function editbtn(txt,url,img,js,bclass){
if(!bclass || bclass==null || bclass.length==0)
   bclass="editbtn";
if(js==false){
   var u="'"+url+"'";
   document.write('<table cellpadding=0 cellspacing=0 border=0><tr><td><div class="'+bclass+'" onClick="goe('+u+');return false;" onMouseOver="overedbtn(this,\''+bclass+'\');" onMouseOut="outedbtn(this,\''+bclass+'\');"><table cellpadding=0 cellspacing=0 border=0 width="100%"><tr><td class="bl" width=1% valign=middle><a href="'+url+'" onClick="event.cancelBubble=true"><span><img src="'+imroot+'/i/t/w/btn/'+img+'" border=0></span></a></td><td class="br" width=99%><a href="'+url+'" onclick="event.cancelBubble=true"><span>'+txt+'</span></a></td></tr></table></div></td></tr></table>');
   }
else{
   document.write('<table cellpadding=0 cellspacing=0 border=0><tr><td><div class="'+bclass+'"  onClick="'+url+';return false;" onMouseOver="overedbtn(this,\''+bclass+'\');" onMouseOut="outedbtn(this,\''+bclass+'\');"><table cellpadding=0 cellspacing=0 border=0  width="100%"><tr><td class="bl" width=1% valign=middle><a href="" onClick="event.cancelBubble=true;'+url+';return false;"><span><img src="'+imroot+'/i/t/w/btn/'+img+'" border=0></span></a></td><td class="br" width=99%><a href="" onClick="event.cancelBubble=true;'+url+';return false;"><span>'+txt+'</span></a></td></tr></table></div></td></tr></table>');
   }
}

function editbtnstart(bclass){
if(bclass==null || bclass.length==0)
   bclass="editbtn";
document.write('<table cellpadding=0 cellspacing=0 border=0><tr><td><div class="'+bclass+'" onMouseOver="overedbtn(this)" onMouseOut="outedbtn(this)"><table cellpadding=0 cellspacing=0 border=0><tr><td valign=middle>');
}
function editbtnend(){document.write('&nbsp;</td></tr></table></div></td></tr></table>');}
function btnback(url){document.write('<div class="editback"><table cellpadding=0 cellspacing=0 border=0><tr><td><a href="'+url+'"><img src="'+imroot+'/i/t/w/btn/pagesback.gif" border=0></a></td><td><font size=2>&nbsp;</font><a href="'+url+'">Go back</a></td><td><img src="'+imroot+'/i/t/w/rnddot.gif" width=10 height=1></td></tr></table></div>');}
function ieditdivider(){}
function ieditfooter(){document.write('<div class="ieditfooter">'+propSysNameLong+'<br><a href="http://'+propHomeLink+'">'+propHomeLink+'</a><p>&nbsp;</center></div>');}

function ajaxSend(url,robj){
function ajback(){
if (ajr.readyState == 4) {
  if (ajr.status == 200) {
    if(ajr.responseText.indexOf("err:")==0)
      {
      if(cobj.onError)
        cobj.onError(ajr,cobj);
      }
    else if (cobj.onComplete)
       cobj.onComplete(ajr,cobj);
    }
  else
    if(cobj.onError)
       cobj.onError(ajr,cobj);
  }
}
var ajr = null;
var cobj = robj;
var td = new Date();
url=url+"&d="+td.getTime();

if (window.XMLHttpRequest) {
ajr = new XMLHttpRequest();
ajr.onreadystatechange = ajback;
ajr.open("GET", url, true);
ajr.send(null);
} else if (window.ActiveXObject) {
ajr = new ActiveXObject("Microsoft.XMLHTTP");
if (ajr) {
ajr.onreadystatechange = ajback;
ajr.open("GET", url, true);
ajr.send();
}}
}
function getParam(window,param){
query=window.location.search;
if(query.length==0)return "";
query=query.substring(1);
var params=query.split("&");
for(var i=0;i<params.length;i++)
{
var pos=params[i].indexOf("=");
var name=params[i].substring(0, pos);
if(name==param)
 return params[i].substring(pos + 1);
}
return null;
}

function centerdiv(divid)
{
   bg=document.getElementById(divid);
   fw=document.body.offsetWidth-20;
   ssleft=(fw-bg.clientWidth)/2;
   fh=document.body.clientHeight;
   if(bg.clientHeight<fh)
      ssh=(fh-bg.clientHeight)/2;
   else
      ssh=0;
   ssh+=document.body.scrollTop;
   bg.style.left=ssleft;
   bg.style.top=ssh;
}

function addSubmitFunc(funcname)
{
numSubmitFunctions=numSubmitFunctions+1;
SubmitFunctions[numSubmitFunctions]=new Function(funcname);
}

if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (this[from] === elt)
        return from;
    }
    return -1;
  };
}


