var handlerFunc = function(t) 
{
	var new_h = 0;
	var obj_ret_s = eval("(" + t.responseText + ")");
	// var obj_ret_s = json_parse(t.responseText);
	// window.scrollTo(0,700);
	
	if(obj_ret_s.status == "false")
	{
		 	window.scrollTo(0,0);
	}
	else
	{
		 	window.scrollTo(0,700);
	}
	
	$("affilinet_search").innerHTML = unescape(obj_ret_s.content);
	
	//$("affilinet_search").innerHTML = unescape(t.responseText);
	$("preloader_aff").style.display = "none";
    $("lock_aff").value = 0;

 	fixHeight();
	markSortDirections();

	
}

var handlerdetailFunc = function(t) 
{
	$("lock_aff").value = 0;
	$("aff_detail_view_1").innerHTML = t.responseText;
    window.scrollTo(0, 0);
    
}

var handlerloginFunc = function(t) 
{
	var obj_ret = eval("("+t.responseText+")");
	if(obj_ret.status == "false")
	{
		alert("Bitte überprüfen Sie ihren Usernamen und Passwort!");
	}
	else
	{
	//alert(unescape(obj_ret.shopLink));
	$("no_login").innerHTML = unescape(obj_ret.loginBox);
	$("aff_button_det").innerHTML = unescape(obj_ret.shopLink);
    $("aff_form_left").style.display = "none";
    $("aff_form_right").style.display = "none";
	$("fotter_login").style.display = "block";    
    $("aff_detail_view").style.height = "520px";
    }
}

var handlernewFunc = function(t) 
{
	var obj_ret = eval("("+t.responseText+")");
	if(obj_ret.status == "false")
	{
		alert("Bitte geben Sie eine gültige E-Mail Adresse an!");
	}
	else
	{
	$("no_login").innerHTML = unescape(obj_ret.loginBox);
	$("aff_button_det").innerHTML = unescape(obj_ret.shopLink);
    $("aff_form_left").style.display = "none";
    $("aff_form_right").style.display = "none";
    $("fotter_login").style.display = "block";     
    $("aff_detail_view").style.height = "520px";
    }
}

var errFunc = function(t) 
{
    alert('Error ' + t.status + ' -- ' + t.statusText);
    touchUp({bg:'#FCF9D8',fg:'#666'});
}

function aff_new()
{
	var error = 0;
	
	if($("email").value == "" || $("email").value == "E-Mail Adresse")
	{
		$("email").style.borderColor = "red"; 
		error = 1;	
	}

	if($("agb").checked == false )
	{
		$("agb").style.color = "red";
		$("l_agb").style.color = "red"; 
		error = 1;	
	}	
	
	if(error == 0)
	{
		var form = 'aff_new_form';
	    new Ajax.Request('/fileadmin/scripts/partner/register.php', {encoding:'iso-8859-1', postBody:Form.serialize(form), onSuccess:handlernewFunc, onFailure:errFunc});
	}
}


function aff_login()
{
	var error = 0;
	
	if($("pwd").value == "" || $("pwd").value == "Passwort")
	{
		$("pwd").style.borderColor = "red"; 
		error = 1;	
	}
	if($("user").value == "" || $("user").value == "Benutzername")
	{
		$("user").style.borderColor = "red"; 
		error = 1;
	}
	
	if(error == 0)
		{
			var form = 'aff_log_form';
		    new Ajax.Request('/fileadmin/scripts/partner/register.php', {encoding:'iso-8859-1', postBody:Form.serialize(form), onSuccess:handlerloginFunc, onFailure:errFunc});
		}
}


function detail_affilinet()
{
	var form = 'p24affilinetdetailform';
    new Ajax.Request('/fileadmin/scripts/partner/affilinet_detail.php', {encoding:'iso-8859-1', postBody:Form.serialize(form), onSuccess:handlerdetailFunc, onFailure:errFunc});
	new Ajax.Request('/fileadmin/scripts/partner/aff_track.php?aktion=det_klick', {encoding:'iso-8859-1', postBody:Form.serialize(form), onSuccess:handlertrackFunc, onFailure:errFunc});
}


