// clear text on search form on click into text field
function ClearTextSearch(){
	if($('search_box_validation').value == $('search_text').value){
		$('search_text').value = "";
	}
}
function ClearTextSearchStart() {
document.search.search_text.value = "";

}

function SaveMailAlert(){
	if(validateMailalertForm()){
	
	new Ajax.Request($F('url'), 
		{   
		   method:"post",
           parameters:{email:$F('email'), price:$F('price'), products_id:$F('product_id'),product_name:$F('product_name'), curtime: (new Date()).getTime() },
           onSuccess: function(transport) {   
				var resp = $('form_spy'); 
				var respText = transport.responseText;
				resp.update(respText);  
			  } 
		}); 
	}
}

function validateSearchBox(str){
		if($('search_box_validation').value == $('search_text').value){
			document.getElementById("error").style.display = "block";
			document.getElementById("error").innerHTML = ($('search_box_error_message').value);
			$('search_text').focus();
			return false;
		}
		
		var search_text = $F('search_text');
		if(search_text.blank()){
			document.getElementById("error").style.display = "block";
			document.getElementById("error").innerHTML = ($('search_box_error_message').value);
			$('search_text').focus();
			return false;
		}
		
		if(isSpclChar($('search_text').value)){
			//document.getElementById("error").style.display = "block";
			//document.getElementById("error").innerHTML = ($('search_box_error_message_notfound').value);
			//window.location='/search/'+$('search_text').value;
			if(str!=''){
				window.location='/'+str+'/suche_'+$('search_text').value;
			}else{
				window.location='/suche_'+$('search_text').value;
			}
		}
		return false;
}

function validateSearchBoxLanding(str){
		if($('search_box_validation').value == $('search_text').value){
			document.getElementById("error").style.display = "block";
			document.getElementById("error").innerHTML = ($('search_box_error_message').value);
			$('search_text').focus();
			document.getElementById("top_text").style.display = "none";
			return false;
		}
		
		var search_text = $F('search_text');
		if(search_text.blank()){
			document.getElementById("error").style.display = "block";
			document.getElementById("error").innerHTML = ($('search_box_error_message').value);
			$('search_text').focus();
			document.getElementById("top_text").style.display = "none";
			return false;
		}
		
		if(isSpclChar($('search_text').value)){
			//document.getElementById("error").style.display = "block";
			//document.getElementById("error").innerHTML = ($('search_box_error_message_notfound').value);
			if(str!=''){
				window.location='/'+str+'/suche_'+$('search_text').value;
			}else{
				window.location='/suche_'+$('search_text').value;
			}
		}else{
			document.getElementById("top_text").style.display = "none";
		}
		return false;
}

function isSpclChar(str){
		var iChars = "!@#$%^&*()+=[]\\\';,/{}|\":<>?";
        for (var i = 0; i < str.length; i++) {
                if (iChars.indexOf(str.charAt(i)) != -1) {
						document.getElementById("error").style.display = "block";
						document.getElementById("error").innerHTML = ($('search_box_error_message_specialchars').value);
						return false;
				}
        }
		return true;
}  


function validateMailalertForm(){
	var email = $F('email');
	if(email.blank()){
		//alert('Please enter the email address.');
		//$('email').focus();
		return false;
	}
	
	if(checkEmail(email) == ""){
		//$('email').focus();
		return false;
	} else if (checkEmail(email) == "z.B. xy@ihre-seite.ch") {
		return false;
	}
	
	var price = $F('price');
	if(price.blank()){
		//alert('Please enter your price .');
		//$('price').focus();
		return false;
	}
	if(price == "z.B. 300.00") {
		return false;
	}
	
	return true;
}

function checkEmail(str){
	
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
		return true;
	else{
		//alert("Invalid E-mail Address! Please re-enter.")
		return false;
	}
}
function __blogFeed(_urlname){
	var _url = '/blogfeed/'+_urlname;
	
	new Ajax.Request(_url, 
		{   
		   method:"post",
           parameters: {curtime: (new Date()).getTime() },
           onSuccess: function(transport) {   
				var resp = $('blogverzeichnis_feed'); 
				var respText = transport.responseText;
					
				resp.update(respText);  
				
			  } 
		});
}

function __ebookletFeed(_urlname){
	var _url = '/ebookletfeed/'+_urlname;
	
	new Ajax.Request(_url, 
		{   
		   method:"post",
           parameters: {curtime: (new Date()).getTime() },
           onSuccess: function(transport) {   
				var resp = $('ebooklet_feed'); 
				
				var respText = transport.responseText;
					
				resp.update(respText);  
				
			  } 
		});
}

