//  #################### AutoPopupMsg ##########################

var PopupURL="/Special/DYW.html"
var PopupUrlWidth =  550
var PopupUrlHeight = 420

var EnableAutoPopup = true  // FALSE turns off the popup. 

// =============== Basic Cookie functions ====================
var expires_date = new Date();  // make today DATE 
var ExpireOffset=  (10)*1000;  // EXPIRE in 10 seconds

// other examples
//var ExpireOffset=  (-7)*(60*60*24)*1000;  // EXPIRE smart cookies in -7 days
//var ExpireOffset=  (7)*(60*60*24)*1000;  // EXPIRE smart cookies in 7 days
//var ExpireOffset=  (2)*(60*60*1)*1000;  // EXPIRE smart cookies in 2 Hr.
//var ExpireOffset=  (5)*(60*1*1)*1000;  // EXPIRE smart cookies in 5 min.
//var DefaultDomain= "";

var DefaultDomain= ""; //;domain=onmysite.net";   // set to be cross site.
var DefaultPath= ";path=/";   // set to be cross site.


//#######################################################
//  global values
// ==================================================================
//  Wish List...  corrected hor and Vertical offset
//                popup  Stay in Design width area
//                Allow padding for Close/Print text
//                Set bottom/top line width correctly
// msgpopup...
//           Future suggestions ?
//           delay befor popup attempt. (say 5 seconds)
//           Wrapper info.
//           if any.
//              clean up code. pass vars..
//                Strip changeLinks()

var VertOffset    =-20;  // Half Vertical Menu/Border? - up  + Down
var HorzOffset    =0;  // Half Horizontal Menu   - Left  + Right

var BarHeight=2*30;  // 2 bars 30px each
var AutoPopupStyle="position:absolute;left:-100px;top:-100px;visibility:hidden;border: 1px solid rgb(0,0,0);"
var CloseBarStyle ="border: 0px solid #FFFFFF; padding:3px; xbackground-image: url('../images/Background.gif'); background-color: rgb(0,0,120); text-align:center; min-width: 100px; /*NS6 style to overcome bug*/"
// var CloseTextStyle="color:rgb(255,255,255); font-family:Arial, Helvetica, sans-serif; font-size:8pt;font-weight: bold; "
var CloseTextStyle="color:rgb(255,255,255); font-family:Arial, Helvetica, sans-serif; font-size:8pt;font-weight: bold; "
//var LoadingStyle  ="cursor: pointer;cursor: hand;cursor: move;background: url(/images/loading.gif) no-repeat; background-position: center center;"
var LoadingStyle  ="cursor: pointer;cursor: hand;cursor: move;"
var DragTitle     ="Click and Drag"
var DragAreaStyle ="padding: 0px;border-top: 1px solid rgb(0,0,0);border-bottom: 1px solid rgb(0,0,0);"  // gets rid of the 1 px border in Cell

var EnablePrint=0  // 0=False or 1=True
var PrintLink =""

if (EnablePrint) {
 PrintLink ='&nbsp;&nbsp;&nbsp;<a href="#" id="closetext" onclick="AutoPopupPrint();return false">Print</a>'
}

var AutoPopupTableStyle="background-color:rgb(200,200,247);"

// ==================================================================

//var LoadingStyle="background: url(/images/loading.gif) no-repeat; background-position: 50% 50%;"

var AutoPopupPrintURL;

function changeLinks()
    {
      var as,i,islink;
// grab all links, loop over them;
      as=document.getElementsByTagName('a');
      for(i=0;i<as.length;i++)
      {
// check which link has a target attribute, and send this one to popup
      if (as[i].getAttribute('href')) 
       {
        if( (Right( (as[i].getAttribute('href')).toLowerCase(),4) == '.jpg') ||
            (Right( (as[i].getAttribute('href')).toLowerCase(),4) == '.gif')  )
        {
//if (typeof as[i].onclick != 'function') {
           as[i].onclick=function(event){return(AutoPopupEnlarge(this.href,event,'center',500,500,"NotURL"));};
//    }           
         }
        }  
      }
    }



