try{ var resObjekt = new XMLHttpRequest(); }
    catch (e)
	{
		try{ var resObjekt = new ActiveXObject("Msxml2.XMLHTTP");} 
        catch (e)
		{
			try{ var resObjekt = new ActiveXObject("Microsoft.XMLHTTP");} 
            catch (failed){ var resObjekt = null; alert("error");}
        }   
    }



function save_session(partner, partnername)
{
	resObjekt.open("get", "/ajax/ajax_save_session.php?partner="+partner, true);
	resObjekt.send(null);
	pageTracker._trackPageview("/clickout/"+partnername+"/");
        
}

function add_bookmark()
{
	if (document.all) window.external.addFavorite("http://www.tamola.de","tamola");
	else if (window.sidebar) window.sidebar.addPanel("tamola", "http://www.tamola.de", "");
	else alert("Bitte drück Strg+D um die Seite zu Deinen Favoiten hinzuzufügen.");
}


function check_bankcode()
{
	var bankcode = document.getElementsByName("bank_code")[0].value;
	resObjekt.open("get", "/ajax/ajax_check_bankcode.php?bankcode="+bankcode, true);
	resObjekt.onreadystatechange = check_bankcode_handleResponse;
	resObjekt.send(null);
}
function check_bankcode_handleResponse()
{
	var bankname_content = document.getElementById("bankname");
	if (resObjekt.readyState == 4)  bankname_content.innerHTML = resObjekt.responseText;
	//else check_bankcode();
}

function shop_search()
{
	var search_string = document.getElementsByName("search_string")[0].value;
	if (search_string.length < 3) document.getElementById("general_search_shoplist").style.display = "none";
	else
	{
		resObjekt.open("get", "/ajax/ajax_shop_search.php?search_string="+search_string, true);
		resObjekt.onreadystatechange = shop_search_handleResponse;
		resObjekt.send(null);
	}
}
function shop_search_handleResponse()
{
	
	if (resObjekt.readyState == 4)
	{
		var ajax_shoplist = document.getElementById("general_search_shoplist");
		if (resObjekt.responseText == "") ajax_shoplist.style.display = "none";
		else
		{
			ajax_shoplist.innerHTML = resObjekt.responseText;
			ajax_shoplist.style.display = "block";
		}
	}
}

function shop_search_full(buttonclick, search_default_text)
{
	if (document.getElementById('selected_shopname')) var shop_name = document.getElementById('selected_shopname').value;
	else var shop_name = "-1";
	var search_string = document.getElementsByName("search_string")[0].value;
	if (document.getElementsByName("search_string")[0].value == search_default_text) search_string="";
	self.location.href='/shopdetails/'+shop_name+'/';
	if (shop_name != "-1" && !buttonclick)
	{
		self.location.href='/shopdetails/'+shop_name+'/';
	}
	else
	{
		search_string = search_string.replace(/%/g, " ");
		search_string = search_string.replace(/ä/gi, "%E4");
		search_string = search_string.replace(/ö/gi, "%F6");
		search_string = search_string.replace(/ü/gi, "%FC");
		search_string = search_string.replace(/ß/gi, "%DF");
		self.location.href = '/shops/alle/beliebteste/seite1/'+search_string+'/';
	}
}

function select_hit(count)
{
	var str_searchcount_partnername = document.getElementById('searchcount_partnername').value;
	var arr_searchcount_partnername = str_searchcount_partnername.split(";");
	var old_selected = document.getElementById('selected_searchcount').value;

	if (document.getElementById('searchhit_'+old_selected)) document.getElementById('searchhit_'+old_selected).style.backgroundColor = '#FFFFFF'; 
	document.getElementById('searchhit_'+count).style.backgroundColor = '#E6EEF8'; 
	document.getElementById('selected_shopname').value = arr_searchcount_partnername[count]; 
	document.getElementById('selected_searchcount').value = count;
}



function select_next_hit()
{
	var str_searchcount_partnername = document.getElementById('searchcount_partnername').value;
	var arr_searchcount_partnername = str_searchcount_partnername.split(";");
	var obj_count = document.getElementById('selected_searchcount');
	var count = obj_count.value;
	if (arr_searchcount_partnername.length-2 > count)
	{
		if (count >= 0) document.getElementById('searchhit_'+count).style.backgroundColor='#FFFFFF';
		count++;
		obj_count.value = count;
		document.getElementById('searchhit_'+count).style.backgroundColor='#E6EEF8';
		document.getElementById('selected_shopname').value = arr_searchcount_partnername[count];
	}
}

function select_prev_hit()
{
	var str_searchcount_partnername = document.getElementById('searchcount_partnername').value;
	var arr_searchcount_partnername = str_searchcount_partnername.split(";");
	var obj_count = document.getElementById('selected_searchcount');
	var count = obj_count.value;
	if (count > 0)
	{
		document.getElementById('searchhit_'+count).style.backgroundColor='#FFFFFF';
		count--;
		obj_count.value = count;
		document.getElementById('searchhit_'+count).style.backgroundColor='#E6EEF8';
		document.getElementById('selected_shopname').value = arr_searchcount_partnername[count];
	}
}

function remind_shop(shopid)
{
	resObjekt.open("get", "/ajax/ajax_remind_shop.php?shopid="+shopid, true);
	resObjekt.send(null);
}



function select_shop(shopid)
{
	document.getElementById("top_border_"+shopid).src="/images/partner_top_active.jpg";
	document.getElementById("container_"+shopid).style.backgroundImage = "url(/images/partnerlist_bg_active.jpg)";
	document.getElementById("bottom_border_"+shopid).src="/images/partner_bottom_active.jpg";
}

