
function SetFocus(TargetFormName) {
  var target = 0;
  if (TargetFormName != "") {
    for (i=0; i<document.forms.length; i++) {
      if (document.forms[i].name == TargetFormName) {
        target = i;
        break;
      }
    }
  }

  var TargetForm = document.forms[target];
    
  for (i=0; i<TargetForm.length; i++) {
    if ( (TargetForm.elements[i].type != "image") && (TargetForm.elements[i].type != "hidden") && (TargetForm.elements[i].type != "reset") && (TargetForm.elements[i].type != "submit") ) {
      TargetForm.elements[i].focus();

      if ( (TargetForm.elements[i].type == "text") || (TargetForm.elements[i].type == "password") ) {
        TargetForm.elements[i].select();
      }
      break;
    }
  }
}

function RemoveFormatString(TargetElement, FormatString) {
  if (TargetElement.value == FormatString) {
    TargetElement.value = "";
  }

  TargetElement.select();
}

function CheckDateRange(from, to) {
  if (Date.parse(from.value) <= Date.parse(to.value)) {
    return true;
  } else {
    return false;
  }
}

function IsValidDate(DateToCheck, FormatString) {
  var strDateToCheck;
  var strDateToCheckArray;
  var strFormatArray;
  var strFormatString;
  var strDay;
  var strMonth;
  var strYear;
  var intday;
  var intMonth;
  var intYear;
  var intDateSeparatorIdx = -1;
  var intFormatSeparatorIdx = -1;
  var strSeparatorArray = new Array("-"," ","/",".");
  var strMonthArray = new Array("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
  var intDaysArray = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

  strDateToCheck = DateToCheck.toLowerCase();
  strFormatString = FormatString.toLowerCase();
  
  if (strDateToCheck.length != strFormatString.length) {
    return false;
  }

  for (i=0; i<strSeparatorArray.length; i++) {
    if (strFormatString.indexOf(strSeparatorArray[i]) != -1) {
      intFormatSeparatorIdx = i;
      break;
    }
  }

  for (i=0; i<strSeparatorArray.length; i++) {
    if (strDateToCheck.indexOf(strSeparatorArray[i]) != -1) {
      intDateSeparatorIdx = i;
      break;
    }
  }

  if (intDateSeparatorIdx != intFormatSeparatorIdx) {
    return false;
  }

  if (intDateSeparatorIdx != -1) {
    strFormatArray = strFormatString.split(strSeparatorArray[intFormatSeparatorIdx]);
    if (strFormatArray.length != 3) {
      return false;
    }

    strDateToCheckArray = strDateToCheck.split(strSeparatorArray[intDateSeparatorIdx]);
    if (strDateToCheckArray.length != 3) {
      return false;
    }

    for (i=0; i<strFormatArray.length; i++) {
      if (strFormatArray[i] == 'mm' || strFormatArray[i] == 'mmm') {
        strMonth = strDateToCheckArray[i];
      }

      if (strFormatArray[i] == 'tt') {
        strDay = strDateToCheckArray[i];
      }

      if (strFormatArray[i] == 'jjjj') {
        strYear = strDateToCheckArray[i];
      }
    }
  } else {
    if (FormatString.length > 7) {
      if (strFormatString.indexOf('mmm') == -1) {
        strMonth = strDateToCheck.substring(strFormatString.indexOf('mm'), 2);
      } else {
        strMonth = strDateToCheck.substring(strFormatString.indexOf('mmm'), 3);
      }

      strDay = strDateToCheck.substring(strFormatString.indexOf('tt'), 2);
      strYear = strDateToCheck.substring(strFormatString.indexOf('jjjj'), 2);
    } else {
      return false;
    }
  }
  if (strYear.length != 4) {
    return false;
  }

  intday = parseInt(strDay, 10);
  if (isNaN(intday)) {
    return false;
  }
  if (intday < 1) {
    return false;
  }

  intMonth = parseInt(strMonth, 10);
  if (isNaN(intMonth)) {
    for (i=0; i<strMonthArray.length; i++) {
      if (strMonth == strMonthArray[i]) {
        intMonth = i+1;
        break;
      }
    }
    if (isNaN(intMonth)) {
      return false;
    }
  }
  if (intMonth > 12 || intMonth < 1) {
    return false;
  }

  intYear = parseInt(strYear, 10);
  if (isNaN(intYear)) {
    return false;
  }
  if (IsLeapYear(intYear) == true) {
    intDaysArray[1] = 29;
  }

  if (intday > intDaysArray[intMonth - 1]) {
    return false;
  }
  
  return true;
}

function IsLeapYear(intYear) {
  if (intYear % 100 == 0) {
    if (intYear % 400 == 0) {
      return true;
    }
  } else {
    if ((intYear % 4) == 0) {
      return true;
    }
  }

  return false;
}

function td_menge_listing(y,id) {
	var x = y;
	if ( document.getElementById(id).value == "" )
		x = "";
	else
		x = eval( document.getElementById(id).value );
	document.getElementById(id).value = x + y;
	if(y < 0)
	{
		if (document.getElementById(id).value <= y-(y+y))
			document.getElementById(id).value = y-(y+y);
	}
	else
	{
		if (document.getElementById(id).value <= y)
			document.getElementById(id).value = y;
	}
}

function td_menge_listing_okd(y,id) {
	if (isNaN(document.getElementById(id).value))
	{
		document.getElementById(id).value = y;
	}
	else
	{
	var x = document.getElementById(id).value;
	var value = false;
		for (i=y; value == false; x++)
		{
			if(x % i == 0)
			{
				value = true;
				document.getElementById(id).value = x;
			}
		}
	}
}

feld = '';
goorno = true;
function getField (field) 
{
	if(goorno == true)
		feld = $(field).val();
	goorno = false;
}

function setField (field) 
{
	$(field).val(feld);
	goorno = true;
}


var win = null;
function NewWindow(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable=yes'
	win = window.open(mypage,myname,settings)
}

function resize(which, max) {
	var elem = document.getElementById(which);
	var aryImages = new Array();
  aryImages[0] = new Image; 
	aryImages[0].src = elem.src;
	if (elem == undefined || elem == null) 
		return false;
	if (max == undefined) 
		max = 120;
	var element_width = aryImages[0].width;
	var element_height = aryImages[0].height;
	if (element_width > element_height) {
		if (element_width > max) 
			document.getElementById(which).width = max;
	} else {
		if (element_width > max) 
			document.getElementById(which).height = max;
	}
	document.getElementById(which).style.display = "inline";
}


String.prototype.htmlEntities = function()
{
  var chars = new Array ('&','à','á','â','ã','ä','å','æ','ç','è','é',
                         'ê','ë','ì','í','î','ï','ð','ñ','ò','ó','ô',
                         'õ','ö','ø','ù','ú','û','ü','ý','þ','ÿ','À',
                         'Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë',
                         'Ì','Í','Î','Ï','Ð','Ñ','Ò','Ó','Ô','Õ','Ö',
                         'Ø','Ù','Ú','Û','Ü','Ý','Þ','€','\"','ß','<',
                         '>','¢','£','¤','¥','¦','§','¨','©','ª','«',
                         '¬','­','®','¯','°','±','²','³','´','µ','¶',
                         '·','¸','¹','º','»','¼','½','¾');

  var entities = new Array ('amp','agrave','aacute','acirc','atilde','auml','aring',
                            'aelig','ccedil','egrave','eacute','ecirc','euml','igrave',
                            'iacute','icirc','iuml','eth','ntilde','ograve','oacute',
                            'ocirc','otilde','ouml','oslash','ugrave','uacute','ucirc',
                            'uuml','yacute','thorn','yuml','Agrave','Aacute','Acirc',
                            'Atilde','Auml','Aring','AElig','Ccedil','Egrave','Eacute',
                            'Ecirc','Euml','Igrave','Iacute','Icirc','Iuml','ETH','Ntilde',
                            'Ograve','Oacute','Ocirc','Otilde','Ouml','Oslash','Ugrave',
                            'Uacute','Ucirc','Uuml','Yacute','THORN','euro','quot','szlig',
                            'lt','gt','cent','pound','curren','yen','brvbar','sect','uml',
                            'copy','ordf','laquo','not','shy','reg','macr','deg','plusmn',
                            'sup2','sup3','acute','micro','para','middot','cedil','sup1',
                            'ordm','raquo','frac14','frac12','frac34');

  newString = this;
  for (var i = 0; i < chars.length; i++)
  {
    myRegExp = new RegExp();
    myRegExp.compile(chars[i],'g')
    newString = newString.replace (myRegExp, '&' + entities[i] + ';');
  }
  return newString;
}

var last_middle_content = '';
function show_middle_content(id,dis)
{
	if(typeof id == "undefined")
		id = '';
	if(typeof dis == "undefined")
		dis = 1;
	if(dis == 1)
	{
		document.getElementById('back_div').style.display = "inline";
		//Effect.toggle('back_div','appear');
		document.getElementById('div_middle_content').style.display = "inline";
		document.getElementById(id).style.display = "inline";
		last_middle_content = id;
		var scrollbar = new Control.ScrollBar('scrollbar_content','scrollbar_track');
		scrollbar.recalculateLayout();
	}else if(dis == 0){
			if(id != '')
				document.getElementById(id).style.display = "none";
			else if(last_middle_content != '')
				document.getElementById(last_middle_content).style.display = "none";
			document.getElementById('div_middle_content').style.display = "none";
			document.getElementById('back_div').style.display = "none";
			//Effect.toggle('back_div','appear');
		}
}

String.prototype.htmlEntitiesDecode = function()
{
  var chars = new Array ('&','à','á','â','ã','ä','å','æ','ç','è','é',
                         'ê','ë','ì','í','î','ï','ð','ñ','ò','ó','ô',
                         'õ','ö','ø','ù','ú','û','ü','ý','þ','ÿ','À',
                         'Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë',
                         'Ì','Í','Î','Ï','Ð','Ñ','Ò','Ó','Ô','Õ','Ö',
                         'Ø','Ù','Ú','Û','Ü','Ý','Þ','€','\"','ß','<',
                         '>','¢','£','¤','¥','¦','§','¨','©','ª','«',
                         '¬','­','®','¯','°','±','²','³','´','µ','¶',
                         '·','¸','¹','º','»','¼','½','¾');

  var entities = new Array ('amp','agrave','aacute','acirc','atilde','auml','aring',
                            'aelig','ccedil','egrave','eacute','ecirc','euml','igrave',
                            'iacute','icirc','iuml','eth','ntilde','ograve','oacute',
                            'ocirc','otilde','ouml','oslash','ugrave','uacute','ucirc',
                            'uuml','yacute','thorn','yuml','Agrave','Aacute','Acirc',
                            'Atilde','Auml','Aring','AElig','Ccedil','Egrave','Eacute',
                            'Ecirc','Euml','Igrave','Iacute','Icirc','Iuml','ETH','Ntilde',
                            'Ograve','Oacute','Ocirc','Otilde','Ouml','Oslash','Ugrave',
                            'Uacute','Ucirc','Uuml','Yacute','THORN','euro','quot','szlig',
                            'lt','gt','cent','pound','curren','yen','brvbar','sect','uml',
                            'copy','ordf','laquo','not','shy','reg','macr','deg','plusmn',
                            'sup2','sup3','acute','micro','para','middot','cedil','sup1',
                            'ordm','raquo','frac14','frac12','frac34');

  newString = this;
  for (var i = 0; i < entities.length; i++)
  {
    myRegExp = new RegExp();
    myRegExp.compile('&' + entities[i] + ';','g')
    newString = newString.replace (myRegExp, chars[i]);
  }
  return newString;
}

function filter_table (phrase, _id){
	var words = phrase.value.toLowerCase().split(" ");
	var table = document.getElementById(_id);
	var ele;
	for (var r = 1; r < table.rows.length; r++){
		ele = table.rows[r].innerHTML.replace(/<[^>]+>/g,"");
	        var displayStyle = 'none';
	        for (var i = 0; i < words.length; i++) {
		    if (ele.toLowerCase().indexOf(words[i])>=0)
			displayStyle = '';
		    else {
			displayStyle = 'none';
			break;
		    }
	        }
		table.rows[r].style.display = displayStyle;
	}
}

function number_format (number, decimals, dec_point, thousands_sep) {
    number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
    var n = !isFinite(+number) ? 0 : +number,
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);            return '' + Math.round(n * k) / k;
        };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');    }
    return s.join(dec);
}

