// JavaScript Document
var intSelStory = 0;
function do_select_story(strNumIn){
	if(typeof Prototype == "undefined")
		alert(strNotLoaded)
	else{
		if(intSelStory != strNumIn){
			var divNew = $('divStory_' + strNumIn);
			var divOld = $('divStory_' + intSelStory);
			var divTarg = $('divStory');
			intSelStory = strNumIn;
			for(var i=1; i <=4; i++){
				do_unhover_pic(i);
			}
			divTarg.innerHTML = divNew.innerHTML;
			divOld.display = "none";
			divTarg.style.zIndex = "100";
			divNew.style.zIndex = "50";
		}
	}
}

function do_hover_pic(strNumIn){
	if(typeof Prototype == "undefined")
		alert(strNotLoaded)
	else if (strNumIn >0){
		//var divTitleDest = $('divStoryHead');
		//var divBodyDest = $('divStoryBody');
		//var divTitleSrc = $('divStoryHead_' + strNumIn);
		//var divBodySrc = $('divStoryBody_' + strNumIn);
		var imgImage = $('imgHover_' + strNumIn);
		//alert("DEBUG: 'imgHover_" + strNumIn + "' = " + imgImage );
		imgImage.src = "img/hover_" + strNumIn + "_on.jpg";
		if(intSelStory != strNumIn){
			var divNew = $('divStory_' + strNumIn);
			var divTarg = $('divStory');
	
			divNew.absolutize();
			divNew.clonePosition(divTarg) 
			divNew.style.zIndex = "400";
			divNew.appear({duration: 0.25});
		}
		//alert(imgImage.Src);
		//divTitleDest.innerHTML = divTitleSrc.innerHTML;
		//divBodyDest.innerHTML = divBodySrc.innerHTML;
	}
}

function do_unhover_pic(strNumIn){
	if(typeof Prototype == "undefined")
		alert(strNotLoaded)
	else{
	//alert(intSelStory + " != " +  strNumIn + " = " + (intSelStory != strNumIn));
	var divNew = $('divStory_' + intSelStory);
	if(intSelStory != strNumIn){
		var imgImage = $('imgHover_' + strNumIn);
		var divOld = $('divStory_' + strNumIn);
		
		do_hover_pic(intSelStory);		
		imgImage.src = "img/hover_" + strNumIn + "_off.jpg";
		divOld.fade({duration: 0.25});	
		divOld.style.zIndex = "10";
		//alert(imgImage.Src);
	}else {
		var divOld = $('divStory_' + intSelStory);
		divOld.style.zIndex = "100";
	}
	//if(divNew.style.display == "")
		//divNew.appear({duration: 0.25});
	}
}

var arrSticky = new Array();
var arrStuck = new Array();

function show_pop(strAuth,strTarg){
	if(typeof Prototype == "undefined")
		alert(strNotLoaded)
	else{
	var dDiv = $('divPop_'+ strAuth);
	var objTarg = $(strTarg);
	//alert(strAuth+ ' , ' + strTarg);
	dDiv.absolutize();
	dDiv.clonePosition(objTarg, {offsetTop : objTarg.getHeight(), offsetLeft : -12}) 
	dDiv.style.width = "200px";
	dDiv.style.height = "auto";
	dDiv.appear({ duration: 0.15 });
	//alert(objTarg.id);
	}
}

function hide_pop(strAuth, force){
	if(typeof Prototype == "undefined")
		alert(strNotLoaded)
	else{
	var dDiv = $('divPop_'+ strAuth);
	if(force){
		arrStuck = arrStuck.without(strAuth);	
	}
	setTimeout('fade_pop(\'' + strAuth + '\')',200);
	}
}

function fade_pop(strAuth){
	if(typeof Prototype == "undefined")
		alert(strNotLoaded)
	else{
	var dDiv = $('divPop_'+ strAuth);
	//alert('Sticky: ' + arrSticky.indexOf(strAuth) + ' Stuck: ' + arrStuck.indexOf(strAuth));
	if(arrSticky.indexOf(strAuth) < 0 && arrStuck.indexOf(strAuth) < 0)
		dDiv.fade({ duration: 0.15 });
	}
}

function make_pop(strAuth){
	if(typeof Prototype == "undefined")
		alert(strNotLoaded)
	else{
	if(arrSticky.indexOf(strAuth) >= 0)
		arrSticky = arrSticky.without(strAuth);
	else
		arrSticky.push(strAuth);
	}
}


var recCnt = 0;
var recTot = 0;

function do_invite(){
	if(typeof Prototype == "undefined")
		alert(strNotLoaded)
	else{
		var dModal = showModal('frmInvite');
		$('divInvSuccess').fade();
		$('btnInvSub').appear();
		var field_area = $('divRecipients');
		if(recTot > 0)
			field_area.innerHTML = "";
	 	var inpEmail = $('strInvEmail');
		inpEmail.value = "";
	}
}