function Request_affilinet()
{
	var form = 'p24affilinetform';
	if($("old").value != $("key").value)
	{
		$("aff_page").value = 1;
		$("lock_track").value = 0;
	}
	if($("lock_aff").value == 0)
	{
		$("preloader_aff").style.display = "block";
		$("lock_aff").value = 1;
    	new Ajax.Request('/fileadmin/scripts/partner/affilinet.php', {encoding:'iso-8859-1', postBody:Form.serialize(form), onSuccess:handlerFunc, onFailure:errFunc});
    	if($("lock_track").value < 1)
    	{
    	new Ajax.Request('/fileadmin/scripts/partner/aff_track.php?aktion=search', {encoding:'iso-8859-1', postBody:Form.serialize(form), onSuccess:handlertrackFunc, onFailure:errFunc});
		}
	
	}
}


var handlertrackFunc = function(t)
{

}


function Track_Detail_Klick(shop, b_id, pr_id,aktion)
{
	var link = '/fileadmin/scripts/partner/aff_track.php?shop='+shop+'&b_id='+b_id+'&pr_id='+pr_id+'&aktion='+aktion;
	
	new Ajax.Request(link, {encoding:'iso-8859-1', onSuccess:handlertrackFunc, onFailure:errFunc});
}

function page_affilinet()
{
	
	var form = 'p24affilinetform';
    new Ajax.Request('/fileadmin/scripts/partner/affilinet.php', {encoding:'iso-8859-1', postBody:Form.serialize(form), onSuccess:handlerFunc, onFailure:errFunc});
}

function set_page(page)
{
	close_aff_details();
	$("aff_page").value = page;
	$("lock_track").value = 1;
	$("old").value = $("key").value;
}


function set_detail(detail)
{
	$("ProductID").value = detail;
}

function unlock()
{
	$("lock_aff").value = 0;
}

function show_aff_details()
{
    w = $("head").offsetLeft;
	var w_1 = (w + 100);
	$("p24affilinetform").style.display = "none";
	$("aff_detail_view").style.left = w_1+"px";
	$("aff_detail_view").style.display = "block";
}

function close_aff_details()
{
	$("aff_detail_view").style.display = "none";
	$("p24affilinetform").style.display = "block";
	window.scrollTo(0,700);
}


function clear_aff(el)
{
	el.value="";
	el.style.borderColor ="#808080";
}

	/**
	 * method sortList
	 *
	 * @return void
	 *
	 *
	 *
	 */
	var sortList = function()
	{
		var by            = 'Title';
		var direction     = 1;
		var selectedValue = $('p24ShopMallSortSelectId').value;
		
		switch(selectedValue)
		{
			case '1':
				by = 'Title';
				direction = 1;
			break;
			case '2':
				by = 'Title';
				direction = 2;
			break;
			case '3':
				by = 'Price';
				direction = 1;
			break;
			case '4':
				by = 'Price';
				direction = 2;
			break;
		}
	
		$("lock_aff").value = 1;
		$('sort').value = by;
		$('order').value = direction;
		var form = Form.serialize('p24affilinetform');
		// markSortDirections();
		
    	new Ajax.Request(
    		'/fileadmin/scripts/partner/affilinet.php', 
    		{
    			encoding: 'iso-8859-1', 
    			postBody: form, 
    			onSuccess: handlerFunc, 
    			onFailure: errFunc
    		}
    	);
	}
	
	/**
	 * method markSortDirections
	 *
	 * @return void
	 *
	 *
	 *
	 */
	var markSortDirections = function()
	{
		by = $('sort').value;
		direction = $('order').value;
		
		switch(true)
		{
			case (by == 'Price' && direction == 1):
				$('p24ShopMallSortSelectId').value = 3;
			break;
			case (by == 'Price' && direction == 2):
				$('p24ShopMallSortSelectId').value = 4;
			break;
			case (by == 'Title' && direction == 1):
				$('p24ShopMallSortSelectId').value = 1;
			break;
			case (by == 'Title' && direction == 2):
				$('p24ShopMallSortSelectId').value = 2;
			break;
		}
	}
