//JavaScript Core Library
//Copyright  2002-2005 Machineware, LLC
//Internet Explorer Edition

var httpR = new Object;

function getReqData(oname){
	try{
		return(httpR[oname].responseText);
	} catch(e){
	
	}
}

function httpStatus(oname){
	return(httpR[oname].readyState);
}


function runResponse(oname){
	try{
		eval(httpR[oname].responseText);
	} catch(e){
	
	}
}

function httpPostRequest(oname,url,cb,params){
	httpR[oname] = new ActiveXObject("Microsoft.XMLHTTP");
	if(cb){
		httpR[oname].onreadystatechange = cb;
	}
	url = url + '&isxml=1';
	httpR[oname].open("POST", url, true);
	httpR[oname].setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	var postp;
	for(var x=0;x<params.length;x++){
		postp = postp + '&' + params[x].name   + '=' + params[x].data;
	}
	httpR[oname].send(postp);
}


function httpRequest(oname,url,cb){
	try{
		httpR[oname] = new ActiveXObject("Microsoft.XMLHTTP");
		if(cb){
			httpR[oname].onreadystatechange = cb;
		}
		url = url + '&isxml=1';
		httpR[oname].open("GET", url, true);
		httpR[oname].send();
	} catch(e){
		z = getObjByName('iframe');
		setFrameSrc(z,url);
	}
}


self.onerror = function(a,b,c) {
	alert('Caught Error ' + a + ' in ' + b + ' on line ' + c);
	return true;
}

function panPix(tpix){
	tg = getObjByName(tpix);
	pixh = tg.children[0].height;
	pMax = pixh - 128;
	if(panDown){
		if(pOff < pMax){
			setObjTop(tg,'-'+pOff);
			pOff = pOff + pInc;
		} else {
			panDown = false;
		}
	} else {
		if(pOff > pMin){
			pOff = pOff - pInc;
			setObjTop(tg,'-'+pOff);
		} else {
			panDown = true;
		}
	}
	setTimeout('panPix("'+tpix+'");',50);
}

//--Right clicks


function registerContextMenu(){
	document.body.oncontextmenu = rightClickMenu;
	document.body.onmouseup = hideRightClick;
}

function showRightClick(evtO,mtype){
	lastRMenu = mtype;
	z = getObjByName('rClick_'+mtype);
	setObjTopLeft(z,getEventStartY(evtO)+getDocScroll(),getEventStartX(evtO));
}

//---end right click


function getCSSProperty(thesel,theprop){
	for(sheet=document.styleSheets.length - 1;sheet>=0;sheet--){
		targetID = selectorInSheet(thesel,sheet);
		if(targetID >= 0){
			return(document.styleSheets[sheet].rules.item(targetID).style.getAttribute(theprop));
		}
	}
}


function setCSSProperty(thesel,theprop,theval){
	for(sheet=0;sheet<document.styleSheets.length;sheet++){
		targetID = selectorInSheet(thesel,sheet);
		if(targetID >= 0){
			document.styleSheets[sheet].rules.item(targetID).style.setAttribute(theprop,getCSSValue(theprop,theval));
		}
	}
}

function getCSSValue(theprop,theval){
	if(theval == ''){
		switch(theprop){
			case 'backgroundColor':
				return('transparent');	
			case 'backgroundImage':
				return('none');	
			case 'color':
				return('black');	
			case 'font-weight':
				return('normal');	
			default:
				return(theval);	
		}
	} else {
		return(theval);
	}
}

function checkCSSRefresh(thesel){
}

function doCSSPreview(thesel,therule){
	addCSSRule(thesel,therule);
}

function addCSSRule(thesel,therule){
	for(sheet=0;sheet<document.styleSheets.length;sheet++){
		if(selectorInSheet(thesel,sheet) >= 0){
			document.styleSheets[sheet].addRule(thesel,therule);
		}
	}
}

function selectorInSheet(thesel,sheet){
	selCount = document.styleSheets[sheet].rules.length -1;
	for(x=selCount;x>=0;x--){
		if(document.styleSheets[sheet].rules.item(x).selectorText == thesel){
			return(x);
			break;
		}
	}
	return(-1);
}

var hsel='';
var seld=null;
var seldb=null;

function flashSel(thesel,cdc){
	if(hsel != ''){
		if(thesel != hsel){
			return(0);
		}
	} else {
		hsel = thesel;
	}
	if(cdc == -1){
		cdc = 7;
		seld=getCSSProperty(thesel,'color');
	}
	if(cdc > 0 ){
		nudc = cdc-1;
		if(nudc % 2){
			setCSSProperty(thesel,'color','#FFFFFF');
		} else {
			setCSSProperty(thesel,'color','#000000');
		}
		setTimeout('flashSel("'+thesel+'",'+nudc+');',150);
	} else { //restore value
		setCSSProperty(thesel,'color',seld);
		seld=null;
		hsel='';
	}
}

function flashSelB(thesel,cdc){
	if(hsel != ''){
		if(thesel != hsel){
			return(0);
		}
	} else {
		hsel = thesel;
	}
	if(cdc == -1){
		cdc = 7;
		seld=getCSSProperty(thesel,'backgroundColor');
		seldb=getCSSProperty(thesel,'backgroundImage');
		if(seldb != null){
			setCSSProperty(thesel,'backgroundImage','');
		}
	}
	if(cdc > 0 ){
		nudc = cdc-1;
		if(nudc % 2){
			setCSSProperty(thesel,'backgroundColor','#FFFFFF');
		} else {
			setCSSProperty(thesel,'backgroundColor','#000000');
		}
		setTimeout('flashSelB("'+thesel+'",'+nudc+');',150);
	} else { //restore value
		setCSSProperty(thesel,'backgroundColor',seld);
		setCSSProperty(thesel,'backgroundImage',seldb);
		seld=null;
		seldb=null;
		hsel='';
	}
}