function do_rss(){
	if(typeof Prototype == "undefined")
		alert(strNotLoaded)
	else{
		var dModal = showModal(null, 500, 'divRSSForm');
		var strFunc = 'show_rss';
		var poststr;
		make_req(strAjaxURL + 'rss.php',strFunc,poststr,'POST');
	}
}

function show_rss(strArgs){
	$('divRSSContent').innerHTML = strArgs;
}

function remove_recipient(liID){
	 if(!document.getElementById) return; //Prevent older browsers from getting any further.
	 var field_area = $('divRecipients');
	 var recli = $(liID);
	 if(recli){
		 field_area.removeChild(recli);
		 recTot--;
	 }	
	 if(recTot == 0)
		 field_area.innerHTML = "";
}

function invite_cancel(){
	destroyModal();	
	 var field_area = document.getElementById('divRecipients');
	 field_area.innerHTML = "";
	 var inpEmail = $('strInvEmail');
	 inpEmail.value = "";
	 recTot == 0;
}



function add_inv_addy() {
 if(!document.getElementById) return; //Prevent older browsers from getting any further.
 var field_area = document.getElementById('divRecipients');
 var value=document.getElementById('strInvEmail').value;
//$('strInvEmail').className = "required validate-email inpInvite";
	//if(Validation.get('invValid').test('strInvEmail')){
 if(addValid.validate()) {
	 if(value){
		 if(recTot == 0)
			 field_area.innerHTML = "";
		 if(document.createElement) { //W3C Dom method.
		  var li = document.createElement("li");
		  var input = document.createElement("input");
		  input.name = "to_email[]";
		  input.value = value;
		  input.type = "hidden"; //Type of field - can be any valid input type like text,file,checkbox etc.
		  li.innerHTML = value + "<A style=\"cursor:pointer\" onclick=\"javascript:remove_recipient('li" + recCnt + "')\"> [ Remove ]</a>";
		 li.setAttribute('id',"li" + recCnt);
		  li.appendChild(input);
		  field_area.appendChild(li);
		 } else { //Older Method
		  field_area.innerHTML += "<LI id=\"li" + recCnt + "\">" + value + " <A  style=\"cursor:pointer\" onclick=\"javascript:remove_recipient('li" + recCnt + "')\">[ Remove ]</a> <input name='to_email['" + value + "']' id='to_email' type='hidden' value='" + value + "' /></LI>";
		 }
	 	recCnt++;
	 	recTot++;
	 //Clear field value
	 document.getElementById('strEmail').value = "";
	}	
 }
 //$('strInvEmail').className = "inpInvite";
 return false;
}

function update_rand(strCurrId){
	if(typeof Prototype == "undefined")
		alert(strNotLoaded)
	else{
		var strFunc = 'after_update_rand';
		var poststr;
		
		poststr = "CurrId=" + escape($('hidCurrRandPosts').value);
		//poststr = "CurrId=" + strCurrId;
		make_req(strAjaxURL + 'random.php',strFunc,poststr,'POST');		
	}
}

function after_update_rand(strArgs){		
	$('divRandCont_front').innerHTML = $('divRandCont').innerHTML;
	//$('divRandCont_front').className = $('divRandCont').className;
	//$('divRandCont_front').style = $('divRandCont').style;
	//if(Prototype.Browser.IE)
		$('divRandCont_front').clonePosition($('divRandCont'));
	//else
		//$('divRandCont_front').clonePosition($('divRandCont'), {offsetTop : -10});
	
	$('divRandCont_front').style.display = "";
	$('divRandCont').style.display = "none";
	$('divRandCont').innerHTML = strArgs;	
	$('divRandCont_front').fade({duration:0.75});
	$('divRandCont').appear({duration:1.2});
}

function submit_form(){
	if(Valid.validate()){
		strFunc = 'after_save';			
		var poststr = "action=save_petition&" + get_arg_list('frmPetition');
		make_req(strAjaxURL + 'save_petition.php',strFunc,poststr,'POST');
		//show_update('tableOutput');									
	}
	return false;
}
function after_save(strArgs){
	if(strArgs == "SUCCESS"){
		$('divSuccess').absolutize();
		$('divSuccess').clonePosition($('divSubmit')) ;
		$('divSuccess').appear();
		$('divSubmit').fade();
	}else
		alert(strArgs);
}
//Wipe field variables on load (for firefox)
 /*document.getElementById('name').value ="";
 document.getElementById('city').value ="";
 document.getElementById('email').value ="";
 document.getElementById('province').value ="";
 document.getElementById('message_body').value ="";*/
 
function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;} 