col_png = new Array();
png_sources = new Object();
browser = '';
gallery_popup_image_default_width = 0;
gallery_popup_image_default_height = 0;
window.onload = js_onload;
window.onresize = js_resize;
js_init();

function js_init() {
	
	js_getbrowser();
	
	if (browser == 'IE'){
		document.styleSheets[3].href=commonpath + '/common/css/ie.css';	
	}
	
}

function js_getbrowser(){
	if (navigator.appVersion.toLowerCase().indexOf('msie') != -1){
		browser = 'IE';
	}
}

function js_onload(){

	if (browser == 'IE'){
		js_pnginit();
	}

	if (iam_popup){
		if (iam_gallery){
			obj_gallery_popup_image = document.getElementById('gallery_popup_image');
			gallery_popup_image_default_width = obj_gallery_popup_image.offsetWidth;
			gallery_popup_image_default_height = obj_gallery_popup_image.offsetHeight;
		}
	}
	else{
		
	}

	js_resize();
}


//Seite aufgrund der Auflsung anpassen
function js_resize() {
	if (iam_popup){
		if (iam_gallery){
			obj_container_gallery_popup_image = document.getElementById('container_gallery_popup_image');
			obj_gallery_popup_image = document.getElementById('gallery_popup_image');
			if (document.body.offsetWidth<gallery_popup_image_default_width || document.body.offsetHeight<gallery_popup_image_default_height){
				if (document.body.offsetWidth<gallery_popup_image_default_width){
					obj_gallery_popup_image.style.width = '100%';
					obj_gallery_popup_image.style.height = 'auto';
				}
				
				if (document.body.offsetHeight<obj_gallery_popup_image.offsetHeight){
					obj_gallery_popup_image.style.width = 'auto';
					obj_gallery_popup_image.style.height = '100%';
				}
			}
			else{
				obj_gallery_popup_image.style.width = 'auto';
				obj_gallery_popup_image.style.height = 'auto';
			}
			if (document.body.offsetHeight>obj_gallery_popup_image.offsetHeight){
				obj_gallery_popup_image.style.marginTop = (document.body.offsetHeight-obj_gallery_popup_image.offsetHeight)/2 + 'px';
			}
			else {
				obj_gallery_popup_image.style.marginTop = 'auto';
			}
		}
	}
	else{
		
	}
}


function js_pnginit(){
	
	for (i=0;i<col_png.length;i++){
		obj_png = document.getElementById(col_png[i]);
		png_sources[col_png[i]] = obj_png.src;
		if (col_png[i]!='navimg_active_bg'){
			if (obj_png.style.width==''){
				obj_png.style.width = obj_png.offsetWidth;
			}
			if (obj_png.style.height==''){
				obj_png.style.height = obj_png.offsetHeight;
			}
		}
		obj_png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + obj_png.src + "',sizingMethod='scale')";
		obj_png.src = commonpath + '/images/layout/blank.gif';
	}
}

function js_check_if_blankgif(file) {
	if (file.indexOf('blank.gif')>=0){
		return true;
	}
	return false;
}

function js_imgover(obj){
	file = obj.src;
	if (browser=='IE' && js_check_if_blankgif(file)){
		file = png_sources[obj.id];
		dot_pos = file.lastIndexOf('.');
		file_ext = file.substr(dot_pos);
		if (file.indexOf('2' + file_ext)>=0){
			tmp_img = file.replace('2' + file_ext,file_ext);
		}
		else{
			tmp_img = file.replace(file_ext,'2'+file_ext);
		}
		obj.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + tmp_img + "',sizingMethod='scale')";
	}
	else{
		dot_pos = file.lastIndexOf('.');
		file_ext = file.substr(dot_pos);
		tmp_img= new Image();
		if (file.indexOf('2' + file_ext)>=0){
			tmp_img.src = file.replace('2' + file_ext,file_ext);
		}
		else{
			tmp_img.src = file.replace(file_ext,'2'+file_ext);
		}
		obj.src = tmp_img.src;
	}
}

function js_imgout(obj){
	file = obj.src;
	if (browser=='IE' && js_check_if_blankgif(file)){
		file = png_sources[obj.id];
		dot_pos = file.lastIndexOf('.');
		file_ext = file.substr(dot_pos);
		if (file.indexOf('2' + file_ext)>=0){
			tmp_img = file;
		}
		else{
			tmp_img = file.replace('2' + file_ext,file_ext);
		}
		obj.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + tmp_img + "',sizingMethod='scale')";
	}
	else{
		dot_pos = file.lastIndexOf('.');
		file_ext = file.substr(dot_pos);
		tmp_img= new Image();
		if (file.indexOf('2' + file_ext)==-1){
			tmp_img.src = file.replace(file_ext,'2' + file_ext);
		}
		else{
			tmp_img.src = file.replace('2' + file_ext,file_ext);
		}
		obj.src = tmp_img.src;
	}
}

function js_trim(string) {
	return string.replace(/^\s*|\s*$/,'');
}

function js_checkEmail(field) {
	if (field.value) {
		var usr = "([a-zA-Z0-9][a-zA-Z0-9_.-]*|\"([^\\\\\x80-\xff\015\012\"]|\\\\[^\x80-\xff])+\")";
		var domain = "([a-zA-Z0-9][a-zA-Z0-9._-]*\\.)*[a-zA-Z0-9][a-zA-Z0-9._-]*\\.[a-zA-Z]{2,5}";
		var regex = "^"+usr+"\@"+domain+"$";
		var myrxp = new RegExp(regex);
		var check = (myrxp.test(field.value));
		if (check!=true) {
			return false;
		}
		else {
			return true;
		}
	}
}

function js_gallery_popup(popup_url,gallery,image){
	max_width = 1200;
	max_height = 1000;
	width = screen.availWidth-100;
	height = screen.availHeight-100;
	if (width>max_width){
		width = max_width;
	}
	if (height>max_height){
		height = max_height;
	}
	window.open(popup_url + '?gallery=' + gallery + '&image=' + image,'','location=no,menubar=no,resizable=yes,status=no,toolbar=no,scrollbars=yes,width=' + width + ',height=' + height);
}