function size_format(bytecount) {
  var str = bytecount+' Byte';
  if (Number(bytecount) > 1024) { str = number_format((bytecount/1024).toFixed(2),2,',','.')+' KB'; }
  if (Number(bytecount) > 1048576) { str = number_format((bytecount/1048576).toFixed(2),2,',','.')+' MB'; }
  if (Number(bytecount) > 1073741824) { str = number_format((bytecount/1073741824).toFixed(2),2,',','.')+' GB'; }
  return str;
} 


//SHOPPINGCART
function update_product_to_cart(p_id,quantity,dis_cart_reset)
{
	if(typeof p_id != 'undefined' && typeof quantity != 'undefined')
	{
		del_product_in_cart(p_id,dis_cart_reset);
		setTimeout(function(){add_product_to_cart(p_id,quantity,dis_cart_reset);},300);
	}
}


function add_product_to_cart(p_id,quantity,dis_cart_reset)
{
	if(typeof p_id != 'undefined' && typeof quantity != 'undefined')
	add_products_to_cart(p_id+'_'+quantity,dis_cart_reset);
}

function add_products_to_cart(p_ids,dis_cart_reset)
{
	if(typeof p_ids != 'undefined')
	{
		$.getJSON('ajax_function.php?exe=83a5c895143400938a7cd15f42f662f6&list_product_ids='+p_ids, function(data)
		{
			
			if(typeof data.add_to_cart != 'undefined' && data.add_to_cart == true)
			{
				if(typeof dis_cart_reset == 'undefined' || dis_cart_reset == false)
				{
					reset_cart(true);
					if(data.added_products.length > 1)
						footer_popup('<table><tr><td><img src="../customize/images/cart_add.png" />&nbsp;</td><td>'+data.added_products.length+' '+data.added_products_text+'</td></tr></table>');
					else{
						if(data.added_products[0].products_image != '')
							footer_popup('<table><tr><td><img src="../customize/images/cart_add.png" />&nbsp;</td><td><img class="cart_image" src="'+data.added_products[0].products_image+'" /></td><td>&nbsp;'+data.added_products[0].products_quantity_add+'x&nbsp;<span class="cart_desc">'+data.added_products[0].short_desc+'</span></td></tr></table>');
						else
							footer_popup('<table><tr><td><img src="../customize/images/cart_add.png" />&nbsp;</td><td>&nbsp;'+data.added_products[0].products_quantity_add+'x&nbsp;<span class="cart_desc">'+data.added_products[0].short_desc+'</span></td></tr></table>');
					}
				}
			}
		});
	}
}

