﻿// Removes left vertical line on rollover	
function navMainDivider(wrapper, status){
	var element = document.getElementById(wrapper);
	if (status == "hide"){
		element.style.background = "none";
	}
	else if (status == "show"){
		if(!$(wrapper).hasClass("previous")){
			element.style.background = "url(images/global/white_list_line.gif) no-repeat center right";
		}
	}
}

function initSearchBox(){
if($$(".searchBoxButton")[0]){
	$$(".searchBoxButton").each(function(el){
		//console.log(el.getParent().getNext());
		el.slideFX = new Fx.Slide(el.getParent().getNext(),{
		onComplete: function(element){
				if(element.getParent().getStyle("height").toInt()<2){
					this.set([0, 1]);
					element.getParent().setStyle('display',"none");
				}else{
					this.set(this.to);
				}
		},
		onStart: function(element){		
				if(element.getParent().getStyle("height").toInt()==0){
					this.set([0, 1]);
				}else{
				}
		},
		duration:600		
		});
	});	
	$$(".searchBoxButton").each(function(el){
		el.addEvent('click', function(e){
			e = new Event(e);
			e.target.slideFX.element.getParent().setStyle('display',"");
			e.target.addClass("downArrow");
			e.target.removeClass("normal");
			e.target.slideFX.slideIn().chain(function(){
				$$(".searchBoxButton").each(function(el){
					if(el!=e.target){
						el.removeClass("downArrow");	
						el.addClass("normal");
						el.slideFX.slideOut();			
					}else{
			
					}
				}.bind(e));	
			}.bind(e))
			e.stop();
		});		
	});
	//$$("#otherHeader div.searchBoxButton")[0].slideFX.hide();
	//$$("#otherHeader div.searchBoxButton")[0].removeClass("downArrow");
	$$("#otherHeader div.searchBoxButton")[0].addClass("downArrow");
	//$$("#otherHeader div.searchBoxButton")[0].addClass("normal");
}
}
function initResultsTabs(){
	$$('.tabs ul li').each(function(el){
			//el.setStyle('display',"none");
		});

}

// MY IRELAND PROMPT STUFF
function popupPrompt(el){
	$("prompt").setStyle("z-index",10000);
	$("prompt").setStyle("top",($(el).getTop()-100));
	$("prompt").setStyle("visibility",'visible');
	return false;
}	
function removePrompt(el){
	$("prompt").setStyle("z-index",-10000);
	$("prompt").setStyle("visibility",'hidden');
	return false;
}
function deleteItem(el){
	if(Cookie.get('repeatDelete')=="true"){
		deleteWithoutConfirm(el);
		return false;
	}
	popupPrompt(el);
	return false;
}
function deleteWithoutConfirm(el){
	setRepeatCookie();	
	
	// ENTER DELETE FUNCTION HERE
	
	if($("prompt").getStyle("z-index")!=-10000)removePrompt(el)
	return false;
}

function setRepeatCookie(){
	if ($('dont_prompt').checked){
		Cookie.set('repeatDelete', 'true');
	}
}
// END MY IRELAND PROMPT STUFF
fadeStatus="finished";
nextFade="";
nextFadeIm="";
function fadeMap(which,io){
	if (io=="in" && fadeStatus=="finished"){
		clearTimeout(nextFade);
		nextObj=which;
		nextIo=io;
		nextFade=setTimeout('fadeMapNow(nextObj,nextIo)',1000)
	}else{
		fadeMapNow(which,io);
	}
}
function fadeMapNow(which,io){
	fadeStatus="busy";
	if($(which)&&io=='in'){
		fx = new Fx.Style($(which), 'opacity', {duration: 500, wait: false}).set(0);
		$(which).setStyle("z-index",'2');
		fx.start(0,1).chain(function() {
					$(which).setStyle("z-index",'3');
					$$('.hiddenMap').each(function(el){
						if(el!=$(which)){
							el.setStyle("z-index",'-1');
						}					
					})
	
				});
	}
	if($(which)&&io=='out'){
		fx = new Fx.Style($(which), 'opacity', {duration: 500, wait: false})
		fx.start(1,0).chain(function() {
					$(which).setStyle("z-index",'-1');
					clearTimeout(nextFade);
					if (nextObj!="")fadeMapNow(nextObj,nextIo);
					nextObj="";
					nextIo="";
				});
		
	}
}