function unselect_shop(shopid)
{
	document.getElementById("top_border_"+shopid).src="/images/partner_top.jpg";
	document.getElementById("container_"+shopid).style.backgroundImage = "url(/images/partnerlist_bg.jpg)";
	document.getElementById("bottom_border_"+shopid).src="/images/partner_bottom.jpg";
}


function complaint_load_sessions(partnerid)
{
	resObjekt.open("get", "/ajax/ajax_complaint_load_sessions.php?partner="+partnerid, true);
	resObjekt.onreadystatechange = complaint_load_sessions_handleResponse;
	resObjekt.send(null);
}
function complaint_load_sessions_handleResponse()
{
	if (resObjekt.readyState == 4 && resObjekt.responseText != "") document.getElementById("complaint_info").innerHTML = resObjekt.responseText;
}


function calculate_cashback(cashback_amount, type, id)
{
	var amount = document.getElementsByName("amount_"+id)[0].value;
	var str_amount = amount.toString();
	str_amount = str_amount.replace(/,/, ".");
	amount = parseFloat(str_amount);
	if (type == 0) var cashback = cashback_amount/100 * amount;
	else var cashback = cashback_amount;
	cashback = cashback.toFixed(2);
	var str_cashback = cashback.toString();
	str_cashback = str_cashback.replace(/\./, ",");
	document.getElementsByName("cashback_"+id)[0].value = str_cashback;
}


// Add autocomplete attribute, needed so the page validates correctly
$(document).ready(function() {

	$( "#support-tabs" ).tabs();

    //behaviour of password fields
    $('#password-clear').show();
	$('#password-password').hide();

	$('#password-clear').focus(function() {
	    $('#password-clear').hide();
	    $('#password-password').show();
	    $('#password-password').focus();	});

	$('#password-password').blur(function() {
	    if($('#password-password').val() == '') {
	        $('#password-clear').show();
	        $('#password-password').hide();
	    }
	});

    $('#password-clear2').show();
	$('#password-password2').hide();

	$('#password-clear2').focus(function() {
	    $('#password-clear2').hide();
	    $('#password-password2').show();
	    $('#password-password2').focus();	});

	$('#password-password2').blur(function() {
	    if($('#password-password2').val() == '') {
	        $('#password-clear2').show();
	        $('#password-password2').hide();
	    }
	});

    
        
    $('#password-clear3').show();
	$('#password-password3').hide();

	$('#password-clear3').focus(function() {
	    $('#password-clear3').hide();
	    $('#password-password3').show();
	    $('#password-password3').focus();	});

	$('#password-password3').blur(function() {
	    if($('#password-password3').val() == '') {
	        $('#password-clear3').show();
	        $('#password-password3').hide();
	    }
	});


    $('.remove_default').bind('focus', function() {
        if( $(this).val() == $(this).attr('title') ) {
            $(this).val('');
            $(this).css('color', 'rgb(0, 0, 0)');
        }
    });

      $('.remove_default').bind('blur', function() {
   if ( $(this).val() == '') {
            $(this).css('color', 'rgb(153, 153, 153)');
            $(this).val($(this).attr('title'));
        }
});

    // Deactivate autocomplete
    $('input[type=password], #general_search_text').each(function() {
     $(this).attr('autocomplete', 'off');
    });

    // Make all overlays modal
    $('div.overlay').jqm({modal:true}); 
    
    $('div.overlay .close').bind('click', function() {
      $(this).closest('div.overlay').jqmHide(); 
    });
    
    $('.open_overlay_register').bind('click', function() {
      $('#overlay_register').jqmShow();
      return false;
    });
    
    $('.open_overlay_recommend').bind('click', function() {
      $('#overlay_recommend').jqmShow();
    });    
      
    
    if (typeof(show_overlay_register) != 'undefined') {
      $('#overlay_register').jqmShow();
    }

    if (typeof(show_overlay_recommend) != 'undefined') {
      $('#overlay_recommend').jqmShow();
    }


    /*

    if (typeof(show_overlay_register_success) != 'undefined') {
      $('#overlay_register_success').jqmShow();
    }

    if (typeof(show_overlay_recommend_success) != 'undefined') {
      $('#overlay_recommend_success').jqmShow();
    }
    
       
    $('a.register').bind('click', function() {
      $('#registerbox').jqmShow(); 
    });
    
    $('#register_overlay #exit_cross').bind('click', function() {
      $('#register_overlay').jqmHide(); 
    });*/
    
    var defaultSearch = $('#search_box input[type=text]').val();
    
    $('#search_box input[type=text]').bind('focus', function() {
      $(this).val($(this).val() == defaultSearch ? '' : $(this).val());
    });
    
    $('#search_box input[type=text]').bind('blur', function() {
      $(this).val(!$.trim($(this).val()).length ? defaultSearch : $(this).val());
    });
    
    $('#coininthecorner_close.front').bind('click', function() {
      $.ajax({
        url : '/coininthecorner_close.php',
        success : function() {
          $('#coininthecorner').hide('normal');
        }
      });
    });
    
    if (typeof(FFSuggest) != 'undefined') {
      var suggest           = new FFSuggest(); 
      var searchURL         = "/fact_finder/suggest.php"; 
      var formname          = "search_box"; 
      var queryParamName    = "query"; 
      var divLayername      = "suggestLayer"; 
      var instanceName      = "suggest"; 
      var debugMode         = true;
      
      suggest.init(searchURL, formname, queryParamName, divLayername, instanceName,  debugMode, '', ''); 
      
      document.onmousedown = suggest.hideLayerOutsideCall; 
    }
	
	
	//show sub-categories on hover
	/*
	$('.category').bind('mouseover', function() {
		$('div#general_categories_box ul ul').hide('normal');
		$(this).next('ul').show('normal');
	});
	*/
	
	
});
