Date.prototype.format = function(format) // author: vincent
{
	var o = {
		"M+" : this.getMonth() + 1, // month
		"d+" : this.getDate(), // day
		"h+" : this.getHours(), // hour
		"m+" : this.getMinutes(), // minute
		"s+" : this.getSeconds(), // second
		"q+" : Math.floor((this.getMonth() + 3) / 3), // quarter
		"S" : this.getMilliseconds()
			// millisecond
	}
	if (/(y+)/.test(format))
		format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4
				- RegExp.$1.length));
	for (var k in o)
		if (new RegExp("(" + k + ")").test(format))
			format = format.replace(RegExp.$1, RegExp.$1.length == 1
					? o[k]
					: ("00" + o[k]).substr(("" + o[k]).length));
	return format;
}

var tgs = new Array('div', 'td', 'tr');
var szs = new Array('xx-small', 'x-small', 'small', 'medium', 'large',
		'x-large', 'xx-large');
var startSz = 2;
/**
 * 
 */
function changeFontSize(trgt, inc) {
	if (!document.getElementById)
		return
	var d = document, cEl = null, sz = startSz, i, j, cTags;
	sz += inc;
	if (sz < 0)
		sz = 0;
	if (sz > 6)
		sz = 6;
	startSz = sz;
	if (cEl = d.getElementById(trgt)) // cEl = d.getElementsByTagName( trgt )[
		// 0 ];
		cEl.style.fontSize = szs[sz];
	/*
	 * for ( i = 0 ; i < tgs.length ; i++ ) { cTags = cEl.getElementsByTagName(
	 * tgs[ i ] ); for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j
	 * ].style.fontSize = szs[ sz ];
	 */

	compareHeight();
}

var printContent;
function printContent(id, url) {
	document.getElementById("printDate").innerHTML = new Date()
			.format("dd.MM.yyyy");
	this.printContent = document.getElementById(id).innerHTML;
	window.open(url);
	return;
}

function searchSubmit(id) {

	var form = document.getElementById("searchLeft");
	form.submit();
}

function globalMap(language) {
	if (document.getElementById("globalMap")) {
		var indexflashNav = new SWFObject(ctx + "/images/" + language
				+ "/swfs/globalMap_" + language + ".swf", "Allianz Global",
				"148", "100", "9", "wmode");
		indexflashNav.addParam("wmode", "transparent");
		indexflashNav.addVariable("xmlPath", ctx + "/");
		indexflashNav.addVariable("flashVarText", "");
		indexflashNav.write("globalMap");
	}
}
function homeBanner(language) {
	if (document.getElementById("homeBanner")) {
		var indexflashNav = new SWFObject(ctx + "/images/" + language
				+ "/swfs/homeBanner_" + language + ".swf", "Allianz Banner",
				"654", "133", "9", "wmode");
		indexflashNav.addParam("wmode", "transparent");
		indexflashNav.addVariable("flashVarText", "");
		indexflashNav.write("homeBanner");
	}

}

function externallinks() {
	$('a[@rel=external]').each(function() {
		$(this).attr('target', '_blank');
	})
}

function sendMailForm() {
	var name = document.getElementById("name").value;
	var address = document.getElementById("address").value;
	var eMail = document.getElementById("eMail").value;
	var tel = document.getElementById("tel").value;
	if (name == null || name == '') {
		alert("Name is Require");
		return false;
	}
	if (address == null || address == '') {
		alert("Address is Require");
		return false;
	}
	if (eMail == null || eMail == '') {
		alert("E-Mail is Require");
		return false;
	}
	if (tel == null || tel == '') {
		alert("Tel is Require");
		return false;
	}
	document.getElementById("mailForm").submit();
	return true;
}

function isFirstComplaint(isFirst) {
	if (isFirst == '0') {
		document.getElementById("isFirst").style.display = "";
	}
	if (isFirst == '1') {
		document.getElementById("isFirst").style.display = "none";
	}
}
function isComplaint(value) {
	if (value == '1') {
		document.getElementById("isComplaint").style.display = "";
	} else {
		document.getElementById("isComplaint").style.display = "none";
		document.getElementById("isFirst").style.display = "none";
	}
}
function changeLink(link) {
	if (link != '') {
		window.open(link);
	}
}

