
var paused_imgs = Array();

function do_submit(form_id)

{

  document.getElementById(form_id).submit();

  return false;

}



function set_external_links()

{

  if (!document.getElementsByTagName) {

    return;

  }

  var anchors = document.getElementsByTagName('a');

  for (var i = 0; i < anchors.length; i++) {

   var anchor = anchors[i];

   if (anchor.getAttribute('href') && anchor.getAttribute('rel') == 'external') {

     anchor.target = "_blank";

   }

  }

}

window.onload = set_external_links;

jQuery(document).ready(function(){
			jQuery("a[rel^='prettyPhoto']").prettyPhoto();
		});


jQuery(document).ready(function() {							// BEGIN LOAD

$('#prod_frm').bind('change',function(e){
calculate_price('prod_frm');
});
/*
$('a.simple_pic').zoomimage({
    controls:false,
    shadow: 7,
    caption:false
});

$('a.gallery_img').zoomimage({
	controlsTrigger: 'mouseover',
	className: 'custom',
	shadow: 40,
	controls: true,
	opacity: 1,
	centered: true,
	hideSource: true,
	beforeZoomIn: function(boxID) {
		$('#' + boxID)
			.find('img')
			.css('opacity', 0)
			.animate(
				{'opacity':1},
				{ duration: 500, queue: false }
			);
	},
	beforeZoomOut: function(boxID) {
		$('#' + boxID)
			.find('img')
			.css('opacity', 1)
			.animate(
				{'opacity':0},
				{ duration: 500, queue: false }
			);
	}

});

$('a.gallery_ref_img').zoomimage({
	controlsTrigger: 'mouseover',
	className: 'custom',
	shadow: 40,
	controls: true,
	opacity: 1,
	centered: true,
	hideSource: true,
	beforeZoomIn: function(boxID) {
		$('#' + boxID)
			.find('img')
			.css('opacity', 0)
			.animate(
				{'opacity':1},
				{ duration: 500, queue: false }
			);
	},
	beforeZoomOut: function(boxID) {
		$('#' + boxID)
			.find('img')
			.css('opacity', 1)
			.animate(
				{'opacity':0},
				{ duration: 500, queue: false }
			);
	}

});

$.fn.cycle.defaults.speed   = 300;
$.fn.cycle.defaults.timeout = 300;
*/
/*$(".p_img_slideshow").cycle();
$(".p_img_slideshow").cycle('pause');*/









$(".p_img_slideshow").bind('mouseenter', function(e){    
    $(e.target).cycle('resume');     
});

$(".p_img_slideshow").bind('mouseleave', function(e){      
    $(e.target).cycle('pause');
});														

var ml = $("#mail_link");
if(ml)
{
    try{
    mstr = $(ml).attr('href');
    mstr = mstr.replace('[kukac]', '@');
    mstr = mstr.replace('[pont]', '.');
    $(ml).attr('href', mstr);
    }
    catch(exc){}
}
var ml = $("#mail_link2");
if(ml)
{
    try{
    mstr = $(ml).attr('href');
    mstr = mstr.replace('[kukac]', '@');
    mstr = mstr.replace('[pont]', '.');
    $(ml).attr('href', mstr);
    }
    catch(exc){}
}

$(".choose_sample").bind('click', function (e){

	var targ = e.target;
	var type;
	if($(targ).hasClass('wood'))
		type = 'wood';
	else if($(targ).hasClass('ral'))
		type = 'ral';
	else if($(targ).hasClass('plexi'))
		type = 'plexi';
	else if($(targ).hasClass('textile'))
		type = 'textile';
	else 
		type = 'leather';
		
	var t_id = e.target.id;
	var param1 = 'ch_' + t_id.substring(7);
	var param2 = 'c_id_' + t_id.substring(7);	
	//var param3 = $('#' + param1).attr('class');
	var param3 = type;
	var size;
	switch(type)
	{
		case 'leather' : size = 'width=509,height=416';break;
		case 'ral' : size = 'width=948,height=670';break;
		case 'plexi' : size = 'width=330,height=140';break;
		case 'wood' : size = 'width=900,height=780';break;
		case 'textile' : size = 'width=820,height=326';break;
	}
	
	//alert(param1 + ' ' + param2 + ' ' + param3);	
	childWindow = window.open('/mintak/' + param1 + '/' + param2 + '/' + param3,'sample_window',size + ',status=no,menubar=no,location=no');
    if (childWindow.opener == null)
    { 
        childWindow.opener = self;
    }
    
});

});																	// END LOAD

function remove_paused(d_id)
{
    var new_array = Array();
    j = 0;
    for(var i = 0; i < paused_imgs.length; i++)
    {
        if(paused_imgs[i] != d_id)
        {
            new_array[j++] = paused_imgs[i];            
        }
    }  
    window.console.log('elvileg removed '+d_id);
    paused_imgs = new_array;
}

function is_paused(d_id)
{
    var paused = false;
    for(var i = 0; i < paused_imgs.length; i++)
    {
        if(paused_imgs[i] == d_id)
        {
            window.console.log('is_paused '+d_id);
            return true;
        }
    }    
    return false;
}

