/* Gets any object in the document */
function getDocObj(itemName) 
{
	if (document.all) return(document.all[itemName]);
	if (document.getElementById) return(document.getElementById(itemName));
	return(null);
}
/* Navigates through images */
function navNextImg(imgObj,where,limit)
{
	imgObj = getDocObj(imgObj);
	var currImg = parseInt(imgObj.src.substring(imgObj.src.lastIndexOf("/") + 1,imgObj.src.indexOf(".jpg")),10);
	//alert(currImg);
	if((currImg < limit && where > 0) || (currImg > 1 && where < 0)) imgObj.src = imgObj.src.replace( pad(currImg,2) + ".jpg",pad(parseInt(currImg,10) + parseInt(where,10),2) + ".jpg" );
}
/* Hides an element */
function flop(id)
{
	if(getDocObj(id)) getDocObj(id).style.display = 'none';
}
/* Pads a number with leading zeroes */
function pad(number,length) 
{
    var str = '' + number;
    while (str.length < length) str = '0' + str;
    return str;
}
/* Opens a new window 
url - The URL of the page to open. Example: "http://scriptasylum.com". 
w - The width of the window in pixels. 
h - The height of the window in pixels (doesn't include menubars). 
tb - Toolbar visible? 1 = yes, 0 = no. 
stb - Status bar visible? 1 = yes, 0 = no. 
L - Linkbar visible? 1 = yes, 0 = no. 
mb - Menubar visible? 1 = yes, 0 = no. 
sb - Scrollbars visible? 1 = yes, 0 = no. 
rs - Resizable window? 1 = yes, 0 = no. 
x - The horizontal position of the window from the left of the screen. 
y - The vertical position of the window from the top of the screen
*/
function openWindow(url,w,h,tb,stb,l,mb,sb,rs,focusthis)
{
var x = (screen.width  - w) / 2;
var y = (screen.height - h) / 2;
var t=(document.layers)? ',screenX='+x+',screenY='+y: ',left='+x+',top='+y;
tb=(tb)?'yes':'no'; stb=(stb)?'yes':'no'; l=(l)?'yes':'no'; mb=(mb)?'yes':'no'; sb=(sb)?'yes':'no'; rs=(rs)?'yes':'no';
var x=window.open(url, 'newWin'+new Date().getTime(), 'scrollbars='+sb+',width='+w+',height='+h+',toolbar='+tb+',status='+stb+',menubar='+mb+',links='+l+',resizable='+rs+t);
if(focusthis) x.focus();
//return x;
}

function setCookie( name, value, expires, path, domain, secure ) 
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}


function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // if cookie exists
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1)
         end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}

function conditionalLoadPopUnder(url, w, h, tb, stb, l, mb, sb, rs){
	if (get_cookie('popunder') == '')
	{
		loadPopUnder(url, w, h, tb, stb, l, mb, sb, rs);
		setCookie("popunder","yes",30);
		// document.cookie="popunder=yes"
	}
}

function loadPopUnder(url, w, h, tb, stb, l, mb, sb, rs){
	win2 = openWindow(url,w,h,tb,stb,l,mb,sb,rs,false); 
	win2.blur()
	window.focus()
}

function isPositiveInteger (s)
   {   var secondArg = false;

       if (isPositiveInteger.arguments.length > 1)
          secondArg = isPositiveInteger.arguments[1];

       // The next line is a bit byzantine.  What it means is:
       // a) s must be a signed integer, AND
       // b) one of the following must be true:
       //    i)  s is empty and we are supposed to return true for
       //        empty strings
       //    ii) this is a positive, not negative, number

       return (isSignedInteger(s, secondArg)
          && ( (isEmpty(s) && secondArg)  || (parseInt (s) > 0) ) );
   }
   
function isSignedInteger (s)

   {   if (isEmpty(s))
      if (isSignedInteger.arguments.length == 1) return false;
      else return (isSignedInteger.arguments[1] == true);

      else {
         var startPos = 0;
         var secondArg = false;

         if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

         // skip leading + or -
         if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
            startPos = 1;
         return (isInteger(s.substring(startPos, s.length), secondArg))
      }
   }
   
    function isInteger (s)
   {
      var i;

      if (isEmpty(s))
      if (isInteger.arguments.length == 1) return 0;
      else return (isInteger.arguments[1] == true);

      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);

         if (!isDigit(c)) return false;
      }

      return true;
   }

   function isEmpty(s)
   {
      return ((s == null) || (s.length == 0))
   }

   function isDigit (c)
   {
      return ((c >= "0") && (c <= "9"))
   }