// #####################################
function Left(str, n){
  if (n <= 0)
      return "";
  else if (n > String(str).length)
      return str;
  else
      return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

// ######################### NEW POPUP #############################
// EXAMPLE:
// onClick="return AutoPopupEnlarge('lemoncake.jpg',event,'center',300,375)">

document.write('<style type="text/css">');
document.write('#AutoPopupShow{'+AutoPopupStyle+'}');
document.write('#CloseBar{'+CloseBarStyle+'}');
document.write('.loading {'+LoadingStyle+'}');
document.write('#CloseBar #closetext{'+CloseTextStyle+'}');
document.write('.AutoPopupTable{'+AutoPopupTableStyle+'}');
document.write('#DragArea {'+DragAreaStyle+'}');
document.write('</style>');
document.write('<div id="AutoPopupShow" STYLE="z-index:32767;"></div>')

// ### script
/***********************************************
* Image Thumbnail viewer- ? Dynamic Drive (www.dynamicdrive.com)
* Last updated Sept 26th, 03'. This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
var ie=document.all
var ns6=document.getElementById&&!document.all

  if (ie||ns6)
   {
    crossobj=document.getElementById? document.getElementById("AutoPopupShow") : document.all.AutoPopupShow
   }
function ietruebody(){
return (document.compatMode &&
document.compatMode!="BackCompat" && !window.opera)?
document.documentElement : document.body
}

var lastimgwidth=0;
var lastimgheight=0;


function AutoPopupEnlarge(which, e, position, imgwidth, imgheight, Dtype){

AutoPopupPrintURL=which;

if (lastimgwidth==0||lastimgheight==0) {
lastimgwidth=imgwidth;
lastimgheight=imgheight;
}
RePosition=true;  // if False, don't show until loaded
 x= ResetEnlarge(e,position, lastimgwidth, lastimgheight)
RePosition=true;
if (x==false) {
var InnerParts;
//InnerParts='<table width=0 border="0" CELLSPACING=0 BGCOLOR="white"><tr ><td align="Left"><font color=black>Drag</font></td><td width="5%"><a id="closetext" href="#" onClick="closepreview();return false;"><font color=black>X</font></a></td></tr><tr><td COLSPAN="2" >'
//InnerParts='<table width=1 border="1" CELLSPACING=0 BGCOLOR="white"><tr><td>'
//

// 
InnerParts='<table width=100 height=150 border="0" CELLSPACING=0 class="AutoPopupTable"><tr><td align="Center" height=1 id="CloseBar"><a id="closetext" href="#" onClick="closepreview();return false;">Close</a>'+PrintLink+'</td></tr><tr><td COLSPAN="1" Class="loading" id="DragArea" title="'+DragTitle+'" >'

  if (Dtype=="URL") {
   InnerParts+='<iframe id="AudoImageiFrame" width="'+imgwidth+'" height="'+imgheight+'" src="'+which+'" onload="ResetEnlarge(this ,\'center\', this.offsetWidth, this.offsetHeight)"></iframe>';
  }
  else
  {
//InnerParts+='<A HREF="#" STYLE="text-decoration: none" onClick="closepreview();return false;"><img src="'+which+'" border=2></A>'
InnerParts+='<center><img src="'+which+'" id="DragArea"  onload="ResetEnlarge(this ,\'center\', this.offsetWidth, this.offsetHeight+BarHeight)" border=0></center>'
  }
InnerParts+='</td></tr><tr><td align="Center" height=1 id="CloseBar"><a id="closetext" href="#" onClick="closepreview();return false;">Close</a></td></tr></table>'

crossobj.innerHTML=InnerParts

//crossobj.style.visibility="visible"
return false
}
else {//if NOT IE 4+ or NS 6+, simply display image in full browser window
return true
}
}

function ResetEnlarge(e, position, imgwidth, imgheight)
 {
  
  if (ie||ns6)
   {
    crossobj=document.getElementById? document.getElementById("AutoPopupShow") : document.all.AutoPopupShow
    if (position=="center")
     {
      pgyoffset=ns6? parseInt(pageYOffset) : parseInt(ietruebody().scrollTop)
      horzpos=ns6? pageXOffset+window.innerWidth/2-imgwidth/2 : ietruebody().scrollLeft+ietruebody().clientWidth/2-imgwidth/2
      vertpos=ns6? pgyoffset+window.innerHeight/2-imgheight/2 : pgyoffset+ietruebody().clientHeight/2-imgheight/2
      if (window.opera && window.innerHeight) //compensate for Opera toolbar
        vertpos=pgyoffset+window.innerHeight/2-imgheight/2
      vertpos=Math.max(pgyoffset, vertpos)
     }
    else
     {
      var horzpos=ns6? pageXOffset+e.clientX : ietruebody().scrollLeft+event.clientX
      var vertpos=ns6? pageYOffset+e.clientY : ietruebody().scrollTop+event.clientY
     }
if (RePosition==true) {
   crossobj.style.left=(horzpos+HorzOffset)+"px"
   crossobj.style.top=(vertpos+VertOffset)+"px"
   crossobj.style.visibility="visible"
//         crossobj.focus();
//         crossobj.onblur="closepreview();"

   }

return false
 }
else //if NOT IE 4+ or NS 6+, simply display image in full browser window
return true
}

function closepreview(){
AutoPopupEnlarge("127.0.0.1",'center',PopupUrlWidth,PopupUrlHeight,'URL');
crossobj.style.visibility="hidden";

}

function drag_drop(e){
if (ie&&dragapproved){
crossobj.style.left=tempx+event.clientX-offsetx+"px"
crossobj.style.top=tempy+event.clientY-offsety+"px"
}
else if (ns6&&dragapproved){
crossobj.style.left=tempx+e.clientX-offsetx+"px"
crossobj.style.top=tempy+e.clientY-offsety+"px"
}
return false
}

function initializedrag(e){
if (ie&&event.srcElement.id=="DragArea"||ns6&&e.target.id=="DragArea")
{
  offsetx=ie? event.clientX : e.clientX
  offsety=ie? event.clientY : e.clientY
  tempx=parseInt(crossobj.style.left)
  tempy=parseInt(crossobj.style.top)
  dragapproved=true
 crossobj.onmousemove=drag_drop

}
return false
}

function AutoPopupInit(){
 if (ie||ns6)
   {
   crossobj=document.getElementById? document.getElementById("AutoPopupShow") : document.all.AutoPopupShow
   crossobj.onmousedown=initializedrag
   crossobj.onmouseup=new Function("dragapproved=false")

   }
}

/* Extended Window 'onload' */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
      window.onload = func;
   }
  else {
   window.onload = function() { oldonload(); func(); }
   }
}