function killEvent(evtO){
	window.event.returnValue=false;
}

function buttonIsDown(evtO){
	return(window.event.button ==1);
}

function listenForEvent(obj,theEvt,handler){
	tmp = obj + '.'+ theEvt + '=' + handler;
	eval(tmp);
}

function getEventObject(evtO){
	return(window.event);
}

function getEventTarget(evtO){
	return(window.event.srcElement);
}

function getEventStartX(evtO){
	return(window.event.clientX);
}

function getEventStartY(evtO){
	return(window.event.clientY);
}

function getEventKey(evtO){
	return window.event.keyCode;
}

function stopEventBubble(evtO){
	window.event.cancelBubble=true;
}

function shiftKeyDown(evtO){
	return window.event.shiftKey;
}

function getCookie(c){
	ac=document.cookie;
	st=ac.indexOf(c+'=');
	if(st==-1){
		return '';
	}
	st+= c.length+1;
	en=ac.indexOf(';',st);
	if(en==-1){
		en=ac.length;
	}
	return(ac.substring(st,en));
}

function getScreenWidth(){
	return document.body.clientWidth;
}

function getScreenHeight(){
	return document.body.clientHeight;
}

function setCookie(n,v){
	document.cookie = n+'='+escape(v)+';path=/';
}

function focusTB(x){
	z=getObjByName(x);
	z.focus();
	z.select();
}

function setDivWidth(x,y){
	x.style.width=y;
}

function setDivHeight(x,y){
	x.style.height=y;
}

function getObjWidth(x){
	return x.style.width;
}

function getObjHeight(x){
	return x.style.height;
}

function setObjTopLeft(x,y,z){
	setObjTop(x,y);
	setObjLeft(x,z);
}

function setObjTop(x,y){
	x.style.pixelTop=y;
}

function setObjLeft(x,y){
	x.style.pixelLeft=y;
}

function getObjTop(x){
	return x.style.pixelTop;
}

function getObjLeft(x){
	return x.style.pixelLeft;
}

function getObjByName(x){
	z = document.getElementById(x);
	return(z);
}

function setFrameSrc(x,y){
	x.src=y;
}

function getFrameObjByName(x,y){
	z = eval(x+'.'+y);
	return(z);
}

function getFrameBody(targ){
	return(frames[targ].document);
}

function getParentObj(x){
	return x.parentElement;
}

function getChildren(x){
	return x.children;
}

function getChildObj(x,y){
	return x.children[y];
}

function getObjName(x){
	return x.id;
}

function setObjBgColor(x,y){
	x.style.backgroundColor = y;
}

function getObjBgColor(x){
	return x.style.backgroundColor;
}

function gotoLocation(x){
	document.location = x;
}

function setObjScrollTop(x,y){
	x.scrollTop = y;
}

function getDocScroll(){
	if(document.documentElement.scrollTop){
		return parseInt(document.documentElement.scrollTop);
	} else {
		return parseInt(document.body.scrollTop);
	}
}

//x is object ; y is attribute name
function getObjAttribute(x,y){
	return(x.getAttribute(y));
}

function setObjAttribute(x,y,z){
	x.setAttribute(y,z);
}

function setObjHTML(x,y){
	x.innerHTML=y;
}

function setObjClass(x,y){
	x.className=y;
}

function getObjClass(x){
	return x.className;
}

function setObjText(x,y){
	x.innerText=y;
}

function getObjHTML(x){
	return x.innerHTML;
}

function setObjFilter(x,y){
	x.style.filter = y;
}

function applyFilter(x){
	x.filters.revealTrans.apply();
}

function playFilter(x){
	x.filters.revealTrans.play();
}

function setImgSrc(x,y){
	x.src = y;
}

function getImgSrc(x){
	return x.src;
}

function setImgAltText(x,y){
	x.alt = y;
}

//kill the event
function ke(){
	event.returnValue=false;
}

//x is an object
function hideObj(x){
	x.style.visibility = 'hidden';
}

//x is an object
function showObj(x){
	x.style.visibility = 'visible';
}

function zapObj(x){
	x.style.display = 'none';
}
function addObj(x){
	x.style.display = 'inline';
}

function clr(x){
	if (x.value=='Search photos'){
		x.value = '';
	} 
}


function sc(x){
	if(cc >= x || sper < cc){
		document.location = 'listphotos.php?cat='+cat+'&zs='+x;
	}
}

function cv(x){
	document.location = 'listphotos.php?cat='+cat+'&zr='+x;
}

function offX(z) { 
	return (z.x) ? z.x : getOffsetLeft(z);
}

function offY(z) {
	return (z.y) ? z.y : getOffsetTop(z);
}

function getOffsetLeft(z){
	iPos = 0;
	while (z != null) {
		iPos += z.offsetLeft;
		z = z.offsetParent;
	}
	return iPos;
}

function getOffsetTop(z){
	iPos = 0;
	while (z != null) {
		iPos += z.offsetTop;
		z = z.offsetParent;
	}
	return iPos;
}

function absPos(z,which) {
	iPos = 0;
	while (z != null) {
		iPos += z["offset" + which];
		z = z.offsetParent;
	}
	return iPos;
}