//START: Expanding flash DIV's 
// The class name of toggle objects which will be initially hidden
var toggleDivClassName = "toggle";
// This controls how slowly the div initially starts moving.
// Lower values case a slower initial move speed. Must be > 1
var toggleDivSpeedMultiplier = 1.2;
// The delay between each move. 
var toggleDivDelay = 1;	
var toggleDivOnlyOneOpen = false;
var toggleDivs = new Array();
var togglingDivs = new Object();


// The initial function that handles the request to toggle a DIV
function toggleDiv(divId) {
	//alert("toggleDiv delay: "+toggleDivDelay+"......"+toggleDivSpeedMultiplier);
	var divId = "flashcontent";
	var d = document.getElementById("flashcontent");
	var action = "open";
	if (d==null || d.tagName!="DIV" || !d.offsetHeight || togglingDivs[divId]) { 
		return;
	}
	d.style.overflow = "hidden";
	if (action=="open" || (typeof(action)=="undefined" && d.style.visibility=="hidden")) {
		var originalHeight = d.offsetHeight;
		var height = 1;
		//d.style.height = height+"px";
		d.style.visibility = "visible";
		d.style.position="static";
		setTimeout("toggleObject('"+divId+"','open',"+originalHeight+","+height+")",toggleDivDelay);
	}
	else if (action=="close" || (typeof(action)=="undefined" && d.style.visibility=="visible")) {
		// close it
		var originalHeight = d.style.height;
		var height = originalHeight;
		togglingDivs[divId] = true;
		setTimeout("toggleObject('"+divId+"','close',"+350+","+600+")",toggleDivDelay);
	}	
}

// The function that is called repeatedly until the toggle is done
function toggleObject(divId, openClose, originalHeight, height) { 
var d = document.getElementById(divId);
	if (d==null || d.tagName!="DIV") { return; }

	if (openClose=="open") {
		height = height * toggleDivSpeedMultiplier;
		if (originalHeight+height > 320) {
			delete togglingDivs[divId];
		}
		else {
			//alert("expand height")+height;
			d.style.height = (originalHeight-15)+height+"px";
			setTimeout("toggleObject('"+divId+"','"+openClose+"',"+originalHeight+","+height+")",toggleDivDelay);
		}
	}
	else {
		height = height * (1/toggleDivSpeedMultiplier);
		if (height <= 1) {
			d.style.position = "absolute";
			d.style.visibility = "hidden";
			d.style.height = originalHeight+"px";
			delete togglingDivs[divId];
		}
		else {
			d.style.height = height+"px";
			setTimeout("toggleObject('"+divId+"','"+openClose+"',"+originalHeight+","+height+")",toggleDivDelay);
		}
	}
}	
// END:Expanding flash DIV's 


window.addEvent('domready',initSearchBox)
//window.addEvent('domready',initResultsTabs)
function expandSearch(selected){
		var containedDivs = $$('.selectOptions');
		for(i=0; i<= (containedDivs.length-1); i++){
			document.getElementById(containedDivs[i].id).style.display = 'none';
		}
		if(selected != "1all"){
			document.getElementById(selected).style.display = 'block';
		}
}

//Offer Listing page, select offers
function selectOffer(offerType, optKeywords, onlyHotOffers){
		baseURL = document.domain;
		url = "http://"+baseURL+offerType+"?ho="+onlyHotOffers+"&q="+optKeywords
		window.location = url;
}

//Global popup function
function popupTI(URL, popupWidth, popupHeight){
	window.open (URL,"TI_window","menubar=0,resizable=0,width=eval(popupWidth),height=eval(popupHeight)");
}


//window.addEvent('domready', function() { populate() );
window.addEvent('domready',populate);