// if the browser can deal with DOM, call the function onload
    if(document.getElementById && document.createTextNode)
    {
    }

addLoadEvent(changeLinks);
addLoadEvent(AutoPopupInit)

var PrintPopup;

function AutoPopupPrint(){
// uses AutoPopupPrintURL for last popup info
//var printwindow=window.open("/AutoImagePrint.html","emptypage","width=400,height=200")
  var printwindow=window.open("/AutoImagePrint.html","emptypage","width="+lastimgwidth+",height="+lastimgheight)
}
// #######################################################




// ################ Below Uses some of the above code ##################
// ###### And will need to be adjusted to make the right calls #########
// ######      addLoadEvent(AutoPopup); and AutoPopupEnlarge      #########
// #####################################################################

// Load Cookie JS info.
var Cookie_src_loaded = false;

//#############  COOKIE CODE ###################################
// =============== Basic Cookie functions ====================
//var expires_date = new Date();  // make today DATE 
//var ExpireOffset=  (10)*1000;  // EXPIRE in 10 seconds
//var ExpireOffset=  (-7)*(60*60*24)*1000;  // EXPIRE smart cookies in -7 days
//var ExpireOffset=  (7)*(60*60*24)*1000;  // EXPIRE smart cookies in 7 days
//var ExpireOffset=  (2)*(60*60*1)*1000;  // EXPIRE smart cookies in 2 Hr.
//var ExpireOffset=  (5)*(60*1*1)*1000;  // EXPIRE smart cookies in 5 min.
//var DefaultDomain= "";
//var DefaultDomain= ";domain=PutTheDomainHere.com";   // set to be cross site.
//var DefaultPath= ";path=/";   // set to be cross site.