event_cart_timer = 0;
function del_product_in_cart(p_id,dis_cart_reset)
{
	if(typeof p_id != 'undefined')
		del_products_to_cart(p_id,dis_cart_reset);
}

function del_products_to_cart(p_ids,dis_cart_reset)
{
	if(typeof p_ids != 'undefined')
	{
		$.getJSON('ajax_function.php?exe=977e1543cd2775f27f31a650535e3f04&list_product_ids='+p_ids, function(data) {
			if(typeof data.del_in_cart != 'undefined' && data.del_in_cart == true)
				wait_a_moment = false;
				if(typeof $('#cart_overview') != 'undefined' && $('#cart_overview').css('display') != 'none')
				{
					if(typeof data.del_products != 'undefined')
					{
						for(var product_id in data.del_products)
						{
							if(typeof $('#cart_pr_'+data.del_products[product_id]) != 'undefined')
							{
								$('#cart_pr_'+data.del_products[product_id]).slideUp(300);
								wait_a_moment = true;
							}
						}
					}
				}
				if(typeof dis_cart_reset == 'undefined' || dis_cart_reset == false)
				{
					if(wait_a_moment == false)
						reset_cart();
					else
						setTimeout(function(){reset_cart();},300);
				}
		});
	}
}

function reset_cart(add_product)
{
	$.getJSON('ajax_function.php?exe=94a512d587dc17236bee99c67e8a25f5', function(data){
		if(typeof $('#cart_sum') != 'undefined' && typeof $('#cart_count') != 'undefined' && typeof data.cart_count != 'undefined' && typeof data.sum_format != 'undefined')
		{
			$('#cart_sum').html(data.sum_format);
			$('#cart_count').html(data.cart_count);
		}
		if(typeof $('#cart_overview') != 'undefined' && typeof data.products != 'undefined')
		{
			html_ret = '';
			for(var product_id in data.products)
			{
				html_ret+= '<div class="cart_pr" id="cart_pr_'+product_id+'"><table><tr><td rowspan="2" class="cart_pr_img"><a href="'+data.products[product_id].link+'"><img src="'+data.products[product_id].image+'" /></a></td><td class="cart_pr_desc"><div class="cart_pr_del" onclick="del_product_in_cart('+product_id+');">'+data.del_button+'</div><a href="'+data.products[product_id].link+'">'+data.products[product_id].short_desc+'</a></td></tr><tr><td><div class="cart_pr_quan">'+data.quantity_text+': '+data.products[product_id].quantity+'</div><div class="cart_pr_price">'+data.products[product_id].final_price_format+'</div></td></tr></table></div>';
			}
			html_ret+= '<div class="cart_sum"><div class="cart_sum_text">'+data.sum_text+'</div><div class="cart_sum_pr">'+data.sum_format+'</div></div>';
			html_ret+= '<div class="cart_to_cart"><a href="'+data.cart_link+'">'+data.cart_text.toUpperCase()+'</a></div>';
			html_ret+= '<div class="cart_checkout"><a href="'+data.checkout_link+'">'+data.checkout_text.toUpperCase()+'</a></div>';
			$('#cart_overview').html(html_ret);
			if(typeof add_product != 'undefined')
				show_cart(add_product);
			else
				show_cart();
		}else if(typeof $('#cart_overview') != 'undefined' && $('#cart_overview').css('display') != 'none'){
			hide_cart();
			setTimeout(function(){$('#cart_overview').html('');},500);
		}
	});
}

