// v6.01
// 18 nov 2010
// script by 1boy at 1uffakind.com

// build links like this: javascript:pop('urlorpath','windowname',w,h,'controls','scroll','statusbar')
// popwin = function ( myurl, myname, myw, myh, mycontrols, myscroll, mystatus ) {
popwin = function ( myurl, myname, myw, myh, mycontrols, myscroll, mystatus ) {
// set following master properties for all opens from this page or script
   var popurl = "#";
   var popname = "uffapop";
   var popwidth = "screen";
   var popheight = "screen";
   var popresize = "yes";
   var popmenu = "yes";
   var pophistory = "no";
   var popdirectories = "no";
   var popcontrols = "no";
   var popscroll = "yes";
   var popstatus = "no";

// some defs
   /*
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	var pageWidth, pageHeight;
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	*/
   var pageWidth = screen.availWidth;
   var pageHeight = screen.availHeight;
   
	// args
   if ( myurl != null ) {
	   popurl = myurl;
   }
   if ( myname != null ) {
	   popname = myname;
   }
   
   if ( myw != null && myw != "screen" ) {
	   popwidth = Math.floor(myw);
   }
   if ( popwidth == "screen" ) {
	   popwidth = pageWidth-200;
   } else {
	   if ( popwidth > pageWidth ) {
		   popwidth = pageWidth;
	   }   
   }
   
   if ( myh != null && myh != "screen"  ) {
	   popheight = Math.floor(myh);
   }
   if ( popheight == "screen" ) {
	   popheight = pageHeight-200;
   } else {
	   if ( popheight > pageHeight ) {
		   popheight = pageHeight;
	   }
   }
   
   if ( mycontrols != null ) {
	   popcontrols = mycontrols;
   }
   if ( myscroll != null ) {
	   popscroll = myscroll;
   }
   if ( mystatus != null ) {
	   popstatus = mystatus;
   }
   
   var left = Math.round((pageWidth-popwidth)/2);
   var top = Math.round((pageHeight-popheight)/2);
   
   var specs = "";
   specs += 'width=' + popwidth + ',height=' + popheight + ',';
   specs += 'top='+top+',left='+left+',';
   specs += 'scrollbars=' + popscroll + ',resizable=' + popresize + ',toolbar=' + popcontrols + ',';
   specs += 'location=' + popcontrols + ',personalbar=' + popcontrols +  ',';
   specs += 'locationbar=' + popcontrols + ',statusbar=' + popstatus + ',status=' + popstatus + ',';
   specs += 'history=' + pophistory + ',directories=' + popdirectories  + ',menubar=' + popmenu + '';
   
   // alert(pageWidth+","+pageHeight+","+popwidth+","+popheight);
   
   var poppedwin = window.open( popurl, popname, specs );
   if ( window.focus ) { poppedwin.focus(); }
   /* return false; */		
}

popflash = function ( myurl, myname, myw, myh, mycontrols, myscroll, mystatus ) {
    popwin( myurl, myname, myw, myh, mycontrols, myscroll, mystatus );
    return;
}

