// function: rotate()
// Used to give one element a class and give all others within the same container a different class.  Commonly used on rotator spots on frontpages.
// @thisId : string : id of element to be displayed
// @containerId : string : id of the container of elements to be hidden
// @thisClass(optional) : string : class to be given to the element. If not set, 'visible' will be used
// @containerId(optional) : string : class to be given to all other elements within container. If not set, 'hidden' will be used
function rotate( thisId, containerId, thisClass, otherClass ){
	
	// set default values for thisClass and otherClass
	var thisClass = (thisClass == null) ? "visible" : thisClass;
	var otherClass = (otherClass == null) ? "hidden" : otherClass;
	
	// grab all elements within container
	var elements = document.getElementById(containerId).childNodes;
	
	// loop through elements
	for(var i = 0; i < elements.length; i++){
	
		// if this is the element, give it thisClass
		if( elements[i].id == thisId ){
			elements[i].className = elements[i].className.replace(thisClass, '');
			elements[i].className = elements[i].className.replace(otherClass, '');
			elements[i].className = elements[i].className + ' ' + thisClass;
		
		// if this isn't the element and the element can have a class, give it otherClass
		}else if(elements[i].className != undefined){
			elements[i].className = elements[i].className.replace(thisClass, '');
			elements[i].className = elements[i].className.replace(otherClass, '');
			elements[i].className = elements[i].className + ' ' + otherClass;
		}
	}
	
	// return id of current element
	return thisId;
}

// function: loadURL()
// Loads the URL passed to it.  This gets used for loading a page from a select box
// @url : string : the URL to be opened
function loadURL( url ){
	if( url != undefined && url != '' ){
		window.location = url;
	}
}

// function: CheckInputData()
// description stub
// @information : stub
function CheckInputData(information){
	var sendform = true;
	var regproblem = '';
	var problems = 'Your registration cannot be submitted until the\nfollowing is corrected:\n\n';

	var Form = information;	
	checkEmail = Form.email.value

		if ((checkEmail.indexOf('@') < 0) || ((checkEmail.charAt(checkEmail.length-4) != '.') && (checkEmail.charAt(checkEmail.length-3) != '.'))){ 
		problems += '-You have entered an invalid email address. Please try again.\n'
			sendform = false;
			regproblem = true;
		}
	 
		if (information.pwd.value =="") {
		problems += '-Password is required.\n'
			sendform = false;
			regproblem = true;
		}

		 if (information.pwdr.value =="") {
		problems += '-Please confirm password.\n'
			sendform = false;
			regproblem = true;
		}

		if (information.pwd.value != information.pwdr.value) {
		problems += '-The passwords supplied do not match.\n'
			sendform = false;
			regproblem = true;
		}

		if (information.gender.value =="") {
		problems += '-Please select gender.\n'
			sendform = false;
			regproblem = true;
		}

		if (information.extra_birthyear.value =="") {
		problems += '-Year of birth is required.\n'
			sendform = false;
			regproblem = true;
		}

		if (information.extra_zipcode.value =="00000" || information.extra_zipcode.value == '') {
		problems += '-Zip code is required.\n'
			sendform = false;
			regproblem = true;
		}
		
		if (information.extra_countryCode.value =="") {
		problems += '-Country is required.\n'
			sendform = false;
			regproblem = true;
		}
		
		if (information.extra_incomeID.value =="" || information.extra_incomeID.value == "0") {
		problems += '-Income is required.\n'
			sendform = false;
			regproblem = true;
		}
		
		if (information.extra_industryId.value =="") {
		problems += '-Industry is required.\n'
			sendform = false;
			regproblem = true;
		}
	 
		if (information.extra_jobTitleId.value =="0") {
		problems += '-Job Title is required.\n'
			sendform = false;
			regproblem = true;
		 }

		 if (information.extra_newspaper.selectedIndex < 1) {
		problems += '-Please select usage.\n'
			sendform = false;
			regproblem = true;
		 }
	
		if (information.agreement.checked == false ) {
		problems += '-Please agree to the subscriber agreement.\n'
			sendform = false;
			regproblem = true;
		 }

		if (regproblem != true)	 {
			sendform = true;
		}
					
		// send form
		if (sendform == true) {
		//return false // change to true

		return true;
		pbsSetCookie(information);
		} else {
		alert(problems);
		return false;
		}
}

// function: NewWindow()
// Opens a popup window
// @width : int : width of new window
// @height : int : height of new window in pixels
// @url : string : url of new window
function NewWindow(width,height,url) {
	window.open(url,"PopUp","menubars=0,scrollbars=1,resizable=1,height="+height+",width="+width);
}

// function: openWin()
// description stub
// @windowURL : stub
// @windowName : stub
// @windowFeatures : stub
function openWin( windowURL, windowName, windowFeatures ){
	return window.open( windowURL, windowName, windowFeatures );
}

// function: popup()
// description stub
// @url : stub
// @name : stub
// @height : stub
// @width : stub
// @scrollbars : stub
function popup(url, name, height, width, scrollbars)
{
	var popwin;
	var opts = "toolbar=no,status=no,location=no,menubar=no,resizable=no";
	opts += ",height=" + height + ",width=" + width + ",scrollbars=" + scrollbars;

	popwin = window.open("", name, opts);

	popwin.focus();

	popwin.location = url;

}