function redirectPage(){
	
	merchant = document.getElementById('merchant_select');
	window.location=document.getElementById('url').value+'&manufacturer='+merchant.options[merchant.selectedIndex].value;
	
}
function redirectPageSize(){
	
	merchant = document.getElementById('merchant_select');
	if(merchant.options[merchant.selectedIndex].text){
		pagesize = document.getElementById('pagesize_select');
		
		if((merchant.options[merchant.selectedIndex].text)=='select') window.location=document.getElementById('url').value+'&pagesize='+pagesize.options[pagesize.selectedIndex].value;
		else window.location=document.getElementById('url').value+'&manufacturer='+merchant.options[merchant.selectedIndex].value+'&pagesize='+pagesize.options[pagesize.selectedIndex].value;
	}
	
}
function changeBgcolor(id){
	id.style.backgroundColor='#eef2fb';
	id.style.cursor='pointer';
	
}
function restoreBgColor(id){
	if(id.className=="gallery_item") id.style.backgroundColor='#FFFFFF';
	else id.style.backgroundColor='#efefef';
}
function changeBgcolor2(id){
	id.style.backgroundColor='none';
	id.style.cursor='pointer';
	
}
function restoreBgColor2(id){
	if(id.className=="gallery_item") id.style.backgroundColor='none';
	else id.style.backgroundColor='none';
}

function redirectBrandPageSearch(){
	//window.location='/'+document.merchantForm.merchant_select.selectedIndex;
	merchant = document.getElementById('merchant_select');
	window.location=document.getElementById('url').value+'/?manufacturer='+merchant.options[merchant.selectedIndex].value;
	
}
function changePageSize(){
	
		merchant = document.getElementById('merchant_select');
		if(merchant.options[merchant.selectedIndex].text){
			pagesize = document.getElementById('pagesize_select');
		
		if((merchant.options[merchant.selectedIndex].text)=='Select') window.location=document.getElementById('url').value+'/?pagesize='+pagesize.options[pagesize.selectedIndex].value;
		else window.location=document.getElementById('url').value+'/?manufacturer='+merchant.options[merchant.selectedIndex].value+'?pagesize='+pagesize.options[pagesize.selectedIndex].value;
	}
}
function changePageSizeSearch(){
	
		merchant = document.getElementById('merchant_select');
		if(merchant.options[merchant.selectedIndex].text){
			pagesize = document.getElementById('pagesize_select');
		
		if((merchant.options[merchant.selectedIndex].text)=='Select') window.location=document.getElementById('url').value+'?pagesize='+pagesize.options[pagesize.selectedIndex].value;
		else window.location=document.getElementById('url').value+'/?manufacturer='+merchant.options[merchant.selectedIndex].value+'&pagesize='+pagesize.options[pagesize.selectedIndex].value;
	}
}


function changebackground(id){
	id.style.backgroundColor='#eef2fb';
	id.style.cursor='pointer';

}
function hidebackground(id){
	if(id.className=="list_items item_active") id.style.backgroundColor='#ffffff';	
	else id.style.backgroundColor='#efefef';

	
}
function m_hidebackground(id){
	if(id.className=="detail_list_item item_active") id.style.backgroundColor='#ffffff';	
	else id.style.backgroundColor='#efefef';

	
}

function redirectBrandPage(){
	//window.location='/'+document.merchantForm.merchant_select.selectedIndex;
	merchant = document.getElementById('merchant_select');
	
	window.location=document.getElementById('url').value+'/manufacturer_'+merchant.options[merchant.selectedIndex].value;
	
}
function changePageSize(){
	
		merchant = document.getElementById('merchant_select');
		if(merchant.options[merchant.selectedIndex].text){
			pagesize = document.getElementById('pagesize_select');
		
		if((merchant.options[merchant.selectedIndex].text)=='Select') window.location=document.getElementById('url').value+'/?pagesize='+pagesize.options[pagesize.selectedIndex].value;
		else window.location=document.getElementById('url').value+'/?manufacturer='+merchant.options[merchant.selectedIndex].value+'&pagesize='+pagesize.options[pagesize.selectedIndex].value;
	}
}
function redirectProductList(url){
	window.location=url;
	
}
function onlyNumbers(e){

	if(window.event) // IE
  	{
  		keynum = e.keyCode;
  	}
	else if(e.which) // Netscape/Firefox/Opera
 	 {
  		keynum = e.which;
  	}

	if (keynum > 31 && (keynum < 48 || keynum > 57) && keynum!= 46)
		return false;

	return true;

}

/* overlay */

/* overlay to overlay1 done by et */

function showBox(){
    $('overlay1').show();
    center('box');
    $('box2').hide();
    return false;
}

/*the overlay */

/* overlay to popup */

var xWin;
function openWin(param,valParam){
	
	var pageName = "http://"+param+"/tellafriend"+valParam;
	if(xWin && !xWin.closed){
		xWin.focus();
	}else{
		xWin = window.open(pageName,'tf','top=135,left=200,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=580,height=488');
	}
}

/* overlay to popup */