function show_cart(add_product)
{
	if(typeof $('#cart_overview') != 'undefined' && $('#cart_overview').html() != ''){
		//doof wegen margin-top
		//$('#cart_overview').slideDown(500);
		$('#cart_overview').fadeIn(500);
	}else if(typeof $('#cart_overview') != 'undefined' && $('#cart_overview').html() == '')
		reset_cart(add_product);
	if(typeof add_product != 'undefined' && add_product == true && typeof $('#cart_overview') != 'undefined')
	{
		clearTimeout(event_cart_timer);
		event_cart_timer = 0;
		event_cart_timer = window.setTimeout(function(){hide_cart();},3000);
	}
}

function hide_cart()
{
	if(typeof $('#cart_overview') != 'undefined')
	{
		$('#cart_overview').fadeOut(500);
		event_cart_timer = 0;
	}
}

function set_in_use(in_use)
{
	$.getJSON('ajax_function.php?exe=9ee47d5bcf2166b5c17d27930d49c8e8&in_use='+in_use);
}

function get_brands(brand_select,loader,function_name)
{
	$(loader).css('display','inline');
	$.getJSON('ajax_function.php?exe=1f8634a557c64aa60e5bb306358ddcca', function(data){
		if(typeof data.error == 'undefined')
		{
			html_s = '<select name="'+$(brand_select).attr('name')+'" onchange="'+function_name+'" id="'+$(brand_select).attr('id')+'">';
			$.each(data, function() {
				if(typeof this.disable != 'undefined' && this.disable == true)
					html_s+= '<option value="'+this.value+'" disabled="disabled">'+this.text+'</option>';
				else
					html_s+= '<option value="'+this.value+'">'+this.text+'</option>';
			});
			html_s+= '</select>';
			$(brand_select+'_div').html(html_s);
		}
		$(loader).css('display','none');
	});
}