function populate(){
	if($('selectLocation')){
		$('selectLocation').addEvent('change', function(){
			var optList = $('optionalLists');
			var selectedIndex = (this.selectedIndex)-1;
			optionalArea = optList.getElementsByTagName('td')[0];
			//alert('optAres'+optionalArea+'    selectedIndex: '+ selectedIndex);
			if (selectedIndex != -1){
				optList.style.visibility = 'visible';
				var drop = document.createElement('select');
				var option = document.createElement('option');			
				optionalArea.innerHTML="";
				drop.style.width="174px";
				for (i=0; i<=(locations[selectedIndex].length)-1; i=i+3){
						//alert(locations[0][i]);
						//alert(locations[selectedIndex][i+1]);
						var optionText = document.createTextNode(locations[selectedIndex][i+1]);
						var option = document.createElement('option');
						option.appendChild(optionText);
						option.value = (locations[selectedIndex][i]);
						if (locations[selectedIndex][i+2] == '1'){						
								option.selected = 'selected';							
								var locationParent = this.selectedIndex;
								var locationChild = (i/3)+1;
						}
						drop.appendChild(option);
						drop.id = 'l';
						drop.name = 'l';						
						optionalArea.appendChild(drop);
				}
				//alert(locationChild);
				//alert($('l').getSelectedIndex);
			}
			else{optionalArea.innerHTML="<span><select id='l' name='l'><option>All Ireland</option></select></span>";}
		});
		/* START Prepouplate the dropdowns if any location parameter is passed */
		if($('selectLocation')){
			if(locationsSelectedIndex > 0){
				var optList = $('optionalLists')
				//var selectedIndex = ($('selectLocation').selectedIndex)-1;
				var selectedIndex = locationsSelectedIndex;
				optionalArea = optList.getElementsByTagName('td')[0];
					optList.style.visibility = 'visible';
					var drop = document.createElement('select');
					var option = document.createElement('option');			
					optionalArea.innerHTML="";
					drop.style.width="174px";
					for (i=0; i<=(locations[selectedIndex-1].length)-1; i=i+3){
							var optionText = document.createTextNode(locations[selectedIndex-1][i+1]);
							var option = document.createElement('option');
							option.appendChild(optionText);
							option.value = (locations[selectedIndex-1][i]);
							if (locations[selectedIndex-1][i+2] == '1'){						
									option.selected = 'selected';							
									var locationParent = this.selectedIndex;
									var locationChild = (i/3)+1;
							}
							drop.appendChild(option);
							drop.id = 'l';
							drop.name = 'l';						
							optionalArea.appendChild(drop);
							$('selectLocation')[selectedIndex].selected = true;
					}
			}
		}
		/* START Prepouplate the dropdowns if any location parameter is passed */		
		
	}
	if($('defineType')){
		$('defineType').addEvent('change', function(){
			var optList = $('optionalLists');
			var selectedIndex = (this.selectedIndex)-1;
			optionalArea = optList.getElementsByTagName('td')[1];
			if (selectedIndex != -1){
				optList.style.visibility = 'visible';
				var drop = document.createElement('select');
				var option = document.createElement('option');			
				optionalArea.innerHTML="";
				drop.style.width="155px";
				for (i=0; i<=(types[selectedIndex].length)-1; i++){
						//alert(locations[0][i]);
						var optionText = document.createTextNode(types[selectedIndex][i]);
						var option = document.createElement('option');
						option.appendChild(optionText);
						option.value = i;
						drop.appendChild(option);
						optionalArea.appendChild(drop);

				}
			}
			else{optionalArea.innerHTML="";}
		});
	}	
}


		
/* Calendar Date validator */
	function vaidateDate(){
		d1 = $('date_from').value;
		d2 = $('date_to').value;
		
		var fD = d1.substring(0,2);
		var fM = d1.substring(3,5);
		var fY = d1.substring(6,10);
		
		var tD = d2.substring(0,2);
		var tM = d2.substring(3,5);
		var tY = d2.substring(6,10);	
		var fMDY = new Date(fM + '/' + fD + '/' + fY);
		var tMDY = new Date(tM + '/' + tD + '/' + tY);
		//alert(fMDY+"\n"+tMDY);
		if(fMDY > tMDY){$('date_to').value = "";alert("Invalid 'From' OR 'To' Date(s) \nPlease Select again");}
	}

