function hoverThumb(elem) {
	if (!is.ie6) {
		width = $(elem).getWidth();
		height = $(elem).getHeight();
		$(elem).setStyle({width: width * 2 + 'px', height: height * 2 + 'px', zIndex: 100, border: '2px solid #336699' });
		var parent = $(elem).ancestors()[1];
		parent.setStyle({marginLeft: '-40px', marginTop: '-20px', marginRight: '40px', marginBottom: '20px'});
	} 
}

function unhoverThumb(elem) {
	if (!is.ie6) {
		$(elem).setStyle({width: width -2 + 'px', height: height -2 + 'px', zIndex: 1, border: '1px solid #336699'});
		var parent = $(elem).ancestors()[1];
		parent.setStyle({marginLeft: '0px', marginTop: '0px', marginRight: '0px', marginBottom: '0px'});
	}
}

function toggleMenu(id, show)
{
    el = document.getElementById(id);
    if(show){
        el.style.display="block";
    }else{
        el.style.display="none";
    }
}
function reloadPageLang(language)
{
    //get current url, force it to be a string...
    var url = window.location.toString();
    //strip out any old lang query vars as well as adding the ? if necessary
    url = url.replace(/[\?\&]lang=\w+/,'');
    if (!url.match(/\?/)) {
        url += '?' ;
    }
    //add new lang, and take care of any anchors/url fragments as we go along...
    if (url.match(/#.*$/)) {
        window.location =  url.replace(/(#.*)$/,'&lang='+language+"$1" );
    } else {
        window.location = url + '&lang='+language;
    }
}

function hookEvent(element, eventName, callback)
{
    if(typeof(element) == "string")
        element = document.getElementById(element);
    if(element == null)
        return;
    if(element.addEventListener)
        element.addEventListener(eventName, callback, false);
    else if(element.attachEvent)
        element.attachEvent("on" + eventName, callback);
}
function unhookEvent(element, eventName, callback)
{
    if(typeof(element) == "string")
        element = document.getElementById(element);
    if(element == null)
        return;
    if(element.removeEventListener)
        element.removeEventListener(eventName, callback, false);
    else if(element.detachEvent)
        element.detachEvent("on" + eventName, callback);
}

function Sniffer(){
	this.agt= navigator.userAgent.toLowerCase();
	this.appVer = navigator.appVersion.toLowerCase();
	this.appName	= navigator.appName.toLowerCase();
	this.minor = parseFloat(this.appVer);
	this.major = parseInt(this.minor);

	this.mac = (this.agt.indexOf("mac")!=-1);
	this.ie = this.appVer.indexOf('msie');
	if (this.ie != -1) {
		if(this.mac)
			this.minor = parseFloat(this.agt.substring(this.ie+5,this.agt.indexOf(';',this.ie)));
		else
			this.minor = parseFloat(this.appVer.substring(this.ie+5,this.appVer.indexOf(';',this.ie)));
		this.major = parseInt(this.minor);
	}else{
		this.ie = false;
	}
	this.ie3 = (this.ie && (this.major < 4));
	this.ie4 = (this.ie && (this.major == 4));
	this.ie4up = (this.ie && this.major >= 4);
	this.ie5 = (this.ie && (this.major == 5));
	this.ie5up = (this.ie && (this.major >= 5));
	this.ie6 = (this.ie && (this.major == 6));
	this.ie6up = (this.ie && this.minor >= 6);
	this.ie7 = (this.ie && (this.major == 7));
	this.ie7up = (this.ie && this.minor >= 7);

	this.mozilla =  (!this.ie && (this.agt.indexOf('mozilla')!=-1));

	this.firefox = (this.agt.indexOf('firefox')!=-1)

	this.nav  = ((this.agt.indexOf('mozilla')!=-1) && (this.agt.indexOf('spoofer')==-1) && (this.agt.indexOf('compatible') == -1) && (this.agt.indexOf('opera')==-1) && (this.agt.indexOf('webtv')==-1) && (this.agt.indexOf('hotjava')==-1));
	this.nav4  = (this.nav && (this.major == 4));
	this.nav4up = (this.nav && this.minor >= 4);
	this.nav5up = (this.nav && this.minor >= 5);

	this.opera = (this.agt.indexOf("opera") != -1);
	this.op7up = (this.opera && this.minor >= 7);

	this.safari = ( this.mac && (this.agt.indexOf('safari')!=-1));

	this.gecko = (this.agt.indexOf('gecko') != -1);
	this.hotjava = (this.agt.indexOf("hotjava") != -1);
	this.webtv = (this.agt.indexOf("webtv") != -1);
	this.aol = (this.agt.indexOf("aol") != -1);

	this.pocketPC = (this.appName == "microsoft pocket internet explorer");
}
var is = new Sniffer();


function setBrowserInfo(){
	makeHttpRequest('./php/browser_info.php' ,'browserInfoReturn',false);
}
function browserInfoReturn(txt)
{
	//alert(txt);
	setCookie("browser_info",txt, 100);
}
function getBrowserInfo()
{
    var ck = getCookie("browser_info");
    if(!ck) return false;        
    var obj = eval('(' + ck + ')');
    if(obj.javascript)
        return true;
    alert(" browser:" + obj.browser + "\n version:" + obj.version + "\n platform:" + obj.platform + "\n iframes:" + obj.iframes + "\n Javascript:" + obj.javascript);
}
function setCookie(c_name,value,expiredays)
{
	var exdate = new Date()
	exdate.setDate(exdate.getDate()+expiredays)
	document.cookie = c_name+ "=" +escape(value)+
	((expiredays == null) ? "" : ";expires=" + exdate.toGMTString())
}
function getCookie(c_name)
{   
    if (document.cookie.length > 0){
        c_start = document.cookie.indexOf(c_name + "=")
        if (c_start!=-1){
            c_start=c_start + c_name.length+1
            c_end=document.cookie.indexOf(";",c_start)
            if(c_end==-1) 
                c_end=document.cookie.length;
            //alert(document.cookie.substring(c_start,c_end));
            return unescape(document.cookie.substring(c_start,c_end))
        }
    }
    return "";
}

function swapBgImage(id, img){
	var v = getElementRef(id);
	v.style.backgroundImage="url('"+img+"')";
}
function getMouseXY(e) {
	if (is.ie) {
		if (document.documentElement && document.documentElement.scrollTop)
			theTop = document.documentElement.scrollTop;
		else if (document.body)
			theTop = document.body.scrollTop
		xmouse = event.clientX + document.body.scrollLeft;
		ymouse = event.clientY + theTop;
	} else {
		xmouse = e.pageX
		ymouse = e.pageY
	}
	if (xmouse < 0){ xmouse = 0}
	if (ymouse < 0){ ymouse = 0}
}

function placeDiv(id, x, y){
	var oxo = getElementRef(id);
	oxo.style.left= x + "px";
	oxo.style.top = y + "px";
}
// element object
function getElementRef(id){

	if(typeof id == 'object')
		return id;
	var e;
	if (document.getElementById)
		e = document.getElementById(id);
	else if (document.all)
		e = document.all[id];
	else if (document.layers)
		e = document.layers[id];
	return e;
}
// Get client area width.
function getClientWidth(){
  var w = 0;
  if (self.innerWidth) {
    w = self.innerWidth;
		if (document.height > self.innerWidth) // has vert scrollbar
			w -= 16;
	}else if (is.ie6up) {
		w = document.documentElement.clientWidth;
	}else{
		w = document.body.clientWidth;
  }
  return w;
}
// Get client area height.
function getClientHeight(){
	var h = 0;
	if (self.innerHeight){
		h = self.innerHeight;
		if (document.width > self.innerHeight) // has horz scrollbar
			h -= 16;
	}else if (is.ie6up) {
		h = document.documentElement.clientHeight;
	}else{
		h = document.body.clientHeight;
	}
  return h;
}

function getElementLeft(el)
{
	var elem = getElementRef(el);

	xPos = elem.offsetLeft;
	tempEl = elem.offsetParent;
	while (tempEl != null) {
		xPos += tempEl.offsetLeft;
		tempEl = tempEl.offsetParent;
	}
	return xPos;
}
function getElementTop(el) {
	var elem = getElementRef(el);
	yPos = elem.offsetTop;
	tempEl = elem.offsetParent;
	while (tempEl != null) {
		yPos += tempEl.offsetTop;
		tempEl = tempEl.offsetParent;
	}
	return yPos;
}
function getElementHeight(el) {

	var elem = getElementRef(el);
	if (is.opera) {
		h = elem.style.pixelHeight;
	} else {
		h = elem.offsetHeight;
	}
	return h;
}
function getElementWidth(el)
{
	var elem = getElementRef(el);
	if (is.opera) {
		w = elem.style.pixelWidth;
	} else {
		w = elem.offsetWidth;
	}
	return w;
}
var show = false;
function displayProdText(id,But, moreText, lessText){
	var oxo = getElementRef(id);
	var btn = getElementRef(But);
	if(show == false){
		oxo.style.display = 'block';
		oxo.style.borderTop = '1px solid #DFDFDF';
		var cl = '<a href="javascript:void(0)" class="blue_link" onclick="displayProdText(\'more\' , \'moreBtn\', \''+moreText+'\', \''+lessText+'\' ) ">'+lessText+'</a>';
		btn.innerHTML = cl;
		show = true;
	}else{
		oxo.style.display = 'none';
		oxo.style.border = '';
		var cl = '<a href="javascript:void(0)" class="blue_link" onclick="displayProdText(\'more\' , \'moreBtn\', \''+moreText+'\', \''+lessText+'\') ">'+moreText+'</a>';
		btn.innerHTML = cl;
		show = false;
	}
}
function displayDiv_Btn(id, but, open ,say){
var oxo = getElementRef(id);
var btn = getElementRef(but);
	if(show == false){
		oxo.style.display = 'block';
		oxo.style.borderTop = '1px solid #DFDFDF';
		var cl = '<a href="javascript:void(0)" class="blue_link" onclick="displayDiv_Btn(\''+id+'\' , \' '+btn+'\') ">'+ say +'</a>';
		btn.innerHTML = cl;
		show = true;
	}else{
		oxo.style.display = 'none';
		oxo.style.border = '';
		var cl = '<a href="javascript:void(0)" class="blue_link" onclick="displayDiv_Btn(\''+id+'\' , \' '+btn+'\') ">'+ say +'</a>';
		btn.innerHTML = cl;
		show = false;
	}
}

function displayDiv(id, luz){
	var oxo = getElementRef(id);
	if(luz){
        if(oxo) {
		    oxo.style.display = 'block';
        }
	}else{
        if(oxo) {
		    oxo.style.display = 'none';
        }
	}
}
function toggleDiv(id, cb){
	var v = getElementRef(id);
	if(document.form[cb].checked == true){
		v.style.display = 'block';
	}else{
		v.style.display = 'none';
		document.form.topFlap.checked = document.form.inOut.checked = false;
	}
}
function popUp(URL,pw,ph) {
	day = new Date();
	id = day.getTime();
	var scX = document.all ? window.screenLeft : window.screenX;
	var scY = document.all ? window.screenTop : window.screenY;
	var w = getClientWidth()/2;
	var h = getClientHeight()/2;
	var clientW = scX + w - (pw/2);
	var clientH = scY + h - (ph/2)+50;
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+pw+",height="+ph+",left=" +clientW+",top="+clientH+"');");
}

window.defaultStatus = "Welcome to Overnight Prints";

//// talk to flash
var movieName = null;

function thisMovie(movieName){
  if (window.document[movieName]) {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1){
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName];
  }else{
    return document.getElementById(movieName);
  }
}
function isLoaded (theMovie) {
  if (typeof(theMovie) != "undefined" && theMovie != null) {
    return theMovie.PercentLoaded() == 100;
  } else {
    return false;
  }
}
function toggleVar(varName, varStr1 , varStr2) {
	if (isLoaded(thisMovie(movieName))) {
		if(document.form[varName].checked == true){
			varStr = varStr2;
		}else {
			varStr = varStr1;
		}
		setVar(varName, varStr)
	}
}

function setVar(varName, varStr){
	if (isLoaded(thisMovie(movieName))) {
		thisMovie(movieName).SetVariable(varName, varStr);
	}
}

function go(theFrame) {
  if (isLoaded(thisMovie(movieName))) {
    thisMovie(movieName).GotoFrame(theFrame);
  }
}
function CreateBookmark() {
    //    var title = "Overnight Prints";
    var title     = (typeof(document.title)!='undefined'?document.title:'Overnight Prints');
    var invoiceBk = getElementRef('bookmarkInvoice');
    var url       = this.location + '';
	if (invoiceBk && invoiceBk.value.length > 0) {
		url  = url.match( /.*\// );
		url += 'main.php?A=myonp_order_details&orderId=' + invoiceBk.value;
	}
    
	if (window.sidebar) {                           // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) {                  // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) {         // Opera Hotlist
		return true;
	}
}

function updateContrast(val){
	var front = getElementRef('front');
	front.innerHTML= '<br/><br/><br/><span class="txt_02">Please Wait . . .</span><span class="tx_sm_grey_04"> Image Rendering</span>';
	var curval = document.form['threshold'].value;

	if(val == "up"){
		newval = parseInt(curval) + 1000;
	}else if(val == "down"){
		newval = parseInt(curval) - 1000;
	}else if(val == "invert"){
		newval = parseInt(curval) ;
	} else {
		newval = val;
		var last = getElementRef('dot'+curval);
		last.innerHTML = "";
		var dot = getElementRef('dot'+ val);
		dot.innerHTML = '<div style="border:1px solid #FF6600; width:8px; height:12px; background-color:#AABBCC"></div>';
	}
	var invert = document.form['invert'].checked;
	document.form['threshold'].value  = newval;
	makeHttpRequest('./php/adjustImage.php?threshold=' + newval +'&invert=' + invert ,'changeContrast', false);
}
function changeContrast(txt){
	getElementRef('front').innerHTML= txt;
}
//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
    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;
    }

    // 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;
    }


    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
    return arrayPageSize;
}