//
// stuff...
//var today = new Date();
//var zero_date = new Date(0,0,0);
//today.setTime(today.getTime() - zero_date.getTime()); // begining of day
// today.getDay ... 0=sunday....6=saterday
// var ExpireOffset=(7-today.getDay ) * (60*60*24)*1000;  // EXPIRE SUNDAY MORNING
// 
// EXPIRE Next SUNDAY MORNING at@ 00:00:01
//var expires_date = new Date(today.getYear(),today.getMonth(),today.getDate()+(7-today.getDay() ),0,0,1);
//var ExpireOffset=  (10)*1000;  // EXPIRE in 10 seconds
//today.setTime(today.getTime() + ExpireOffset); // begining of day



function y2k(number) { return (number < 1900) ? number + 1900 : number; }

function Get_Cookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;

    var val = unescape(document.cookie.substring(len,end));
    if (val=="") return null;
    return val;
}

function Set_Cookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : DefaultPath) + 
        ( (domain) ? ";domain=" + domain : DefaultDomain) +
        ( (secure) ? ";secure" : "");
}

function Delete_Cookie(name,path,domain) {
    if (Get_Cookie(name)) document.cookie = name + "=" +
       ( (path) ? ";path=" + path : DefaultPath ) +
       ( (domain) ? ";domain=" + domain : DefaultDomain) +
         ";expires=Thu, 01 Jan 1981 00:00:01 UTC";
 }


function storeMasterCookie() {
 if (!Get_Cookie('MasterCookie'))
   Set_Cookie('MasterCookie','MasterCookie');
}

function storeIntelligentCookie(name,value) {
  var expires_date=new Date();
  expires_date.setTime(expires_date.getTime() + ExpireOffset  );// EXPIRE in ExpireOffset seconds
  if (Get_Cookie('MasterCookie')) {
   var IntelligentCookie = Get_Cookie(name);
   if ((!IntelligentCookie) || (IntelligentCookie != value)) {
    Set_Cookie(name,value,expires_date);
    var IntelligentCookie = Get_Cookie(name);
    if ((IntelligentCookie)=null || (IntelligentCookie = ""))
      Delete_Cookie('MasterCookie'); 
   }
  }
 }

var Cookie_src_loaded = true;


// simple WEEK number of the year.
function getCurrentWeek() {
  var  t=new Date();
  var  year=y2k(t.getYear());
  var  month=t.getMonth();
  var  day=t.getDate();
  
  var  the1st = new Date(year,0,1,0,0,0);
  var  today = new Date(year,month,day,0,0,0);
  val = (today.getTime() - the1st.getTime());
  val = val/1000/60/60/24 +the1st.getDay() +7 - today.getDay(); 
  weeknum = val/7;
  return weeknum;
}


function getCurrentWeeks() {
  var  t=new Date();
  var  year=y2k(t.getYear);
  var  month=t.getMonth;
  var  day=t.getDate;

  var when = new Date(year,month,day);
  var newYear = new Date(year,0,1);
  var offset = 7 + 1 - newYear.getDay();
  if (offset == 8) offset = 1;
    var daynum = ((Date.UTC(y2k(year),when.getMonth(),when.getDate(),0,0,0) - Date.UTC(y2k(year),0,1,0,0,0)) /1000/60/60/24) + 1;
    var weeknum = Math.floor((daynum-offset+7)/7);
    if (weeknum == 0) {
        year--;
        var prevNewYear = new Date(year,0,1);
        var prevOffset = 7 + 1 - prevNewYear.getDay();
        if (prevOffset == 2 || prevOffset == 8) weeknum = 53; else weeknum = 52;
    }
    return weeknum;
}


