/*
JSTarget function by Roger Johansson, www.456bereastreet.com

Modified by Creuna to suit the site
*/
var JSTarget = {
	init: function(att,val,warning,appendWarning,popup) {
		if (document.getElementById && document.createElement && document.appendChild) {
			var strAtt = ((typeof att == 'undefined') || (att == null)) ? 'class' : att;
			var strVal = ((typeof val == 'undefined') || (val == null)) ? 'non-html' : val;
			var strWarning = ((typeof warning == 'undefined') || (warning == null)) ? ' (opens in a new window)' : warning;
			var boolAppendWarning = ((typeof appendWarning == 'undefined') || (appendWarning == null)) ? false : appendWarning;
			var boolPopup = ((typeof popup == 'undefined') || (popup == null)) ? false : popup;
			var oWarning;
			var arrLinks = document.getElementsByTagName('a');
			var oLink;
			var oRegExp = new RegExp("(^|\\s)" + strVal + "(\\s|$)");
			for (var i = 0; i < arrLinks.length; i++) {
				oLink = arrLinks[i];
				if ((strAtt == 'class') && (oRegExp.test(oLink.className)) || (oRegExp.test(oLink.getAttribute(strAtt)))) {
				    if(boolAppendWarning){
					    oWarning = document.createElement("em");
					    oWarning.appendChild(document.createTextNode(strWarning));
					    oLink.appendChild(oWarning);
					}else{
					    //oLink.title = strWarning;
					}
					oLink.onclick = JSTarget.openWin;
				}
			}
			oWarning = null;
		}
	},
	openWin: function(e) {
	    var popup = false;
		var event = (!e) ? window.event : e;
		if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) return true;
		else {
		    if(!popup){
		        //var oWin = window.open(this.getAttribute('href'), '_blank');
		        var oWin = window.open(this.getAttribute('href'), 'popup', 'width=680,height=400,scrollbars=yes');
		    }else{
		        var oWin = window.open(this.getAttribute('href'), '_blank');
		    }
			if (oWin) {
				if (oWin.focus) oWin.focus();
				return false;
			}
			oWin = null;
			return true;
		}
	}
};

JSEvent.addEvent(window, 'load', function(){JSTarget.init();});

var JSOpenUrlFromDropDown = {
	init: function(cssSelector) {
	    jQuery.noConflict();		
	    jQuery(document).ready(function() {
	        var objSelect = jQuery(cssSelector).lt(1);
	        jQuery(objSelect).change(JSOpenUrlFromDropDown.OpenWin);
        });
    },
    OpenWin: function(e) {
        if(this.selectedIndex != 0){
            var oWin = window.open(this.options[this.selectedIndex].value, 'blank');
        }
        if (oWin) {
			if (oWin.focus) oWin.focus();
			return false;
		}
		oWin = null;
		return true;
    }
};

JSEvent.addEvent(window, 'load', function(){JSOpenUrlFromDropDown.init(".choosecountry-portlet select");});
