/**
* Globale JavaScript Funktionen
* 
* @version 1.0
* @author Tiscover Webfactory <office@tiscover.com>
*/


/**
 * Checkt ein Formularfeld auf ! empty
 * 
 * @param obj feld  Formular-Feld
 * @param str message  Fehler-Nachricht
 * 
 * @return bool
 */
function xxlCheckEmpty(feld, message) {
	if (feld.value == '') {
		alert (message);
		feld.focus();
		return false;
	}
}

/**
 * Checkt, ob ein Formularfeld eine korrekte e-mail-Adresse ist
 * 
 * @param obj feld  Formular-Feld
 * @param str message  Fehler-Nachricht
 * 
 * @return bool
 */
function xxlCheckEmail(feld, message) {
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(feld.value) == false) {
		alert (message);
		feld.focus();
		return false;
	}
	return true;
}


function showimage(id,url,title)
{
	document.getElementById("id_img_big_"+id).src=url;
	
	
	if(document.getElementById("img_text_"+id).firstChild == null)
	{
		var myimgtext = document.createTextNode(title);
		document.getElementById("img_text_"+id).appendChild(myimgtext);

	}
	
	document.getElementById("img_text_"+id).firstChild.nodeValue=title;
	
	return false;
}




function sendAjaxRequest(link,target)
{
	var url = '/proxy?url=' + encodeURIComponent(link);
	

	new Ajax.Updater(target,link, {
	  method: 'get',
	  onSuccess: function(transport)
	  {
	    var notice = $('notice');
	    if(transport.responseText != "error")
		{		
			//$('xxlAjaxContent').setStyle({'display': 'inline'});
			//$('xxlLoadingImg').setStyle({'display': 'none'});
			var browser = navigator.userAgent;
			if(browser.search(/Opera/) == -1 && browser.search(/MSIE/) != -1 ){
			    correctPNG();
			}
			new Effect.Morph('xxlOffer', {
			style: 'width:680px',
			duration: 3.0
			
			});
	
	
		}
	  
	  }
	  
	});
}

function myAjaxRequest(link,target)
{
	//$('xxlOffer').setStyle({'display': 'none'});
	//$('xxlLoadingImg').setStyle({'display': 'inline'});
	sendAjaxRequest(link,target)
	/*new Effect.Morph('xxlOffer', {
			style: 'width:0px',
			duration: 3.0
			//afterFinish: sendAjaxRequest(link)
		});*/

	
	
	
	
	return false;
}

function hideCatalogBtn(obj) {
	$(obj.element.id.replace("addBtn", "addBtnDiv")).style.display = 'none';
}


emkbig = 0;

function setEmkBig(val)
{
	emkbig = 1;
}

function addOffer(id, isDetail) {
	var myappear1 = function(obj)
	{
		$('addBtnLink'+id).style.display = 'none';
		$(obj.element.id.replace("addBtnDivD", "removeBtnD")).style.opacity = '1';
		$(obj.element.id.replace("addBtn", "removeBtn")).style.opacity = '0';
		$(obj.element.id.replace("addBtn", "removeBtn")).style.display = 'inline';
		
		new Effect.Appear($(obj.element.id.replace("addBtn", "removeBtn")))
	};
	
	if(isDetail)
	{
		var linkCart = $('addBtnLinkD'+id);
		$('removeBtnDivD'+id).style.opacity = '0';
		$('removeBtnDivD'+id).style.display = 'inline';
		$('removeBtnD'+id).style.height = '28px';
		$('removeBtnD'+id).style.width = '139px';
		new Effect.Fade($('addBtnDivD'+id), {afterFinish:myappear1});
		$('addBtnLink'+id).style.display = 'none';
		$('removeBtnLink'+id).style.display = 'inline';
	}
	else
	{
		var linkCart = $('addBtnLink'+id);
		Position.absolutize($('addBtn' + id));
		var positionCart = Position.cumulativeOffset($('inqManagerImg'));
		
		myappear = function(obj)
		{
			$('addBtnLink'+id).style.display = 'none';
			$(obj.element.id.replace("addBtn", "removeBtn")).style.opacity = '1';
			$(obj.element.id.replace("addBtn", "removeBtnLink")).style.display = 'inline';
			new Effect.Appear($(obj.element.id.replace("addBtn", "removeBtn")))
		};
		
		
		new Effect.Morph('addBtn' + id, {
											style: 'top:'+positionCart[1]+'px;left:'+positionCart[0]+'px;opacity:0;',
											afterFinish: myappear
										}
						);
		
		var onSuccess = function(transport) {
							//eval("var responseJSON = " + transport.responseText + ";");
							//$('cartCountTop').update(responseJSON.count);
							//$('cartCountBottom').update(responseJSON.count);
						}
	}
	
	new Ajax.Updater( 'xxlInqList',linkCart.href, {
							method: 'get'
						}
					);
	
}



function removeOffer(id,isDetail) {
	
	//Position.absolutize($('removeBtn' + id));
	
	var myappear1 = function(obj)
	{
		$('removeBtnLink'+id).style.display = 'none';
		$(obj.element.id.replace("removeBtnDivD", "addBtnD")).style.opacity = '1';
		$(obj.element.id.replace("removeBtn", "addBtn")).style.opacity = '0';
		$(obj.element.id.replace("removeBtn", "addBtn")).style.display = 'inline';
		new Effect.Appear($(obj.element.id.replace("removeBtn", "addBtn")))
		
	};
	
	if(isDetail)
	{
		var linkCart = $('removeBtnLinkD'+id);
		$('addBtnDivD'+id).style.opacity = '0';
		$('addBtnDivD'+id).style.display = 'inline';
		$('addBtnD'+id).style.height = '28px';
		$('addBtnD'+id).style.width = '155px';
		new Effect.Fade($('removeBtnDivD'+id), {afterFinish:myappear1});
		$('removeBtnLink'+id).style.display = 'none';
		$('addBtnLink'+id).style.display = 'inline';
	}
	else
	{
		var myMorph = function(obj){
			
			$('removeBtnLink'+id).style.display = 'none';
			$(obj.element.id.replace("removeBtn", "addBtn")).style.opacity = '0';
			$(obj.element.id.replace("removeBtn", "addBtn")).style.width = '155px';
			$(obj.element.id.replace("removeBtn", "addBtn")).style.height = '28px';
			$(obj.element.id.replace("removeBtn", "addBtnLink")).style.display = 'inline';
			new Effect.Morph('addBtn' + id, {
											style: 'top:'+positionCart[1]+'px;left:'+positionCart[0]+'px;opacity:1;'
											
										}
						);
			
			
			};
		var linkCart = $('removeBtnLink'+id);
		Position.absolutize($('addBtn' + id));
		var positionCart = Position.cumulativeOffset($('removeBtn'+id));
		
		/*
		var linkCart = $('removeBtnLink'+id);
		Position.absolutize($('removeBtn' + id));
		$('addBtnLink'+id).style.opacity = '1';
		$('addBtnLink'+id).style.display = 'inline';
		var positionCart = Position.cumulativeOffset($('removeBtn'+id));
		*/
		new Effect.Fade('removeBtn' + id, { afterFinish: myMorph});
	}
	new Ajax.Updater( 'xxlInqList',linkCart.href, {
							method: 'get'
													}
					);
	
	
	
}

function setSize()
{
	var sheight = document.body.scrollHeight;
	if(document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ))
	{
		var sheight =  document.documentElement.clientHeight;
	}
	
	if(document.body.scrollHeight < window.innerHeight)
	{
		var sheight = window.innerHeight;
	}
	
	$('xxlMain').style.height = sheight+'px';
		
}

