/*	IMPORTANT!
 *	The file "sidebar2.php" in the webroot uses window.onload! 
 *	This means if you try to set window.onload here, wherever sidebar2.php is included,
 *	window.onload it will be overwritten by and nothing will happen!
 *	IMPORTANT!
 */

function Start(page)
{
	OpenWin = this.open(page, "MyNewWindow", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=800,height=600");
}

function onBuyit()
{
	document.Form1.action = "https://www.emovieposter.com/gallery/buyitnow/order.php";
	document.Form1.target = "_blank";
	document.Form1.submit();
	return true;
}

function onQuestion()
{
	document.Form1.action = "http://www.emovieposter.com/includes/sendquestion.php";
	document.Form1.submit();
	return true;
}

function useStart(page)
{
	OpenWin = window.open(page, "MyNewWindow", "toolbar=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes,width=800,height=600");
}

function findPos(obj)
{
		/*
	var curleft = curtop = 0;
	curleft = obj.offsetLeft
	curtop = obj.offsetTop
	if (obj.offsetParent) {
	while (obj = obj.offsetParent) {
		curleft += obj.offsetLeft
		curtop += obj.offsetTop
	}
	}
	return curleft;
	*/
	
	//document.writeln(obj.parentNode.offsetLeft);
	
	thishereVar = obj.offsetLeft + obj.parentNode.parentNode.offsetLeft;
	
	returnVal = thishereVar + 'px';
	
	// document.writeln(returnVal);
	
	return returnVal;
}

function searchGallery()
{
	newTerms = document.search.keywords.value;
	newPage = document.search.gallery.value;
	newLoc = '/gallery/' + newPage + '/search/' + newTerms + '.html';
	window.location.href = newLoc;
	return false;
}

function changeSection()
{
	newTerms = document.sectionchoose.section.value;
	newPage = document.getElementById('gallerypage').value;
	newLoc = '/gallery/' + newPage + '/section/' + newTerms + '.html';
	window.location.href = newLoc;
	return false;
}

function changeRecordsPerPage()
{
	newTerms = document.getElementById('myrecords').value;
	newPage = document.getElementById('gallerypage').value;
	newLoc = '/gallery/' + newPage + '/records/' + newTerms + '.html';
	window.location.href = newLoc;
	return false;
}

//menuTop = 86;
//window.onscroll = doSomething;
// We are no longer using a floating menu
function doSomething()
{
	thishere=document.getElementById("menu");
	if(document.documentElement.scrollTop > menuTop+14)
	{
		if(navigator.appCodeName == "Mozilla")
		{
			if(thishere.style.position == "absolute")
			{
				thishere.style.top='10px';
				// thisherevar = findPos(thishere);
				//thishere.style.left= thisherevar;
			thishere.style.position='fixed';
			}
		}
		if(navigator.appName == "Microsoft Internet Explorer")
		{
			myvar = (document.documentElement.scrollTop) + 'px';
			thishere.style.position="absolute";
			thishere.style.top=myvar;
		}
	}
	else
	{
		thishere.style.position="absolute";
		thishere.style.top= menuTop+'px';
		thishere.style.left='20px';
	}
}

function validateForm(redoButton, fieldId)
{
	var myVal = document.getElementById(fieldId).value;
	var myTemp = window.prompt('Please enter your e-mail address again.','');
	if(myVal == myTemp)
	{
		if(document.getElementById(redoButton).disabled == false)
		{
			document.getElementById(redoButton).disabled = true;
		}
		return true;
	}
	else
	{
		if(document.getElementById(redoButton).disabled == true)
		{
			document.getElementById(redoButton).disabled = false;
		}
		alert("Your e-mail addresses did not match. Please try again.");
		document.getElementById(fieldId).value = "";
		return false;
	}
}

function validateThisForm()
{
	var first = document.getElementById('first').value;
	var last = document.getElementById('last').value;
	var addr1 = document.getElementById('address1').value;
	var email = document.getElementById('email').value;
	var city = document.getElementById('city').value;
	var state = document.getElementById('state').value;
	var zip = document.getElementById('zip').value;
	var pass1 = document.getElementById('pass1').value;

	var myError = 0;
	
	if(first == "")
		myError = myError + 1;
	if(first == " ")
		myError = myError + 1;
	if(last == "")
		myError = myError + 1;
	if(last == " ")
		myError = myError + 1;
	if(addr1 == "")
		myError = myError + 1;
	if(addr1 == " ")
		myError = myError + 1;
	if(email == "")
		myError = myError + 1;
	if(email == " ")
		myError = myError + 1;
	if(city == "")
		myError = myError + 1;
	if(city == " ")
		myError = myError + 1;
	if(state == "")
		myError = myError + 1;
	if(state == " ")
		myError = myError + 1;
	if(zip == "")
		myError = myError + 1;
	if(zip == " ")
		myError = myError + 1;
	if(pass1 == "")
		myError = myError + 1;
	if(pass1 == " ")
		myError = myError + 1;
	
	if(myError > 0)
	{
		alert("You must fill out all required fields which are marked with an asterisk (*)");
		return false;
	}
	else
	{
		return true;
	}
}
	
function signupValidation(formName)
{
	if(validateThisForm())
	{
		var temp1 = document.getElementById('pass1').value;
		var temp2 = document.getElementById('pass2').value;
		if(temp1 == temp2)
		{
			return true;
		}
		else
		{
			alert("The passwords did not match. Please try again.");
			return false;
		}
	}
	else
	{
		return false;
	}
}

	/*AjAX Area*/
	
function toggleLayer(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"block";
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
}



function xmlhttpPost(strURL)
{
	toggleLayer("loading");
	toggleLayer("content");
	myHist = "22" + " Page";
	dhtmlHistory.add(hashName,myHist);
	myvar = strURL;
	thisHash = hashName;
	window.location.hash = hashName;
	setTimeout("number2(myvar)",850);
}

function number2(strURL)
{
	toggleLayer('loading'); 
	var xmlHttpReq = false;
	var self = this;
	if (window.XMLHttpRequest)	// Mozilla/Safari
		self.xmlHttpReq = new XMLHttpRequest();
	else if (window.ActiveXObject)	// IE
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	self.xmlHttpReq.open('POST', strURL, true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function()
	{
		if (self.xmlHttpReq.readyState == 4)
			updatepage(self.xmlHttpReq.responseText);
	}
	self.xmlHttpReq.send("");
	setTimeout("toggleLayer('content')",225);
}

function getquerystring(hereForm)
{
	var myForm = document.forms[hereForm];
	var strSubmit;
	
	for (i = 0; i < myForm.elements.length; i++)
	{
		formElem = myForm.elements[i];
		switch (formElem.type)
		{
			// Text, select, hidden, password, textarea elements
			case 'text':
			case 'select-one':
			case 'hidden':
			case 'password':
			case 'textarea':
				strSubmit += formElem.name + 
				'=' + escape(formElem.value) + '&'
				break;
		}
		
	}
	document.writeln(hereForm);
	return strSubmit;
}

function buildForm(formName, url, hash)
{
	myString = getquerystring(formName);
	finalUrl = url + "?" + myString;
	xmlhttpPost(finalUrl, hash);
}

function updatepage(str)
{
	document.getElementById("contentbox").innerHTML = str;
}

function checkVoter()
{
	var myVar = document.getElementById("wronganswer");
	if(myVar.checked == true)
	{
		alert("You must select an answer. If no answer properly expresses your views, please select 'Other' and tell us why in the 'Comments' box.");
		return false;
	}
	else
	{
		return true;
	}
}

function onechecked(myForm)
{
	var count = 0;	
	theForm = document.getElementById(myForm);
	theStr = '';
	for (i=0; i < theForm.elements.length; i++) 
	{
		if(theForm.elements[i].checked)
			count++;
	}
	if(count > 0)
	{
		return true;
	}
	else
	{
		alert('You must Check at least one Checkbox');
		return false;	
	}
}

function externalLinks()
{
	return false;
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	myregexp = new RegExp("^(http://{1})(w{0,3})(\.*)(emovieposter\.com/{1})");
	
	for (var i=0; i<anchors.length; i++)
	{
		var anchor = anchors[i];
		if (anchor.getAttribute("href").match(myregexp))
		{
		}
		else
		{
			if((anchor.getAttribute("href").charAt(0) != '/') && (anchor.getAttribute("href").charAt(0) != '#') && (anchor.getAttribute("href").charAt(0).toUpperCase() != 'J'))
			{
				anchor.target = "_blank";
			}
		}
	}
}

function nw(url,w,h)
{
	if(!w)
		w = 400;
	if(!h)
		h = 400;
	newwindow = window.open(url, "", "height=" + h + ",width=" + w + ",left=100,top=100,resizable=no,scrollbars=yes,toolbar=no");
}
//window.onload = externalLinks;