function get_modelserie(filter_select,second_select,loader,function_name)
{
	if(typeof $(second_select) != 'undefined')
	{
		$(loader).css('display','inline');
		if(typeof $(filter_select) != 'undefined')
			ext = '&'+$(filter_select).attr('name')+'='+$(filter_select).val();
		else
			ext = '';
		$.getJSON('ajax_function.php?exe=1dda6a5618842eeecc79a7b69f6c6b8d'+ext, function(data){
			if(typeof data.error == 'undefined')
			{
				html_s = '<select name="'+$(second_select).attr('name')+'" onchange="'+function_name+'" id="'+$(second_select).attr('id')+'">';
				$.each(data, function() {
					if(typeof this.disable != 'undefined' && this.disable == true)
						html_s+= '<option value="'+this.value+'" disabled="disabled">'+this.text+'</option>';
					else
						html_s+= '<option value="'+this.value+'">'+this.text+'</option>';
				});
				html_s+= '</select>';
				$(second_select+'_div').html(html_s);
			}
			$(loader).css('display','none');
		});
	}
}

function get_model(filter_select,filter_select2,model_select,loader,function_name)
{
	if(typeof $(model_select) != 'undefined')
	{
		$(loader).css('display','inline');
		ext = '';
		if(typeof $(filter_select) != 'undefined' && filter_select != false)
			ext+= '&'+$(filter_select).attr('name')+'='+$(filter_select).val();
		if(typeof $(filter_select2) != 'undefined' && filter_select2 != false)
			ext+= '&'+$(filter_select2).attr('name')+'='+$(filter_select2).val();
		
		$.getJSON('ajax_function.php?exe=6a52f9e3114286c030ecb3ab91dab424'+ext, function(data){
			if(typeof data.error == 'undefined')
			{
				html_s = '<select name="'+$(model_select).attr('name')+'" onchange="'+function_name+'" id="'+$(model_select).attr('id')+'">';
				$.each(data, function() {
					if(typeof this.disable != 'undefined' && this.disable == true)
						html_s+= '<option value="'+this.value+'" disabled="disabled">'+this.text+'</option>';
					else
						html_s+= '<option value="'+this.value+'">'+this.text+'</option>';
				});
				html_s+= '</select>';
				$(model_select+'_div').html(html_s);
			}
			$(loader).css('display','none');
		});
	}
}