function pause_img(d_id)
{
    var added = false;
    for(var i = 0; i < paused_imgs.length; i++)
    {
        if(paused_imgs[i] == d_id)
        {
            added = true;
            break;
        }
    }
    window.console.log('elvileg most pózolja '+d_id);
    if(!added)
    {
        paused_imgs[paused_imgs.length] = d_id;
    }
}

function print_r(obj, maxdepth, depth)
			{
				maxdepth = maxdepth || 1;
				depth = depth || 0;
				var res = '';
				for (var key in obj) {
					inner_obj = eval('obj.' + key);
					for(i = 0; i < depth; i++)
						res += "\t";
					
				    res += key + ": " + inner_obj + " (" + typeof(inner_obj) + ")\n";
									    
				    if(typeof(inner_obj) == 'object' && inner_obj != null && depth <= maxdepth)
				    {												
				    	try{
						//res += print_r(inner_obj, maxdepth, depth++);
						} catch(err) {
						//res += err;
						}
					}
				}
				return res;
			}

function set_visible(id, title_arrow_id)

{

	if (document.getElementById(id).className=='career_content')

	{

		document.getElementById(id).className='career_content_visible'

		document.getElementById(title_arrow_id).className='career_top_right_up'

	}

	else

	{

		document.getElementById(id).className='career_content'

		document.getElementById(title_arrow_id).className='career_top_right'

	}

			

	return false;

}

var actual_sp = 0;

function scroll_small_pics(v, max)
{
    //alert(actual_sp);
    if( actual_sp + 2 + v <= max &&  actual_sp + v >= 0)
    {
        actual_sp += v;
        for(i = 0; i <= max; i++)
        {
            if(i >= actual_sp && i <= actual_sp + 2)
            {
                if($('#sp' + i).hasClass('hidden'))
                {
                    $('#sp' + i).removeClass('hidden');
                }
            }
            else
            {
                if(!$('#sp' + i).hasClass('hidden'))
                {
                    $('#sp' + i).addClass('hidden');
                }
            }
        }
    }
    return false;
}

function show_medium_image(image_key, max_key)
{
    for(i = 0; i <= max_key; i++)
    {
        if(i != image_key)
        {
            if(!$('#bp' + i).hasClass('hidden'))
            {
                $('#bp' + i).addClass('hidden');
                $('#bp' + i).attr('style', 'display:none');
            }
        }
        else
        {
            if($('#bp' + i).hasClass('hidden'))
            {
                $('#bp' + i).removeClass('hidden');
                $('#bp' + i).attr('style', 'display:block');
            }            
        }
    }
    return false;
}

function calculate_price()
{
	$("#unit_price").text('számítás alatt...');
	$("#unit_price2").text('számítás alatt...');
	$(".huf_price").text("...");
		
	var up = document.getElementById('unit_price');
		
    var sps = $("#prod_frm").serialize();    
	$.post($("#unit_price2").attr("rel"), sps,
		  function(data){
		  	if(data.result == 'ok')
		  	{
		    		$("#unit_price").text(data.unit_price);
		    		$("#unit_price2").text(data.unit_price);
		    		$("#tpr_span").text(data.sum_price);
		    		$(".huf_price").text(data.huf_unit_price);
		    		$("#huf_tpr_span").text(data.huf_sum_price);
		    }
		    else		// hibakezelés
		    {
				alert(data.result);
			}
		  }, "json");
	return false;
}

function check_selects()
{
    var sels = $(".select_1");
    for(i = 0; i < sels.length; i++)
    {
        if(sels[i].options.length == 1)
        {
            opt = sels[i].options[0];
            $(sels[i]).after('<input type="hidden" name="sizes[]" value="'+ opt.value +'" />');
            $(sels[i]).replaceWith(opt.innerHTML);
        }
    }
}

function check_accept(radioid, language)
{
    radio = document.getElementById(radioid);
    if(radio.checked)
        return true;
    if(language == 'hu')
    	alert('A továbblépéshez el kell fogadnia a rendelési feltételeket!');
    else
    	alert('In order to proceed you must accept terms and conditions.');
    return false;
}

function set_pay_type(num)
{
    if(num == 1)
    {
        $('.pay_type_bank').slideDown("slow");
        $('.pay_type_card').slideUp("slow");        
    }
    else
    {
        $('.pay_type_card').slideDown("slow");
        $('.pay_type_bank').slideUp("slow");        
    }
}

function copy_billing(chkbox)
{
    if(chkbox.checked)
    {
        copy_inputs_data();
        $('#bill_code').bind("change",copy_inputs_data);
        $('#bill_city').bind("change",copy_inputs_data);
        $('#bill_street').bind("change",copy_inputs_data);
    }
    else
    {
        $('#bill_code').unbind("change",copy_inputs_data);
        $('#bill_city').unbind("change",copy_inputs_data);
        $('#bill_street').unbind("change",copy_inputs_data);
    }
}