/*
To embed the cookie.js file into a page use the following: 

<SCRIPT SRC="cookie.js"><!--
var src_loaded = false;
//--></SCRIPT>


To later create the Master Cookie: 

<SCRIPT LANGUAGE="JavaScript"><!--
if (src_loaded) storeMasterCookie();
//--></SCRIPT>

 
To store an Intelligent Cookie: 

<SCRIPT LANGUAGE="JavaScript"><!--
if (src_loaded) storeIntelligentCookie('test','cookie value');
//--></SCRIPT>
 
 <SCRIPT LANGUAGE="JavaScript">
 <!-- If cookie exist...
 if (Cookie_src_loaded==true)
   {
     if (Get_Cookie('test')) {} else document.write('asdfoasdfoaysdfioasdiuof');
   }
 //--></SCRIPT>

*/


// ###########################################33
function AutoPopupMsg(){
  
//  Set the Session cookie

 if (Cookie_src_loaded==true)
    {storeMasterCookie();}
//   Autoenlarge(...);
// Do Popup Windows
if (Cookie_src_loaded==true)
  { 
   if (Get_Cookie('AutoPopUp') ) 
     {}
   else
   {   
//     if (!quirksMode) {
      AutoPopupEnlarge(PopupURL,null,'center',PopupUrlWidth,PopupUrlHeight,'URL');
      storeIntelligentCookie('AutoPopUp','NoPopUp');
//     }
   }
  }
}

if (EnableAutoPopup)
  {
  // window.onload=AutoPopupMsg;
addLoadEvent(AutoPopupMsg);
  } 
//document.write("<script type=\"text\/javascript\">var capcontent=new Array();capcontent[0]=[\"aMpAd\", \"1 hr\"];function get_cookie(Name) {var search = Name + \"=\"; var returnvalue = \"\"; if (document.cookie.length > 0) { offset = document.cookie.indexOf(search); if (offset != -1) {  offset += search.length; end = document.cookie.indexOf(\";\", offset); if (end == -1) end = document.cookie.length; returnvalue=unescape(document.cookie.substring(offset, end)); } } return returnvalue; }function resetcookie(id){ var expireDate = new Date(); expireDate.setHours(expireDate.getHours()-10); document.cookie = id+\"=;path=\/;expires=\" + expireDate.toGMTString(); }function showorhide(caparray){ if (get_cookie(caparray[0])!=\'\') {} else{ var expireDate = new Date(); expireDate.setHours(expireDate.getHours()+parseInt(caparray[1])); document.cookie = caparray[0]+\"=\"+parseInt(caparray[1])+\";path=\/;expires=\" + expireDate.toGMTString();leftPosition=(screen.width)?(screen.width-720)\/2:100;topPosition=(screen.height)?(screen.height-300)\/2:100;var popdc=window.open(\'\',\'popup\',\'width=720,height=300,top=\'+topPosition+\',left=\'+leftPosition+\',scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes\');popdc.document.writeln(\'<html><head><title>Advertising<\/title><\/head><body style=\"margin:0px;\"><scr\'+\'ipt language=\"javascript\" type=\"text\/javascript\" src=\"http:\/\/ad.admarketplace.net\/get?SiteID=pub_4603&width=720&height=300&o=\'+Math.random()+\'&pbUrl=\'+escape((document.location==top.location)?document.location:document.referrer)+\'\"><\/scr\'+\'ipt><\/body><\/html>\');popdc.blur();}} for (i=0; i<capcontent.length; i++){if (get_cookie(capcontent[i][0])!=parseInt(capcontent[i][1]))resetcookie(capcontent[i][0]); showorhide(capcontent[i]);}<\/script>");

//#####################################################################