function hideBox(){
    /*$('box2').hide();
    $('box').hide();
    $('overlay').hide();
    document.getElementById("sender_name").value= '';
    document.getElementById("sender_mail").value= '';
    document.getElementById("recipient_name").value= '';
    document.getElementById("recipient_mail").value= '';
    document.getElementById("recipient_msg").value= document.getElementById("recipient_msghidden").value;
	//Blocked by Et//
	*/
	window.top.hidePopWin()// added by ET.
    return false;
}

/*the overlay */
function showBox2(){
    $('overlay1').show();
    $('box').hide();
    center('box2');
    return false;
}

/* the overlay close popup */

/* the overlay close popup */

function center(element){
    try{
        element = $(element);
    }catch(e){
        return;
    }

    var my_width  = 0;
    var my_height = 0;

    if ( typeof( window.innerWidth ) == 'number' ){
        my_width  = window.innerWidth;
        my_height = window.innerHeight;
    }else if ( document.documentElement && 
             ( document.documentElement.clientWidth ||
               document.documentElement.clientHeight ) ){
        my_width  = document.documentElement.clientWidth;
        my_height = document.documentElement.clientHeight;
    }
    else if ( document.body && 
            ( document.body.clientWidth || document.body.clientHeight ) ){
        my_width  = document.body.clientWidth;
        my_height = document.body.clientHeight;
    }

    element.style.position = 'absolute';
    element.style.zIndex   = 99;

    var scrollY = 0;

    if ( document.documentElement && document.documentElement.scrollTop ){
        scrollY = document.documentElement.scrollTop;
    }else if ( document.body && document.body.scrollTop ){
        scrollY = document.body.scrollTop;
    }else if ( window.pageYOffset ){
        scrollY = window.pageYOffset;
    }else if ( window.scrollY ){
        scrollY = window.scrollY;
    }

    var elementDimensions = Element.getDimensions(element);

    var setX = ( my_width  - elementDimensions.width  ) / 2;
    var setY = ( my_height - elementDimensions.height ) / 2 + scrollY;

    setX = ( setX < 0 ) ? 0 : setX;
    setY = ( setY < 0 ) ? 0 : setY;

    element.style.left = setX + "px";
    element.style.top  = setY + "px";

    element.style.display  = 'block';
}


/*Idealizer, Philipp: the next section is for the tell2friend functionality */

   var http_request = false;
   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }




   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById('myspan').innerHTML = result; 
            showBox2();           
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   function get(obj) {
      var poststr = "sender_name=" + encodeURI( document.getElementById("sender_name").value ) +
                    "&sender_mail=" + encodeURI( document.getElementById("sender_mail").value )+
                    "&recipient_name=" + encodeURI( document.getElementById("recipient_name").value )+
                    "&recipient_mail=" + encodeURI( document.getElementById("recipient_mail").value )+
                    "&recipient_msg=" + encodeURI( document.getElementById("recipient_msg").value );
      makePOSTRequest('../../../files/tell2friend.php', poststr);
   }
/*Idealizer, Philipp: the next section is for the tell2friend functionality FINISH*/

/* For image gallery picture change :: suman32@gmail.com */

	function ImageGallery(id){	
		
		var subSecImg = document.getElementById(id).src;
		var secImg = subSecImg.split('\\').reverse()[0].split('/').reverse()[0];
		var leafnameett= subSecImg.split('\\').reverse()[0].split('/').reverse()[2];
		
		var pathname = document.getElementById("ProductImageGallery").src;
		var leafname= pathname.split('\\').reverse()[0].split('/').reverse()[0];
		var leafnamee= pathname.split('\\').reverse()[0].split('/').reverse()[2];
		
		var CreateMainImage = "../../productimage/"+leafnameett+"/size_a/"+secImg;
		var CreateSubImage = "../../productimage/"+leafnamee+"/size_c/"+leafname;		
		
		document.getElementById("ProductImageGallery").src=CreateMainImage;
		document.getElementById(id).src=CreateSubImage;	
			
	}
	
	function ImageGalleryMerchant(id){	
		
		var subSecImg = document.getElementById(id).src;
		var secImg = subSecImg.split('\\').reverse()[0].split('/').reverse()[0];
		var leafnameett= subSecImg.split('\\').reverse()[0].split('/').reverse()[2];
		
		var pathname = document.getElementById("ProductImageGallery").src;
		var leafname= pathname.split('\\').reverse()[0].split('/').reverse()[0];
		var leafnamee= pathname.split('\\').reverse()[0].split('/').reverse()[2];
		
		var CreateMainImage = "../../../../../../../../../merchantimage/"+leafnameett+"/size_a/"+secImg;
		var CreateSubImage = "../../../../../../../../../merchantimage/"+leafnamee+"/size_c/"+leafname;		
		
		document.getElementById("ProductImageGallery").src=CreateMainImage;
		document.getElementById(id).src=CreateSubImage;	
			
	}		
	
/*facebook*/
function fbs_click() {
u=location.href;
t=document.title;
window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
return false;
}