function copy_inputs_data()
{
    $('#data_8').attr('value',$('#bill_code').attr('value'));
    $('#data_9').attr('value',$('#bill_city').attr('value'));
    $('#data_10').attr('value',$('#bill_street').attr('value'));
}
/*
$().ready(function() {

    $("#login_form").validate();
    
    $("#login_form").validate({
		rules: {
			data_2: {
				required: true
			},
			data_1: {
				required: true,
				email: true
			}
		},
		messages: {
			data_2: {
				required: "Kérem írja be jelszavát!"
			},
			data_1: "Kérem szabályos e-mail címet írjon be!"
		}
	});
	
});
*/
function validate_form(frm_id, input_ids)
{
    
}

function show_shipping_block(chkbox)
{
    if(chkbox.checked)
    {
        $('#shipping_block').slideDown("slow");
    }
    else
    {
        $('#shipping_block').slideUp("slow");
    }
}

//---Hírlevél_Form_validátor---2009-08-11-----------------------------------------------START---

function ValidateForm(firstName, lastName, email, formName, checkArray){
	
	var firstNameID = document.getElementById(firstName);
	var lastNameID = document.getElementById(lastName);
	var emailID = document.getElementById(email);
	
	firstNameID.style.border="1px solid #B9B693";
	lastNameID.style.border="1px solid #B9B693";
	emailID.style.border="1px solid #B9B693";
	  		
	if ((firstNameID.value==null)||(firstNameID.value=="")){
		alert("Nem adta meg a vezetéknevét!");
		firstNameID.focus();
		firstNameID.style.border="1px solid red";
    return false;
	}
	
	if (Number(firstNameID.value) % 1 == 0){ 
		alert('A vezetéknév nem lehet csak szám formátumu!'); 
    firstNameID.select();
    firstNameID.focus();
    firstNameID.style.border="1px solid red";
    return false;
	}
	
	if ((lastNameID.value==null)||(lastNameID.value=="")){
		alert("Nem adta meg a keresztnevét!");
		lastNameID.focus();
		lastNameID.style.border="1px solid red";
		return false;
	}
	
	if (Number(lastNameID.value) % 1 == 0){ 
		alert('A keresztnév nem lehet csak szám formátumu!'); 
    lastNameID.select();
    lastNameID.focus();
    lastNameID.style.border="1px solid red";
    return false;
	}
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Nem adta meg az e-mail címét!");
		emailID.focus();
		emailID.style.border="1px solid red";
		return false;
	}
		
	if (email_check(emailID.value)==false){
		emailID.value="";
		emailID.focus();
		emailID.style.border="1px solid red";
		return false;
	}
		
	return do__submit(formName, checkArray);
}

function email_check(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Hibás e-mail cím formátum!");
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Hibás e-mail cím formátum!");
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Hibás e-mail cím formátum!");
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Hibás e-mail cím formátum!");
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Hibás e-mail cím formátum!");
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Hibás e-mail cím formátum!");
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Hibás e-mail cím formátum!");
		    return false;
		 }

 		 return true;					
	}


function do__submit(form_position, element_positions)
{
	if (!form_position) {
		var form_position = 0;
	}

	if (!element_positions) {
		var element_positions = new Array();
	}

	var form_elements = document.forms[form_position].elements.length;
	for (i = 0; i < form_elements; i++) {
		var current_value = document.forms[form_position].elements[i].value;
		if (in_array(i, element_positions) == true && (current_value.match(/^\s+$/) || current_value == '')) {
			alert('Nincs minden szükséges adat megadva!');
			return false;
		}
	}
	document.forms[form_position].submit();
	return false;	
}

function in_array(needle, haystack) {
		for (j = 0; j < haystack.length; ++j) {
			if (haystack[j] == needle) {
				return true;
			}
		}
		return false;
}

//---Hírlevél_Form_validátor---2009-08-11-----------------------------------------------END---

function CalculateTotal(frm) {
    var order_total = 0

    for (var i=0; i < frm.elements.length; ++i) {
        form_field = frm.elements[i]
        form_name = form_field.name
        if (form_name.substring(0,4) == "ITEM") {
            item_price = parseFloat(form_name.substring(form_name.lastIndexOf("_") + 1))
            item_quantity = parseInt(form_field.value)
            if (item_quantity >= 0) {
                order_total += item_quantity * item_price
                }
            }
        }
    document.getElementById('order_total').innerHTML=round_decimals(order_total, 2);
    }

function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
    }

function pad_with_zeros(rounded_value, decimal_places) {
    var value_string = rounded_value.toString()
    var decimal_location = value_string.indexOf(".")
    if (decimal_location == -1) {
        decimal_part_length = 0
        value_string += decimal_places > 0 ? "." : ""
        }
    else {
        decimal_part_length = value_string.length - decimal_location - 1
        }

    var pad_total = decimal_places - decimal_part_length
   
    if (pad_total > 0) {
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
    }

function show_delivery(is_checked)
{
	if (!is_checked)
	{
		$('#del_address').attr('class', 'hidden');
	}
	else
	{
	 	$('#del_address').attr('class', '');
	}
}

function show_delivery_dl(is_checked)
{
	if (!is_checked)
	{
		$('#del_deadline').attr('class', 'hidden');
	}
	else
	{
	 	$('#del_deadline').attr('class', '');
	}
}
