// Site functionality
// Requires: prototype.js + tuksi.js
// Author: Andreas Mailand, ama@dwarf.dk








// aktiver javascript - inden indhold er loadet ind
Tuksi.prototype.preInit = function(){
}

// aktiver javascript - efter indhold er loadet ind
Tuksi.prototype.postInit = function(){
if($('mWebshopPopup')) {
  $('mWebshopPopup').setStyle({display:"none"});
}
}

// global variable for current active pressList item
var oGlobalPressListItem = "";
var oGlobalPressListItemLink = "";

function pressListToggle(sKey, oThis){
	a = "";
	oNewCurrent = $('item' + sKey);

	if (oGlobalPressListItem != "" && oGlobalPressListItem != oNewCurrent && oGlobalPressListItem.style.display != "none"){
		a = oNewCurrent.id + ", " + oGlobalPressListItem.id + ", " + oGlobalPressListItem.style.display
		oGlobalPressListItem.toggle(); // switch off the current active pressList item

		if (oGlobalPressListItemLink.className == "active"){
			oGlobalPressListItemLink.className = "notActive";
		} else {
			oGlobalPressListItemLink.className = "active";
		}

	}

	oNewCurrent.toggle();

	if (oThis.className == "active"){
		oThis.className = "notActive";
	} else {
		oThis.className = "active";
	}

	oGlobalPressListItemLink = oThis;

	sifrSubtleReplace(); // activate sIFR again - to reconstruct the previously hidden headlines

	oGlobalPressListItem = oNewCurrent; // set the new current active pressList item in the global variable
}


/* print function to only print the inside of an object - used on press list */
function printThisBox (sId){
	var oObject = $(sId);

	var newDoc = "<html><head><title>Print vindue</title><link rel=\"Stylesheet\" type=\"text/css\" href=\"/stylesheet/style.css\"></head><body class=\"printPopup\">" + oObject.innerHTML + "</body></html>";

	var NewWindow = window.open("","Print_vindue","height=400,width=400, scrollbars=yes");

	NewWindow.document.write(newDoc);
	NewWindow.document.close();
	NewWindow.print();

}

function tipEnVenReset() {
	document.tipenven.fname.value = "";
	document.tipenven.femail.value = "";
	document.tipenven.yname.value = "";
	document.tipenven.yemail.value = "";
	document.tipenven.comments.value = "";
	document.getElementById("tev_fname").className = "";
	document.getElementById("tev_femail").className = "";
	document.getElementById("tev_yname").className = "";
	document.getElementById("tev_yemail").className = "";
}


function tipEnVen(fname, femail, yname, yemail, comment, url) {

	// check if user has filled out all fields
	var error = false;

	if (fname.length == 0) {
		document.getElementById("tev_fname").className = "error";
		error = true;
	} else {
		document.getElementById("tev_fname").className = "";
	}
	if (femail.length == 0) {

		document.getElementById("tev_femail").className = "error";
		error = true;
	} else {
		document.getElementById("tev_femail").className = "";
	}
	if (yname.length == 0) {
		document.getElementById("tev_yname").className = "error";
		error = true;
	} else {
		document.getElementById("tev_yname").className = "";
	}
	if (yemail.length == 0) {
		document.getElementById("tev_yemail").className = "error";
		error = true;
	} else {
		document.getElementById("tev_yemail").className = "";
	}

	if (error === true) {
		return false;
	}

	// send email

	new Ajax.Request('/include/pagegenerator/modules/ajax_tipenven.php',
		{
		method:'POST',
		parameters: {comment: comment,
					 fname:   fname,
					 femail:  femail,
					 yname:	  yname,
					 yemail:  yemail,
					 url:	  url},
		onSuccess: function(transport, json){
			// do nothing so far
			urchinTracker('/tracking/tip_en_ven');
			
		},
		onFailure: function(){
			alert('Der er opstået en fejl ...') }
		});

	return true;

}

function webshopPopup() {
  $("mWebshopPopup").toggle();
  return false;
}


