//scripts.js


function dolayer(){
	if ( document.getElementById('attachfile').value == '' ){
		var img = document.getElementById('imgdiv');
		img.innerHTML = '<BR><BR><BR>No Image Selected.';
	}
	else	{
		var filename = document.getElementById('attachfile').value;
		var fileextension = filename.substring(filename.length - 3);
		//alert(fileextension);
		if ( fileextension == 'JPG' || fileextension == 'jpg' || fileextension == 'GIF' || fileextension == 'gif')	{
			//load the image to test size
			var layerText = '<img name=imageH src="file:\/\/\/'+document.getElementById('attachfile').value +'" >';
			var imghidden = document.getElementById('imghidden');
			imghidden.innerHTML = layerText;

			//grab the sizes
			var imageH = document.getElementById('imageH');
			pwidth = imageH.width;
			pheight = imageH.height;

			//work out final sizing
			if(pwidth > pheight){
				factor = Math.round(pwidth/100);
			}
			else{
				factor = Math.round(pheight/100);
			}
			pwidth = Math.round(pwidth/factor);
			pheight = Math.round(pheight/factor);

			var layerText = '<img name=image1 src="file:\/\/\/'+document.getElementById('attachfile').value +'" width='+pwidth+' height='+pheight+'>';
			var img = document.getElementById('imgdiv');
			img.innerHTML = layerText;
		}
	}
}

function af_UrlEncode(strText) {
	var isObj;
	var trimReg;
	if(typeof(strText)=="string"){
		if(strText!=null){
			trimReg= /(^\s+)|(\s+$)/g;
			strText = strText.replace(trimReg,'');
			for(i=32;i<256;i++){
				strText=strText.replace(String.fromCharCode(i),escape(String.fromCharCode(i)));
			}
		}
	}
	return strText;
}

function aftest(){
	alert("helo");
}
function af_reset_page(){
	top.document.location.href = top.document.location.href;
}

//Disable right mouse click Script
function clickIE4(){if (event.button==2){return false;}}
function clickNS4(e){
	if (document.layers||document.getElementById&&!document.all){
		if (e.which==2||e.which==3){return false;}
	}
}

if (document.layers){
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
	document.onmousedown=clickIE4;
}
document.oncontextmenu=new Function("return false")
//End Disable right mouse click Script


function xbosinclude(pagename, target){ //used for testing
	alert(pagename);
	alert(target);
}

var rootdomain="http://"+window.location.hostname
var zusername = ""

/* BOS Developement - start replace inner html with code from remote file	*/
function bosinclude(url,targetid) {
	var page_request = false
	if (window.XMLHttpRequest){ // if Mozilla, Safari etc
		page_request = new XMLHttpRequest();
	}
	else if (window.ActiveXObject){ // if IE
		try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e){
			try{
				page_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){}
		}
	}
	else{
		return false;
	}
	//using the GET method
	page_request.open("GET", "serve.php?pagename="+url, false) //get page synchronously 
	page_request.send(null);	//close connection
	bosparseresults(page_request.responseText,targetid); //process the returned info
}

//Problem: if we need to perform multiple content changes, we must allow for it
function bosparseresults(page_request,targetid){
	var btarget=document.getElementById(targetid); //establish the target
	darray = page_request.split("&afbreak;");	//first break the string into an array based on terminator "&afbreak;"
	btarget.innerHTML=darray.shift();	//place content in specified target	
	while(darray.length>1){ //if there is still info in the array, process it
		content=darray.shift(); //extract next content
		target=darray.shift(); //extract next target
		btarget=document.getElementById(target); //establish the target
		btarget.innerHTML=content;	//place content in specified target	
	}
}
/* BOS Developement - end replace inner html with code from remote file	*/

/* start thumbnail click processing - all credit to Jennifer Kyrnin for the idea */
function afPopImage(imageurl){
//	target=document.getElementById('popimage');
	afSwopVisibility('popimage', 'primary_holder');
	bosinclude('imageblurb&imgid='+imageurl , 'popimage');
}

function afDumpImage(){
	afSwopVisibility('primary_holder', 'popimage');
	target=document.getElementById('popimage');
	target.innerHTML="";
}
/* end thumbnail click processing */

//swap visibility of 2 element id's
function afSwopVisibility(makevisible, makehidden){
	light=document.getElementById(makehidden);
	light.style.display='none';
	dark=document.getElementById(makevisible);
	dark.style.display='inline';
}



function verifylogin(){
	frm=document.getElementById("signin");

	if(frm.username.value.length < 1){
		alert("Please type in your User Name");
		frm.username.focus();
		return false;
	}
	if(frm.userpassword.value.length < 1){
		alert("Please type in your Password");
		frm.userpassword.focus();
		return false;
	}
	bosinclude("signin_verify&username="+frm.username.value+"&userpassword="+frm.userpassword.value, "maindisplay")
}

function verifysignup(){
	frm=document.getElementById("signup");
	if(frm.username.value.length < 1){
		alert("Please type in your User Name");
		frm.username.focus();
		return false;
	}
	if(frm.userpassword.value.length < 1){
		alert("Please type in your Password");
		signup.userpassword.focus();
		return false;
	}
	if(frm.email.value.length < 1){
		alert("Please type in your Email Address");
		frm.email.focus();
		return false;
	}

	bosinclude("signup_verify&username="+frm.username.value+"&userpassword="+frm.userpassword.value+"&useremail="+frm.email.value, "maindisplay")
}