function add_del_wishlist(p_id,div1)
{
	$.getJSON('ajax_function.php?exe=ede1708bafd0d98bc888c7471989b440&products_id='+p_id, function(data) {
		if(typeof data.wishlist != 'undefined')
		{
			$(div1).fadeTo(200,0);
			setTimeout(function(){
				if(data.wishlist == 'remove')
					$(div1).find("span").html(data.text);
				else if(data.wishlist == 'add')
					$(div1).find("span").html(data.text);
				$(div1).fadeTo(200,1);
			},200);
		}
	});
}

function add_review(pid,name,text,rateing)
{
	if(name != '' && text != '')
	{
		if(rateing != 0 && rateing != '')
		{
			$.post('ajax_function.php?exe=28a39881669734c917101e5d1cf425a9&products_id='+pid,{'name':name,'text': text,'rateing':rateing}, function(data) {
					show_info('ajax_function.php?products_id='+pid,'cdadecdd16067605ebebdbdd18e085c9');
			});
		}else
			alert('please select a star');
	}else
		alert('please fill fields');
}

function hover_star(star_id)
{
	for(i=1;i <= 5;i++)
	{
		if(i <= star_id)
			$('#review_star_'+i).attr('src','/customize/images/icons/star.png');
		else
			$('#review_star_'+i).attr('src','/customize/images/icons/star_grey.png');
	}
}

function set_star(star_id,obj)
{
	$(obj).val(star_id);
}

function hover_out_star(obj)
{
	for(i=1;i <= 5;i++)
	{
		if(typeof obj != 'undefined')
		{
			if(i <= obj.val())
				$('#review_star_'+i).attr('src','/customize/images/icons/star.png');
			else
				$('#review_star_'+i).attr('src','/customize/images/icons/star_grey.png');
		}else
			$('#review_star_'+i).attr('src','/customize/images/icons/star_grey.png');
	}
}

