//Variable used in autoExpand to limit button clicks
var autoExpandCheck = false;
//Variable to keep track of which JS sources have been added
var sourcesAdded=""; //list of sources already added

 function poptoggle (postid) {
var whichpost = document.getElementById(postid);
if (whichpost.className=="expandblock") {
whichpost.className="collapseblock";
}
else {
whichpost.className="expandblock";
}
}

function poptoggle2 (postid,postid2) {
var whichpost = document.getElementById(postid);
if (whichpost.className=="expandblock") {
whichpost.className="collapseblock";
}
else {
whichpost.className="expandblock";
}
var whichpost2 = document.getElementById(postid2);
if (whichpost2.className=="collapseblock") {
whichpost2.className="expandblock";
}
else {
whichpost2.className="collapseblock";
}
}

function pop (postid) {
var whichpost = document.getElementById(postid);
if (whichpost.className=="collapseblock") {
whichpost.className="expandblock";
}
}

function jahpop(url,target,postid) {
var whichpost = document.getElementById(postid);
if (whichpost.className=="expandblock") {
whichpost.className="collapseblock";
}
else {
whichpost.className="expandblock";
    // native XMLHttpRequest object
    //  document.getElementById(target).innerHTML = '<div align=center><BR><BR><img src="/images/Ajax.gif" width=32 height=32><BR><BR><BR><BR></div>';
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = function() {jahDone(target);};
        req.open("GET", url, true);
        req.send(null);
    // IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = function() {jahDone(target);};
            req.open("GET", url, true);
            req.send();
        }
    }

}
}    


function jah(url,target,loading) {
    // native XMLHttpRequest object
    document.getElementById(target).innerHTML = loading;
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = function() {jahDone(target);};
        req.open("GET", url, true);
        req.send(null);
    // IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = function() {jahDone(target);};
            req.open("GET", url, true);
            req.send();
        }
    }
}  



function jahfav(url,target) {
    // native XMLHttpRequest object
    document.getElementById(target).innerHTML = '<img id="imagebackground3" border=0 align=right hspace=0 width=15 height=15 style="margin-left:10px; margin-bottom:5px; margin-right:3px;" src="/images/Favorite-InLine.gif">';
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = function() {jahDone(target);};
        req.open("GET", url, true);
        req.send(null);
    // IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = function() {jahDone(target);};
            req.open("GET", url, true);
            req.send();
        }
    }
}  

function jahDone(target) {
    // only if req is "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            results = req.responseText;
            document.getElementById(target).innerHTML = results;
        } else {
            document.getElementById(target).innerHTML="jah error:\n" +
                req.statusText;
        }
    }
}


function jahnl(url,target) {
    // native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = function() {jahDone(target);};
        req.open("GET", url, true);
        req.send(null);
    // IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = function() {jahDone(target);};
            req.open("GET", url, true);
            req.send();
        }
    }
}  

function jahnlpost(url,params,target) {
    // native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = function() {jahDone(target);};
        req.open("POST", url, true);
		//Send the proper header information along with the request
		req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		req.setRequestHeader("Content-length", params.length);
		req.setRequestHeader("Connection", "close");
        req.send(params);
    // IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = function() {jahDone(target);};
            req.open("GET", url, true);
            req.send();
        }
    }
} 

function select_all_2()
{
var text_val=eval("document.form2.type");
text_val.focus();
text_val.select();
}

//used for AutoExpand
//id: the id of the div container containing the <a> link to click
function autoExpand(id){
	var moregallery = document.getElementById(id);
	
	if(moregallery && !autoExpandCheck){
		var position = findPos(moregallery)[1] - 100;
		var location;
		var showmore = document.getElementById('moregallery2').getElementsByTagName('a');
		if(showmore.length == 1){
			var showmoreButton = showmore[0];
		}
		
		if (navigator.appName == "Microsoft Internet Explorer"){
			location = document.documentElement.scrollTop;
		}else{
			location = window.pageYOffset;
		}
		location = location + pageHeight();
		
		if(location > position){
			if(showmoreButton)showmoreButton.onclick();
			autoExpandCheck = true;
		}
	}
}

//Checking if Files have been Added
function checkLoadJS(source){
	if (sourcesAdded.indexOf("["+source+"]")==-1){
		loadJS(source);
		sourcesAdded+="["+source+"]" //List of files added in the form "[filename1],[filename2],etc"
	}
}

//Dynamically load JS Source
function loadJS(source){
	var fileref=document.createElement('script');
	fileref.setAttribute("type","text/javascript");
	fileref.setAttribute("src", source);
	document.getElementsByTagName("head")[0].appendChild(fileref);
}

//Find the pixel position of the DOM object
//returns array with index 0: Distance from Left, index 1: Distance from Top
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

//Find the page width of the viewable area in the browser
function pageWidth(){
	return window.innerWidth != null? window.innerWidth: document.body != null? document.documentElement.clientWidth:null;
}

//Find the page Height of the viewable area in the browser
function pageHeight(){
	return window.innerHeight != null? window.innerHeight: document.body != null? document.documentElement.clientHeight:null;
} 