/* a collection of window tricks. */

/* first, declare the variable newWin that will be used 
for the new window object. */
var newWin;

function basicWindow(url,w,h) {
settings = '"toolbar=no, directories=no,menubar=no,scrollbars=no,resizable=no,status=no,width='+w+',height='+h+'"';
closeWindow();
newWin = window.open(url,'newWin',settings);
newWin.focus();
}

function allWindow(url,w,h) {
settings = '"toolbar=yes,titlebar=yes,location=yes,explorer=yes,directories=yes,menubar=yes,fullscreen=yes,scrollbars=yes,resizable=yes,status=yes"';
closeWindow();
newWin = window.open(url,'newWin',settings);
newWin.focus();
}

function plainwindow() {
newWin = window.open() 
}




function centeredWindow(url,winname,w,h) {
windowleft = (screen.width - w)/2;
windowtop = (screen.height - h)/2;
settings = '"toolbar=no,directories=no,menubar=no,scrollbars=no,resizable=no,status=no,width='+w+',height='+h+ ',left='+windowleft+',top='+windowtop+'"';
closeWindow();
newWin = window.open(url,winname,settings);
newWin.focus();
}


function centeredscrollingWindow(url,winname,w,h) {
windowleft = (screen.width - w)/2;
windowtop = (screen.height - h)/2;
settings='"toolbar=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,status=no,width='+w+',height='+h+ ',left='+windowleft+',top='+windowtop+'"';
closeWindow();
newWin = window.open(url,winname,settings);
newWin.focus();
}


function closeWindow() {
if (newWin && !newWin.closed) {
newWin.close();}
}


function placedWinTop(url,winname,w,h) {
windowleft = (screen.width-w)/2;
centerver = screen.height/2;
windowtop = centerver - h-20;

settings = '"toolbar=no, directories=no,menubar=no,scrollbars=no,resizable=no,status=no,width='+w+',height='+h+',left='+windowleft+',top='+windowtop+'"';

newWindow1 = window.open(url,winname,settings);
newWindow1.focus();
}


function placedWinBottom(url,winname,w,h) {
windowleft = (screen.width-w)/2;
centerver = screen.height/2;
windowtop = centerver+10;

settings = '"toolbar=no, directories=no,menubar=no,scrollbars=no,resizable=no,status=no,width='+w+',height='+h+',left='+windowleft+',top='+windowtop+'"';

newWindow2 = window.open(url,winname,settings);
newWindow2.focus();
}


function placedWinSide(graphic) {
w = 100;
h = 100;
centerver = screen.height/2;
windowtop = centerver -50;
if (navigator.userAgent.indexOf('MSIE') != -1) {windowleft = screen.width/2 + document.body.clientWidth/2 + 25;}
else {windowleft = (screen.width)/2 + window.outerWidth/2 + 20;}
settings = '"toolbar=no, directories=no,menubar=no,scrollbars=no,resizable=no,status=no,width='+w+',height='+h+',left='+windowleft+',top='+windowtop+'"';



sidewincontent = "<html><head><title>side<\/title><\/head>";
sidewincontent += "<body marginheight=\"0\" marginwidth=\"0\" style=\"margin:0\">";
sidewincontent +="<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";
sidewincontent +="<tr><td width=\"100\">";
sidewincontent += "<a href=\"javascript:opener.close();self.close();\"><img src=\""+graphic+"\"alt=\"close window\" width=\"100\" height=\"100\"border=\"0\"><\/a><\/td>";
sidewincontent += "<\/tr><\/table><\/body><\/html>";

newWindow3 = window.open('','sidewin',settings);
newWindow3.document.write (sidewincontent);
newWindow3.document.close();
newWindow3.focus();
}


/* Start window scrolling function. First initialize the variable vPos to 0.
*/

var vPos=0;

function scrollWindow(h) {
if (window.scroll) {
do {
vPos+=1;
window.scroll(0,vPos);
} while (vPos <= h);
do {
vPos += -1;
window.scroll(0,vPos);
  } while (vPos > 0);
 }
}


function moveWindow(w,h) {
window.moveTo(0,0);
window.blur();
}


function changeParent(url) {
if (opener) {
opener.document.location = url;
}
}

function insertname(text) {
if ((document.cookie.indexOf('username') == -1) || (document.cookie.length <= 0)) {
{
expiry = new Date;
expiry.setDate(expiry.getDate() + 1000);
document.cookie = "username="+text+";expires="+expiry.toGMTString();

textstring = " Welcome, "+text +". Please enjoy your visit.";
}
opener.document.nameform.namefield.value=textstring;
}
}

function welcome() {
if ((document.cookie.indexOf('username') == -1) || (document.cookie.length <= 0)) {
centeredWindow('formwindow.html','formwin',300,100);
}
else {
text = getcookie('username');
textstring = " Welcome back, "+text +".";
document.nameform.namefield.value=textstring;
   }
}


function getcookie(cookiename) {
   var search = cookiename + "="
   if (document.cookie.length > 0) { // are there any cookies?
      cookieindex = document.cookie.indexOf(search)
      if (cookieindex != -1) { // if cookie exists 
         cookieindex += search.length 
         // set index of beginning of value
         end = document.cookie.indexOf(";", cookieindex) 
         // set index of end of cookie value
         if (end == -1) {
            end = document.cookie.length;
          return unescape(document.cookie.substring(cookieindex, end))}
      } 
   }
}