curr_slide = 'false';
curr_height = 0;
function slider()
{
	if(tab_is_focus == true)
	{
		max_sliders = $('.slider div').length;
		fade_time = 1000;
		if(max_sliders == 1){
			if(curr_slide == 'false')
			{
				$('.slider div').each(function(index) {
					curr_height = $(this,'img').height();
					$('.slider').css('height',curr_height);
					$(this).fadeIn(200);
					curr_slide = 'true';
					return false;
				});
			}
		}else if(max_sliders > 1){
			$('.slider div').each(function(index) {
				if(curr_slide == 'false')
				{
					curr_height = $(this,'img').height();
					$('.slider').css('height',curr_height);
					//$(this).css('display','inline');
					$(this).fadeIn(200);
					curr_slide = index;
					return false;
				}else if(parseInt(curr_slide)+1 == index){
					need_height = $(this,'img').height();
					ob = this;
					if(need_height < curr_height){
						$(ob).fadeIn(fade_time);
						setTimeout(function(){$('.slider').animate({height: need_height},300);},fade_time);
					}else{
						$('.slider').animate({height: need_height},300);
						setTimeout(function(){$(ob).fadeIn(fade_time);},300);
					}
					curr_height = need_height;
					curr_slide = index;
					return false;
				}else if(curr_slide == index){
					$(this).fadeOut(fade_time);
					if(parseInt(curr_slide)+1 == max_sliders)
						curr_slide = 0;
				}else if(parseInt(curr_slide)+1 == max_sliders && index == 0){
					need_height = $(this,'img').height();
					ob = this;
					if(need_height < curr_height){
						$(ob).fadeIn(fade_time);
						setTimeout(function(){$('.slider').animate({height: need_height},300);},fade_time);
					}else{
						$('.slider').animate({height: need_height},300);
						setTimeout(function(){$(ob).fadeIn(fade_time);},300);
					}
					curr_height = need_height;
				}
			});
		}
	}
}

function set_radio_boxes()
{
	$('div.radio_box').click(function() {
		$('input:radio',this).attr('checked','checked');
	});
	$('span.radio_box').click(function() {
		$('input:radio',this).attr('checked','checked');
	});
	$('tr.radio_box').click(function() {
		$('input:radio',this).attr('checked','checked');
	});
}

function set_check_boxes()
{
	$('div.check_box').click(function() {
			if($('input:checkbox',this).attr('checked') == 'checked')
				$('input:checkbox',this).removeAttr('checked');
			else
				$('input:checkbox',this).attr('checked','checked');
	});
	$('input:checkbox','div.check_box').click(function() {
			if($(this).attr('checked') == 'checked')
				$(this).removeAttr('checked');
			else
				$(this).attr('checked','checked');
	});
	$('span.check_box').click(function() {
		if($('input:checkbox',this).attr('checked') == 'checked')
			$('input:checkbox',this).removeAttr('checked');
		else
			$('input:checkbox',this).attr('checked','checked');
	});
	$('input:checkbox','span.check_box').click(function() {
			if($(this).attr('checked') == 'checked')
				$(this).removeAttr('checked');
			else
				$(this).attr('checked','checked');
	});
}

function check_col_exist()
{
	if(jQuery.trim($('#left_col').html()) == '')
		$('#left_col_td').css('display','none');
	if(jQuery.trim($('#right_col').html()) == '')
		$('#right_col_td').css('display','none');
}

function set_col_height()
{
		c_height = $('#left_col_td').height();
		if(typeof c_height != 'undefined' && c_height != 0)
			$('#left_col').css('min-height',c_height+'px');
		c_height = $('#right_col_td').height();
		if(typeof c_height != 'undefined' && c_height != 0)
			$('#right_col').css('min-height',c_height+'px');
}

event_footer_popup = 0;
function footer_popup(html_information)
{
	if(event_footer_popup == 0)
	{
		$('#footer_popup_text').html(html_information);
		$('#footer_popup').fadeIn(200);
		event_footer_popup = setTimeout(function(){
			$('#footer_popup').fadeOut(200);
			setTimeout(function(){$('#footer_popup_text').html('');},200);
			event_footer_popup = 0;
		},3000);
	}else{
		clearTimeout(event_footer_popup);
		$('#footer_popup_text').fadeOut(200);
		setTimeout(function(){
			$('#footer_popup_text').html(html_information);
			$('#footer_popup_text').fadeIn(200);
		},200);
		event_footer_popup = setTimeout(function(){
			$('#footer_popup').fadeOut(200);
			setTimeout(function(){$('#footer_popup_text').html('');},200);
			event_footer_popup = 0;
		},3000);
	}
}

var tab_is_focus = true;
function onBlur() {
	tab_is_focus = false;
};
function onFocus(){
	tab_is_focus = true;
};

