
var myWind;
var content_key = "";

var log = function(message) {
	  if (window.console) {
	     if (window.console.debug != undefined) window.console.debug(message);
	     else if (window.console.log != undefined) window.console.log(message);
	  } else {
	     //alert(message);
	  }
	};
	
function confirmCancel()
{
	return confirm("Are you sure you want to cancel?");
}

function setIfExists(id,src) {
	var img = new Image();
	img.onload = function () {
		document.images[id].src = src;
	};
	img.onerror = function () {
		// do something if images doesn't exist.
		document.images[id].width=0;
		document.images[id].height=0;
	}
	img.src = src;
}

function getMagCoverThumb(issueId, secure)
{
	return getImagePath(issueId, 1, 0, secure);
}

function getImagePath(issueId, pageNum, scrnSize, numUp, secure)
{
	if (pageNum == 0)
		return '/images/igif.gif';

	if (scrnSize != 0 && numUp==undefined)
		numUp = 2;
	
	if (secure == undefined || secure == false)
		basePath = "http";
	else
		basePath = "https";
	
	basePath += "://smedia.csleuth.com/images/mag/";
	
	switch (scrnSize) {
		case 0:		basePath = basePath + "public/"+issueId+"/resized/thumbs/"; break;
		case 1024: 	basePath = basePath + "private/"+issueId+"/resized/"+numUp+"x1024x768/"; break;
		case 1280:	basePath = basePath + "private/"+issueId+"/resized/"+numUp+"x1280x1024/"; break;
		case 800:
		default:	basePath = basePath + "private/"+issueId+"/resized/"+numUp+"x800x600/";
	}

	if (pageNum != undefined) {
		if (scrnSize == 0)
			basePath += (issueId + "-" +pageNum + ".jpg");
		else {
			basePath += (issueId + "-" +pageNum + ".jpg?"+content_key);
			log(basePath);
		}
	}
	
	return basePath;
}


function saveUserCookies(form) {
	var u = xGetElementById("loginUsername");
	if (u === null) {
		return true;
	}
	expDate = new Date();
	FixCookieDate(expDate);
	expDate.setFullYear(expDate.getFullYear() + 1);
	SetCookie("Username", form.loginUsername.value, expDate);
	return true;
}

function deleteCookie(){
	DeleteCookie("Username", "/");
	DeleteCookie("PW", "/");
}

function infoWindow(theURL, w, h) {
    var width = 300;
    var height = 200;
    if (w !== null) {
        width = w;
    }
    if (h !== null) {
        height = h;
    }
    var screenx = screen.width / 2 - width / 2;
    var screeny = screen.height / 2 - height / 2;
    var optionstring = "alwaysRaised=1, screenX=" + screenx + ", screenY=" + screeny + ", toolbar=0, menubar=0, resizeable=1, titlebar=0, dependent=1, width=" + width + ", height=" + height + ", scrollbars=1, location=0";
    if (!myWind || myWind.closed) {
        myWind = window.open(theURL, "_blank", optionstring);
    } else {
        myWind.focus();
    }
    
    return myWind;
}

function openFloatingWin(url)
{
	w = screen.width;
	h = screen.height;
	t = 0;
	lft = 0;
	window.open(url,"_blank","toolbar=no, location=no, alwaysRaised=true, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width="+w+", height="+h+", top="+t+", left="+lft);
} 
