﻿$(function(){
	
	//initialize datepickers
	$(".datepicker").datepicker({
		minDate: new Date(),
		dateFormat: 'yy.mm.dd',
		showOn: 'both',
		buttonImage: '/img/calendar.png',
		buttonImageOnly: true,
		duration: 'normal',
		showAnim: 'fadeIn'
	});		   

	// custom selectboxes
	$("select").selectbox({
		animationSpeed: 100,
		listboxMaxSize: 8
	});

	//hide order forms on list page
	$(".listpage .orderform").hide();
	// toggle order forms of list page
	$(".details .submitdown").click(function(index,el) {
		$(this).parents(".contentbox").next("form").find(".orderform").slideToggle("fast");
	});

  $('.news_text').truncate({max_length: 180});
  
  setInterval("displaytime()", 1000);
});

function checkRequest(id) {
	if (MM_validateForm('arrive'+id,dict['js_erkezes'],'R','name'+id,dict['js_nev'],'R','phone'+id,dict['js_telefonszam'],'R','email'+id,dict['js_email_cim'],'RisEmail','code'+id,dict['js_ellenorzo_kod'],'R')) {
		document.getElementById('form'+id).submit();
	}
}

function MM_validateForm() {
  if (document.getElementById){
		var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
		for (i=0; i<(args.length-2); i+=3) {
			test=args[i+2];
			nm=args[i+1];
			val=document.getElementById(args[i]);
			if (val) {
				nm=args[i+1];
				if ((val=val.value)!="") {
					if (test.indexOf('isEmail')!=-1) { 
						p=val.indexOf('@');
						if (p<1 || p==(val.length-1)) errors+='- '+nm+' '+dict['js_must_contain_email']+'\n';
					}
				} else if (test.charAt(0) == 'R') errors += '- '+nm+' '+dict['js_is_required']+'\n'; 
			}
		}
		if (errors) alert(dict['js_errors_occured']+':\n'+errors);
		return (errors == '');
	}
}

function finishRequest() {
	$(function() {
		$("#dialog").attr("title",dict['js_erdeklodes']);
		$("#dialog").text(dict['js_request_thank_you']);
		$("#dialog").dialog({
			bgiframe: true,
			height: 140,
			modal: true,
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			}
		});
	});
}

var serverdate=new Date(currenttime);

function padlength(what) {
	var output=(what.toString().length==1)? "0"+what : what;
	return output;
}

function displaytime() {
	serverdate.setSeconds(serverdate.getSeconds()+1);
	$("#servertime").html(padlength(serverdate.getHours())+":"+padlength(serverdate.getMinutes()));
}