/* Default functions
 * --------------------------------------------------------------
 * www.nichtswieweg.ch
 * Version 0.1
 */

function OpenEmailLink(var1, var2) {
	location.href = 'ma' + 'il' + 'to' + ':' + var1 + '@' + var2;
}

function RollOver(obj) {
	if (obj.src) {
		var length = obj.src.length;
		var status = obj.src.substring(length-5, length-4);
		
		obj.src = obj.src.substring(0, length-5) + (status == 0 ? 1 : 0) + obj.src.substring(length-4, length);    
	}
}

function ToolbarButton(str) {
	switch (str) {
		case "print":
			var _client = document.getElementById('client').value;
			var _idart  = document.getElementById('idart').value;
			var _idcat  = document.getElementById('idcat').value;
			var _lang   = document.getElementById('lang').value;
			window.open('front_content.php?idart=265&idcat=37&lang=1&_client='+_client+'&_idart='+_idart+'&_idcat='+_idcat+'&_lang='+_lang);
			break;
		case "send_a_friend":
			location.href = "mailto:?subject=Interessanter Link gefunden!&body=Ein interessanter Link zum Thema Reisen: " + location.href;
			break;
		case "zoom_in":
            		ChangeFontsize(1);
			break;
		case "zoom_out":
            		ChangeFontsize(-1);
			break;
	}
}

var changedFontSize = 0;
function ChangeFontsize(increment) {
	changedFontSize += increment;
	SetCookie("fontSize", changedFontSize);

	var getElement = document.getElementsByTagName("td");
  	for (var i=0; i < getElement.length; i++) {
    		var eachElement = getElement[i];
		if (document.defaultView) {	
      			var currentFontSize = document.defaultView.getComputedStyle(eachElement, null).getPropertyValue("font-size");   
    		} else {
			if (eachElement.currentStyle) {	
      				var currentFontSize = eachElement.currentStyle.fontSize;
			}
		}
	
		var currFontSize = parseInt(currentFontSize, 10);
		var fontIncrease = parseInt(increment, 10);
	
		newFontSize = currFontSize + fontIncrease;
    		eachElement.style.fontSize = newFontSize + "px";

  	}	

	if (changedFontSize == 0) {
		DeleteCookie("fontSize");
	}
}

function RenderPNG(src, height, width, alt) {
	if (navigator.appVersion.indexOf("MSIE") != -1) {
		document.write("<img alt='"+alt+"' border=0 src=images/dot.gif style=width:"+width+"px;height:"+height+"px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+src+",sizingMethod='scale')/>");
	} else {
		document.write("<img alt='"+alt+"' src="+src+" style=width:"+width+"px;height:"+height+"px; border=0>");
	}
}

function Trim(s) {
  	// Remove leading spaces and carriage returns
  	while ((s.substring(0,1) == ' ' ) || 
	 	   (s.substring(0,1) == '\n') || 
		   (s.substring(0,1) == '\r')) {
		s = s.substring(1,s.length);
  	}

  	// Remove trailing spaces and carriage returns
  	while ((s.substring(s.length-1,s.length) == ' ') || 
		   (s.substring(s.length-1,s.length) == '\n') || 
		   (s.substring(s.length-1,s.length) == '\r')) {
    	s = s.substring(0,s.length-1);
	}
  	return s;
}

function SetCookie(name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
}

function GetCookie(name) {
    	var dc = document.cookie;
   	var prefix = name + "=";
    	var begin = dc.indexOf("; " + prefix);
    
	if (begin == -1) {
        	begin = dc.indexOf(prefix);
        	if (begin != 0) return null;
    	} else {
        	begin += 2;
    	}
    
	var end = document.cookie.indexOf(";", begin);
    	if (end == -1) {
        	end = dc.length;
    	}
    	return unescape(dc.substring(begin + prefix.length, end));
}

function DeleteCookie(name, path, domain) {
	if (GetCookie(name)) {
        	document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") +  "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function Popup(url, width, height) {
	window.open(url, '_blank', 'width=' + width + ', height=' + height + ', left=' + Math.round((screen.width - width)/2) + ', top=' + Math.round((screen.height - height)/4) + ', location=0, statusbar=0, menubar=0, toolbar=0, scrollbars=0, resizable=no');
}

function Init() {
	// Start the slide show
	StartSlideShow();

	// Set the font size
	if (GetCookie("fontSize")) {
		ChangeFontsize(parseInt(GetCookie("fontSize")));
	}
}