function check_tab_focus()
{
	if (/*@cc_on!@*/false) { // check for Internet Explorer
		document.onfocusin = onFocus;
		document.onfocusout = onBlur;
	} else {
		window.onfocus = onFocus;
		window.onblur = onBlur;
	}
}

url_pattern = new Array();
url_pattern['d_id'] = 'printer_info.php?printer_brand_id=';
url_pattern['opt_p_id'] = 'optional_alternates.php?products_id=';
last_brand = '';
last_brand_int = '';
need_url = '';
function search_autocomplete()
{
	$(".input_search_field").keydown(function(){
		last_brand = '';
		last_brand_int = '';
	}).autocomplete('ajax_function.php?exe=0bf235399ffebcb65f30de24eac3f9b4', {
	dataType: 'json',
	minChars: 2,
	//cacheLength: 1,
	max: false,
	width: 200,
	selectFirst: false,
	parse: function(data) {
		var rows = new Array();
		var count = 0;
		if(typeof data.error == 'undefined')
		{
			need_url = data.url;
			$.each(data.live_search,function(index_b,value_b){
				last_brand_int = '';
				/*rows[count] = { data:index_b, value:index_b, result: index_b };
				count++;*/
				brand_length = value_b.length;
			  $.each(value_b,function(index,value){
					value.brand = index_b;
					value.brand_l = brand_length;
					if(last_brand_int == '' || last_brand_int != index_b)
			 		{
			 			last_brand_int = index_b;
			 			rows[count] = { data: value, value: '<div class="head">'+index_b+' ('+brand_length+')</div><div class="cont">'+value.text+'</div>', result: value.text };
					}else
						rows[count] = { data: value, value: '<div class="cont">'+value.text+'</div>', result: value.text };
					count++;
			  });
		  });
		}
	  return rows;
	},
 	formatItem: function(item) {
 		if(last_brand == '' || last_brand != item.brand)
 		{
 			last_brand = item.brand;
			return '<div class="head">'+item.brand+' ('+item.brand_l+')</div><div class="cont">'+item.text+'</div>';
		}else
			return '<div class="cont">'+item.text+'</div>';
	}
	}).result(function(event, item) {
		if(typeof item.d_id != 'undefined')
			location.href = need_url+url_pattern['d_id']+item.d_id;
		else if(typeof item.opt_p_id != 'undefined')
			location.href = need_url+url_pattern['opt_p_id']+item.opt_p_id;
	  	//location.href = item.url;
	});
}


//OLD jetzt search_autocomplete()
/*
i_search_runs = false;
function i_search(obj,i_search_div)
{
	if(i_search_runs == false)
	{
		i_val = $(obj).val();
		if(i_val.length >= 2)
		{
			$.getJSON('ajax_function.php?exe=0bf235399ffebcb65f30de24eac3f9b4&key='+escape(i_val), function(data) {
				
				i_search_runs = true;
				if(typeof data.error == 'undefined')
				{
					html_out = '';
					$.each(data,function(brand,b_value){
						html_out+= '<div class="head">'+brand+' ('+b_value.length+')</div>';
						$.each(b_value,function(){
							html_out+= '<div><a href="'+this.link+'">'+this.text+'</a></div>';
						});
					});
					//alert(html_out);
					$(i_search_div).html(html_out);
					$(i_search_div).fadeIn(100);
				}else
					$(i_search_div).fadeOut(200);
				i_search_runs = false;
			});
		}else
			$(i_search_div).fadeOut(200);
	}else
		setTimeout(function(){i_search(obj,i_search_div);},50)
}
*/

function pageflip()
{
	$("#pageflip").hover(function() { //On hover...
	$("#pageflip img , .msg_block").stop()
		.animate({ //Animate and expand the image and the msg_block (Width + height)
			width: '307px',
			height: '319px'
		}, 500);
	} , function() {
	$("#pageflip img").stop() //On hover out, go back to original size 50x52
		.animate({
			width: '50px',
			height: '52px'
		}, 220);
	$(".msg_block").stop() //On hover out, go back to original size 50x50
		.animate({
			width: '50px',
			height: '50px'
		}, 200); //Note this one retracts a bit faster (to prevent glitching in IE)
});
}