//Ajax function
function ajx(link, eID, method, loader) {this.link=link;this.eID=eID;this.method=method;if (loader){this.loader=loader}}
ajx.prototype.form = null;
ajx.prototype.complete = function() { };
ajx.prototype.run = function() {
	var xmlHttp;
	var eID = this.eID;
	var loader = this.loader;
	var fn = this.complete;
	if (!$(eID)) { return false; }
	if (loader==true) { 
		if ($('ajxLoader')) { $('ajxLoader').style.display = 'block'; } 
	}
	try {  
		// Firefox, Opera 8.0+, Safari  
		xmlHttp=new XMLHttpRequest();  
	}
	catch (e) {  
		// Internet Explorer  
		try {    
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
		}
		catch (e) {    
			try {      
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
			}
			catch (e) {   
				return false;      
			}    
		}  
	} 
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			$(eID).innerHTML=xmlHttp.responseText;
			if (typeof fn == "function") {
				if (loader==true) { if ($('ajxLoader')) { $('ajxLoader').style.display = 'none'; } }		
				fn();
			}
			attachWebtrends();
		}
	} 
	xmlHttp.open(this.method,this.link,true);
	if (this.form && this.form!='') {
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		try {
			var q = new ajxfrmQ(this.form);
		}
		catch (e) { 
			return false; 
		}
		xmlHttp.send(q.string);
		return true;
	}
	xmlHttp.send(null);																
	return true;
}
function ajxfrmQ(frm) {
	var form = document.forms[frm];
	var qstr="";
	for(i=0; i<form.elements.length; i++) {
		if(form.elements[i].type=="hidden") {
			if(qstr.length>0) {
				qstr = qstr + '&' + form.elements[i].name + '=' + form.elements[i].value
			}
			else {
				qstr = form.elements[i].name + '=' + form.elements[i].value
			}
		}
	}
	this.string = qstr;	
}

function feedback_form(link){
		if($('feedback_form').style.display != 'block'){
			$('feedback_form').style.display = 'block';
			$('vlDoc').value = link;			
			$('confirmation').value = link;
			$('vl').href = link;
			// $('vl').title = 'testing';
			$('vl').title = this.title;
			//$$("div.tabs_content_scroll")[0].setAttribute('style','overflow: hidden');
			return false;
		}
		else{
			$('feedback_form').style.display = 'none';
			//$$("div.tabs_content_scroll")[0].setAttribute('style','overflow-y: scroll');
		}
		return false;
}

function feedback_form2(link, title){
		if($('feedback_form').style.display != 'block'){
			$('feedback_form').style.display = 'block';
			// $('vlDoc').value = link;
			if(link.charAt(link.length-1) != "/"){
				link = link + "/";
			}
			
			if(title != null){
			title = title.trim();
			}
			$('vlDoc').value = link + '\t' + title;
			// $('confirmation').value = link;
			$('confirmation').value = link + '\t' + title;
			$('vl').href = link;
			var vlTitle = title.replace(/\s/g,'').toLowerCase();
			$('vl').title = link + '\t' + vlTitle;
			//$$("div.tabs_content_scroll")[0].setAttribute('style','overflow: hidden');
			return false;
		}
		else{
			$('feedback_form').style.display = 'none';
			//$$("div.tabs_content_scroll")[0].setAttribute('style','overflow-y: scroll');
		}
		return false;
}

function download_dialog(link){
		if($('download_dialog').style.display != 'block'){
			$('download_dialog').style.display = 'block';
			$('download').href = link.split('\t')[0];
			$('download').title = link.split('\t')[1].replace(/\s/g,'').toLowerCase();
		}
		else{$('download_dialog').style.display = 'none';}
	
}

function optional_select(which){
		$('mcTILiterature').style.display = "none";
		$('mcRadio').style.display = "none";
		$('mcTV').style.display = "none";
		$('mcFriendRelative').style.display = "none"; 					
		if (which != "PleaseSelect") {
			$(which).style.display = "block";
		}
	}

