function toggle(div_id) {
	var el = document.getElementById(div_id);
	if ( el.style.display == 'none' ) {	el.style.display = 'block';}
	else {el.style.display = 'none';}
}
function blanket_size(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv_height=blanket_height/2 - 450;
	//popUpDiv.style.top = popUpDiv_height + 'px';  //commented to have short window heights not push the exit link off the top
}

function window_pos(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);
	window_width=window_width/2-450;
	popUpDiv.style.left = window_width + 'px';
}
function popup(windowname) {
	blanket_size(windowname);
	window_pos(windowname);
	toggle('blanket');
	toggle(windowname);		
}

//setup ajax support.  callback is any function to be called once request is complete.  
function useAjax(url, callback) {

    var req = init();
  
        
    function init() {
		var crossxhr = false;
		if(window.XMLHttpRequest) {
			crossxhr = new XMLHttpRequest();
		 } else if(window.ActiveXObject) {
			try {
				crossxhr = new ActiveXObject('Msxml2.XMLHTTP');
			} catch(e) {
				try {
					crossxhr = new ActiveXObject('Microsoft.XMLHTTP');
				} catch(e) {
					crossxhr = false;
				}
			}
		}
			return crossxhr;
	}
	
	req.onreadystatechange = processRequest;
    
    function processRequest () {
      if (req.readyState == 4) {
        if (req.status == 200) {
          if (callback) callback(req.responseText);
        }
      }
    }

    this.doGet = function() {
      req.open("GET", url, true);
      req.send(null);
    }
    
    this.doPost = function(body) {
      req.open("POST", url, true);
      req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      req.send(body);
    }
}


function openimgview(popname, mainpic, refid, ps) {
	var ca="./imgview.php";
	dp = new useAjax(ca, showimgview);
	var bodye= "refid=" + Number(refid);
	bodye = bodye + "&mainpic=" + Number(mainpic);
	bodye = bodye + "&ps=" + Number(ps);
	dp.doPost(bodye);
}

function showimgview(adb) {
	document.getElementById('slideview').innerHTML=adb;
	popup('imgview');
}
function changeslidemain(picid, ps) {
	document.getElementById('imgviewmainpic').src="loadpic.php?id=" + picid + "&fullsize=1&ps=" + ps;
}


function pageps(pagenum) {
	var ca="./photostream.php";
	dp = new useAjax(ca, updatephotostream);
	var bodye= "pagenum=" + Number(pagenum);
	dp.doPost(bodye);
	function updatephotostream(adb) {
		document.getElementById('psbox').innerHTML=adb;
	}
}