function autoHeight() {

	if (document.getElementById("products")
			&& document.getElementById("customerCenter")
			&& document.getElementById("eService")
			&& document.getElementById("news")) {

		if ($("#products").height() - $("#customerCenter").height() > 0) {
			$("#customerCenter").height($("#products").height());
		} else {
			$("#products").height($("#customerCenter").height());
		}

		if (($("#news").height() - $("#eService").height()) > 14) {
			$("#eService").height($("#news").height() + 14);
		} else {
			$("#news").height($("#eService").height() - 14);
		}
	}
}

String.prototype.mylength = function() {
	var arr = this.match(/[\u00FF-\uFFFF]/gi);
	if (!arr || arr == null)
		return this.length;
	var len = this.length + arr.length;
	return len;
}
String.prototype.mysubstring = function(limit) {
	var len = 0;
	var arr = [];
	for (var i = 0; i < this.length; i++) {
		var it = this.substring(i, i + 1);
		len += it.mylength();
		if (len > limit)
			break;
		arr[arr.length] = it;
	}
	var result = arr.join("");
	return result;
}

jQuery.fn.limit = function() {
	$(this).each(function() {

		var mylimit = parseInt($(this).attr("name"));
		var applied = $(this).attr("applied");
		if (applied)
			return;
		var text = $(this).text();
		var original_text = text;
		if (text.mylength() > mylimit) {
			text = text.mysubstring(mylimit);
			text += "...";
			// text = "<SPAN style=\"position:relative\"><SPAN class='tooltip'>"
			// + original_text + "</SPAN>" + text + "</SPAN>";
			$(this).html(text);
			// $(this).mouseover(function(){
			// $(this).find(".tooltip").css("display","");
			// });
			// $(this).mouseout(function(){
			// $(this).find(".tooltip").css("display","none");
			// });
			// $(this).find(".tooltip")
			// .css({ 'display':'block',
			// 'position':'absolute',
			// 'top':'2em',
			// 'left':'2em',
			// 'width':'15em',
			// 'border':'1px solid #0cf',
			// 'background-color':'#cff',
			// 'color':'#000',
			// 'text-align':'center',
			// 'word-wrap':'break-word',
			// 'word-break':'break-all'})
			// .css("display","none");
			$(this).attr("applied", true);
		}

	});
}

function turnLang() {
	$("#sitePath").val(window.location.href);
	document.getElementById('navigationAreaForm').submit();
}

function compareHeight() {
	var navigationArea = $("#navigationArea");
	var contentArea = $("#contentArea");
	var relatedArea = $("#relatedArea");
	var navigationAreaHeight = navigationArea.attr("clientHeight");
	var contentAreaHeight = contentArea.attr("clientHeight");
	var relatedAreaHeight = relatedArea.attr("clientHeight");
	var maxHeight;
	contentArea.height("");
	if (navigationAreaHeight <= contentAreaHeight) {
		maxHeight = contentAreaHeight;

		if (contentAreaHeight <= relatedAreaHeight) {
			maxHeight = relatedAreaHeight;
		}
	} else if (navigationAreaHeight <= relatedAreaHeight) {
		maxHeight = relatedAreaHeight;
	} else {
		maxHeight = navigationAreaHeight;
	}

	if (contentAreaHeight == maxHeight) {
		return;
	}

	// alert(maxHeight);
	contentArea.height(maxHeight);
	// alert(document.getElementById("contentArea").style.height);
}

$(document).ready(function() {
	// var nowDate = new Date();
	// var month = nowDate.getMonth() + 1;
	// var translateDate = nowDate.getFullYear() + "/" + month + "/" +
	// nowDate.getDate();
	// nowDate = new Date(translateDate);
	// $('.date').each(function(i){
	// var temp = $(this).text();
	// var newsDate = new Date(temp.replace("-", "/").replace("-", "/"));
	// nowDate = nowDate.valueOf();
	// newsDate = newsDate.valueOf();
	// var tempDate = nowDate - newsDate;
	// if(tempDate <= 30 * 24 * 60 * 60 * 1000){
	// $("img[name='"+temp+"']").css("display","inline");
	// }
	// });
	var date = new Date();
	$(".copyright").each(function(){
		$(this).html($(this).html().replace("2009",date.getFullYear()));
	});
	$("img[name='topNews1']").each(function(i) {
		$(this).css("display", "inline");
	});
});