// function: EatCookie()
// description stub
function EatCookie() {
	document.cookie="usernamepassword=;Path=/"
	document.cookie="UserRegID=;Path=/"
	document.location="/apps/pbcs.dll/frontpage?RegLogout=1"
}

// function: ChangeClassName()
// description stub
// @id : stub
// @newClassName : stub
function ChangeClassName(id, newClassName) {
		document.getElementById(id).className = newClassName;
}

// function: ajaxRequest()
// description stub
// @url : stub
// @pars : string : vars to be passed to the given url in the format of 'var1=value1&var2=value2'
// @viewFunction : string : name of function to parse the returned output
function ajaxRequest( url, pars, viewFunction ){
	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'post',
			parameters: pars,
			onComplete: eval(viewFunction)
		});
}


function ajaxRequest2( url, pars, viewFunction ){
	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'post',
			parameters: pars,
			onComplete: eval(viewFunction)
		});
}



// function: displayPoll()
// this function should not be called directly.  It parses an ajax request for submitting the poll
// @originalRequest : object : the response received from the ajax request
function displayPoll(originalRequest){
	$('poll').style.display = 'none';
	var regex = /[\s\S]*<BODY BGCOLOR="#FFFFFF">([\s\S]*)<\/BODY>[\s\S]*/gm;
	$('poll').innerHTML = originalRequest.responseText.replace(regex,"$1");
	try{
		$('poll_submit').onclick = function(e){
			ajaxRequest( $('poll_submit').parentNode.action, Form.serialize($('poll_submit').parentNode), 'displayPoll');
			$('poll').innerHTML = '<img src="/graphics/loading.gif" alt="" /> Submitting vote...';
			return false;
		}
	}catch(e){}
	new Effect.BlindDown('poll', {duration: .5});
}


function displayPoll2(originalRequest){
	$('poll').style.display = 'none';
	var regex = /[\s\S]*<BODY BGCOLOR="#FFFFFF">([\s\S]*)<\/BODY>[\s\S]*/gm;
	$('poll').innerHTML = originalRequest.responseText.replace(regex,"$1");
	try{
		$('poll_submit').onclick = function(e){
			ajaxRequest( $('poll_submit').parentNode.action, $('poll_submit').parentNode.serialize(), 'displayPoll');
			//$('poll').innerHTML = '<img src="/graphics/loading.gif" alt="" /> Submitting vote...';
			return false;
		}
	}catch(e){}
	new Effect.BlindDown('poll', {duration: .5});
}


// function: makeVisible(), hideme()
// description: newslist and agentlist object file - show and hide thumbnails and lede
// agent102 newslist16


function makeVisible(id){
	
	element = "details"+id;
	teaser = "tease" + id;

	theader = document.getElementById(teaser);
	target = document.getElementById(element);
	
	theader.style.display = 'none';
	target.style.display = 'block';
	

}

function hideMe(id){

	element = "details"+id;
	teaser = "tease" + id;

	theader = document.getElementById(teaser);
	target = document.getElementById(element);
	
	theader.style.display = 'block';
	target.style.display = 'none';
	

}



// functions: choosedate(), ResetDate(), DoPrint()
// description: for events search
// 

function choosedate () {
	window.open('/g/kalender_eng.html?searchform.dateselected','','menubar=0,titlebar=0,width=268,height=236');
	document.searchform.Interval.options[document.searchform.Interval.options.length-1].selected = true;
}

function ResetDate () {
	if (document.searchform.Interval.selectedIndex != (document.searchform.Interval.options.length-1))
	{
		document.searchform.dateselected.value = "";
	}
}

function DoPrint () {
	var f = document.searchform;
	f.action = "<pbs:prog>/events?category=print";
	f.submit();
}




// functions: setSocCat(bucketsearch)
// description: for SEARCH BOX CATEGORY
// 



// functions: 
// description: for MULTIMEDIA VIDEO PAGE
// 

		function goto(ID)
		{
		document.location.href = "/apps/pbcs.dll/section?Category=multimedia&ID=" + ID;
		}
		function getQueryVariable(variable)
		{
		var query = window.location.search.substring(1);
		var vars = query.split("&");
		  for (var i=0;i<vars.length;i++) 
		  {
			var pair = vars[i].split("=");
			if (pair[0] == variable) {
			  return pair[1];
			}
		  } 
		}
		function getmovieid()
		{
			document.getElementById("test").value=getQueryVariable("ID");
		}
		function mout(ID,imagename)
		{
			  document.getElementById(ID).src = "/images/" + imagename;
		}
		function mover(ID,imagename)
		{
			  document.getElementById(ID).src = "/images/" + imagename;
		}
		
		function MIn(objId,opacity,msg) 
		{
		  if (document.getElementById)
		  {
			obj = document.getElementById(objId);
			setOpacity(obj, 100);
			ddrivetip(msg, 300);
		  }
		}
		function Mout(objId,opacity) 
		{
		  if (document.getElementById)
		  {
			obj = document.getElementById(objId);
			setOpacity(obj, 40);
			hideddrivetip();
		  }
		}
		function setOpacity(obj, opacity) 
		{
			opacity = (opacity == 100)?99.999:opacity;
		    obj.style.filter = "alpha(opacity=" + opacity + ")";		  
		    obj.style.KHTMLOpacity = opacity/100;		  
		    obj.style.MozOpacity = opacity/100;		  
		    obj.style.opacity = opacity/100;
		}