/// 2009-08-06 NEW with cache!
content_loaded=Array();
newscript=Array();

function loadContent(contentid,contentparam,forcereload,outputid,lang)
	{
	if (content_loaded[contentid]!=1 || forcereload==1)
		{
		if (lang=='uk' || contentparam.indexOf('lang=uk')!=-1)
			{
			loading_text='Loading...';
			}
		else if (lang=='de' || contentparam.indexOf('lang=de')!=-1)
			{
			loading_text='Loading...';
			}
		else
			{
			loading_text='Betöltés...';
			}
		document.getElementById('content_'+contentid).innerHTML='<br/><br/><center>'+loading_text+'</center>';

		content_loaded[contentid]=1;
		newscript[contentid]=document.createElement("script");
		outputparam=outputid ? '&outputid='+outputid : '';
		langparam=lang ? '&lang='+lang : '';
		newscript[contentid].src='/inc/functions/load_content.php?' + (contentparam.indexOf('contentid')==-1 ? 'contentid='+contentid+outputparam+langparam : '') + contentparam + '&nocache=' + nocache;
		document.getElementsByTagName("body")[0].appendChild(newscript[contentid]);
		}

	return true;
	}


function openwindow(pageurl,width,height,scroll,winname) 
	{
	scroll=scroll!='no' ? 'yes' : 'no';
	winname=winname ? winname : '_blank';
	if (width || height)
		{
		posleft=(screen.width-width)/2;
		postop=(screen.height-height)/2;
	   if (0>postop) postop=0; 
	   if (0>posleft) posleft=0;
		pos=',toolbar=no,location=no,directories=no,menubar=no,status=no,left='+posleft+',top='+postop+',width='+width+',height='+height;
	   }
	  else
	  	{
	  	pos='';
	  	}

	window.open(pageurl,winname,'scrollbars='+scroll+pos);
	}



function isEmail(str)
	{
	var supported = 0;
	if (window.RegExp)
		{
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
		}
	if (!supported) return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
	}



function formatNum(num,dec)
	{
	if (isNaN(num)) num = 0;
	num = (num.toFixed(dec)).toString();
	if (dec)
		{
		var numInt = num.substr(0,(num.length-dec-1));
		var numDec = num.substr(num.length-dec,dec);
		}
	else
		{
		var numInt = num;
		var numDec = '';
		}
	for (var i = 0; i <= Math.floor((numInt.length-1)/3)-i; i++)
	numInt = numInt.slice(0,-(4*i+3))+' '+numInt.slice(-(4*i+3));
	while (numDec.length<dec)
	numDec += "0";
	return numInt+(dec ? ',' : '')+numDec;
	}



function backtoNum(num)
	{
	numConv=parseFloat((num.replace(/ /g,'')).replace(/,/g,'.'));
	return (isNaN(numConv) ? 0 : numConv);
	}



function set_humancheck(formobj)
	{
	var d=new Date();
	formobj.value=d.getTime();
	}



function show_samples(type)
	{
	openwindow('/samples/'+type+'.php?', '810','800','yes','no','no');
	void(0);
	}



function calc_price(service_id, service_qty1, service_qty2)
	{
	document.MainForm['services['+service_id+'][qty1]'].value=service_qty1;

	if (document.MainForm['services['+service_id+'][qty2]'])
		{
		document.MainForm['services['+service_id+'][qty2]'].value=service_qty2;
		qty2_object=document.getElementById(service_id+'_qty2');
		document.MainForm['services['+service_id+'][price]'].value=qty2_object[qty2_object.selectedIndex].getAttribute('price');
		}

	service_price=document.MainForm['services['+service_id+'][price]'].value;
	service_vatbase=service_price*service_qty1*service_qty2;

	document.MainForm['services['+service_id+'][vatbase]'].value=service_vatbase;

	document.getElementById('price_'+service_id).innerHTML=formatNum(service_vatbase, 0);
	}



function calc_total()
	{
	total=0;
	services_list='<table class="services_list"><col style="width:250px;"><col style="width:65px;"><col style="width:70px;"><col style="width:7px;"><col style="width:70px;"><col style="width:7px;"><col style="width:75px;">';
	for (i=0;i<document.MainForm.elements.length;i++)
		{
		field_name=document.MainForm.elements[i].name;
		if (field_name.indexOf('services[')!=-1 && field_name.indexOf('[name]')!=-1)
			{
			field_id=field_name.substring(field_name.indexOf('services[')+9, field_name.indexOf(']'));
			price=backtoNum(document.getElementById('price_'+field_id).innerHTML);
			total+=price;
			if (price!=0)
				{
				if (document.MainForm['services['+field_id+'][qty2]'] && document.MainForm['services['+field_id+'][qty2]'].value>0)
					{
					service_qty2_text=document.MainForm['services['+field_id+'][qty2]'].value + '&nbsp;&nbsp;x&nbsp;&nbsp;';
					}
				else
					{
					service_qty2_text='';
					}
				services_list += '<tr><td>' + document.MainForm['services['+field_id+'][name]'].value + '</td><td style="text-align: right;">' + service_qty2_text + formatNum(backtoNum(document.MainForm['services['+field_id+'][qty1]'].value), 0) + '</td><td>' + document.MainForm['services['+field_id+'][unit]'].value + '</td><td>x</td><td style="text-align: right;">' + formatNum(backtoNum(document.MainForm['services['+field_id+'][price]'].value), 0) + ' Ft</td><td>=</td><td style="text-align: right;">' + formatNum(backtoNum(document.MainForm['services['+field_id+'][vatbase]'].value), 0) + ' Ft</td></tr>';
				}
			}
		}
	document.getElementById('price_total').innerHTML=formatNum(total, 0);
	document.MainForm.price_total_net.value=total;
	document.MainForm.price_total_gross.value=total*1.25;
	if (total!=0)
		{
		services_list += '<tr><td colspan="7"><hr></td></tr>';
		services_list += '<tr><td style="padding: 4px 4px 0px 4px;">NETTÓ ÖSSZESEN:</td><td colspan="5" style="padding: 4px 4px 0px 4px;"></td><td style="padding: 4px 4px 0px 4px; text-align: right;">' + formatNum(total, 0) + ' Ft</td></tr>';
		services_list += '<tr><td style="padding: 0px 4px 0px 4px;">+25% ÁFA:</td><td colspan="5" style="padding: 0px 4px 0px 4px;"></td><td style="padding: 0px 4px 0px 4px; text-align: right;">' + formatNum(total*0.25, 0) + ' Ft</td></tr>';
		services_list += '<tr><td style="padding: 0px 4px 0px 4px;"><b>ÖSSZESEN:</b></td><td colspan="5" style="padding: 0px 4px 0px 4px;"></td><td style="padding: 0px 4px 0px 4px; text-align: right;"><b>' + formatNum(total*1.25, 0) + ' Ft</b></td></tr>';
		services_list += '</table>';
		}
	else
		{
		services_list += '</table>';
		services_list += 'Még nem választott szolgáltatásokat!';
		}
	document.getElementById('content_services_list').innerHTML=services_list;
	document.MainForm.services_list_html.value=encodeURIComponent(services_list);
	}



function service_change_qty2(service_id)
	{
	service_qty1=document.MainForm['services['+service_id+'][qty1]'].value;
	service_qty2=document.MainForm[service_id+'_qty2'][document.MainForm[service_id+'_qty2'].selectedIndex].value;
	calc_price(service_id, service_qty1, service_qty2);
	calc_total();
	}



function service_checkbox(service_id)
	{
	if (document.getElementById(service_id).checked)
		{
		calc_price(service_id, 1, 1);
		}
	else
		{
		calc_price(service_id, 0, 0);
		}
	calc_total();
	}



function service_checkbox_email_hu(service_id, service_subtype)
	{
	if (service_id==service_subtype+'_email_hu_all')
		{
		checked_new=document.getElementById(service_subtype+'_email_hu_all').checked;
		document.getElementById(service_subtype+'_email_hu_budapest').checked=checked_new;
		document.getElementById(service_subtype+'_email_hu_county_capitals').checked=checked_new;
		document.getElementById(service_subtype+'_email_hu_other').checked=checked_new;
		}
	else if (!document.getElementById(service_id).checked)
		{
		document.getElementById(service_subtype+'_email_hu_all').checked=0;
		}

	service_qty1 = 0;
	service_qty1 += document.getElementById(service_subtype+'_email_hu_budapest').checked ? backtoNum(document.getElementById(service_subtype+'_email_hu_budapest').getAttribute('quantity')) : 0;
	service_qty1 += document.getElementById(service_subtype+'_email_hu_county_capitals').checked ? backtoNum(document.getElementById(service_subtype+'_email_hu_county_capitals').getAttribute('quantity')) : 0;
	service_qty1 += document.getElementById(service_subtype+'_email_hu_other').checked ? backtoNum(document.getElementById(service_subtype+'_email_hu_other').getAttribute('quantity')) : 0;

	if (document.getElementById(service_subtype+'_email_hu_qty2'))
		{
		service_qty2_object=document.getElementById(service_subtype+'_email_hu_qty2');
		service_qty2 = service_qty2_object[service_qty2_object.selectedIndex].value;
		}
	else
		{
		service_qty2 = 1;
		}

	calc_price(service_subtype+'_email_hu', service_qty1, service_qty2);

	calc_total();
	}



function service_checkbox_email_foreign(service_id, service_subtype)
	{
	if (service_id==service_subtype+'_email_foreign_all')
		{
		checked_new=document.getElementById(service_subtype+'_email_foreign_all').checked;
		for(i=0;i<email_foreign_countries_count;i++)
			{
			document.getElementById(service_subtype+'_email_foreign['+email_foreign_countries[i]+']').checked=checked_new;
			}
		}
	else if (!document.getElementById(service_id).checked)
		{
		document.getElementById(service_subtype+'_email_foreign_all').checked=0;
		}

	service_qty1 = 0;
	for(i=0;i<email_foreign_countries_count;i++)
		{
		obj=document.getElementById(service_subtype+'_email_foreign['+email_foreign_countries[i]+']');
		service_qty1 += obj.checked ? backtoNum(obj.getAttribute('quantity')) : 0;
		}

	if (document.getElementById(service_subtype+'_email_foreign_qty2'))
		{
		service_qty2_object=document.getElementById(service_subtype+'_email_foreign_qty2');
		service_qty2 = service_qty2_object[service_qty2_object.selectedIndex].value;
		}
	else
		{
		service_qty2 = 1;
		}

	calc_price(service_subtype+'_email_foreign', service_qty1, service_qty2);

	calc_total();
	}



function service_select(service_id)
	{
	service_object=document.getElementById(service_id);
	if (document.getElementById(service_id+'_qty2'))
		{
		qty2_object=document.getElementById(service_id+'_qty2');
		qty2=qty2_object[qty2_object.selectedIndex].value;
		}
	else
		{
		qty2=1;
		}

	calc_price(service_id, service_object[service_object.selectedIndex].value, qty2);

	calc_total();
	}



payment='';
function selectPayment()
	{
	if (payment!='') document.getElementById('payment_'+payment).style.display='none';
	payment=document.getElementById('payment').value;
	if (payment!='') document.getElementById('payment_'+payment).style.display='';
	}



function maskTaxno(objInput, e)
	{
	e = e || window.event;
	ch = e.which || e.keyCode;

	if ((objInput.value.length==8 || objInput.value.length==10) && (ch!=45)) objInput.value=objInput.value+'-';
	}


nocache=1;
function login(action)
	{
	if (action=='register')
		{
		loadContent('login_form','&action='+action+'&email='+document.MainForm.email.value+'&pass='+document.MainForm.pass.value, 1);
		}
	else if (action=='login_done')
		{
		loadContent('login_form','&action='+action+'&email='+document.MainForm.email.value+'&pass='+document.MainForm.pass.value, 1);
		}
	}

function makeHomePage(object)
	{
	object.style.behavior='url(#default#homepage)';
	object.setHomePage('http://b2b.utazasiiroda.hu');
	}


function SubmitOrderForm()
	{
	var msg = '';

	if (document.MainForm.services_list_html.value.length < 1)
		{
		msg='Egyetlen szolgáltatást se választott!';
		}
	else
		{
		if (document.MainForm.surname) 
			{
			if (!isEmail(document.MainForm.email.value))   {msg=msg+'  - Az Ön e-mail címe\n';}
			if (document.MainForm.pass.value.length < 1)   {msg=msg+'  - Kérjük adjon meg egy jelszót is, hogy később újra hozzáférhessen adataihoz.\n';}
			if (document.MainForm.pass.value.length >= 1 && document.MainForm.pass.value.length < 5)   {msg=msg+'  - A jelszó, minimum 5, maximum 16 karakter hosszú lehet.\n';}
			if (document.MainForm.pass.value.search(/[^a-zA-Z0-9\.\_\-]/gi) != -1 )   {msg=msg+'  -  A jelszó csak ékezet nélküli betüket, számokat, kötőjelet, aláhúzás jelet és pontot tartalmazhat!\n';}
			if (document.MainForm.surname.value.length < 2)   {msg=msg+'  - Vezetéknév\n';}
			if (document.MainForm.name.value.length < 2)   {msg=msg+'  - Keresztnév\n';}
			if (document.MainForm.tel_prefix.value.length < 1)   {msg=msg+'  - Telefon körzet\n';}
			if (document.MainForm.tel_number.value.length < 2)   {msg=msg+'  - Telefonszám\n';}
			if (document.MainForm.company_name.value.length < 2)   {msg=msg+'  - Cégnév\n';}
			if (document.MainForm.taxno.value.length < 13)   {msg=msg+'  - Adószám\n';}
			if (document.MainForm.pcode.value.length < 1)   {msg=msg+'  - Irányítószám\n';}
			if (document.MainForm.city.value.length < 2)   {msg=msg+'  - Város\n';}
			if (document.MainForm.address.value.length < 2)   {msg=msg+'  - Utca, házszám\n';}

			if (document.MainForm.payment.selectedIndex <= 1)
				{
				msg=msg+'  - Kérjük válassszon fizetési módot!\n';
				}
			else if (document.MainForm.payment.selectedIndex == 3)
				{
				msg=msg+'  - Hitelkártyás fizetési módot még nem választhat!\n';
				}

			if (!document.MainForm.read_terms.checked)   {msg=msg+'  - Szolgáltatásaink igénybevétele előtt kérjük szíveskedjen elfogadni általános szerződési feltételeinket!\n';}

			msg=msg!='' ? 'Kérjük ellenörizze az alábbiakat:\n\n'+msg : '';
			}
		else
			{
			msg='Kérjük, hogy az ELÉRHETŐSÉGEK ÉS SZÁMLÁZÁSI ADATOK boxban választásával jelezze, hogy járt-e már nálunk, s szükség esetén adja meg adatait!';
			}
		}

	if (msg != '')
		{
		msg=msg+'\n\n------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n\nAmennyiben fentiekkel kapcsolatban bármilyen kérdése van, munkaidőben a +36-1-3821660 telefonszámon kollegáink szívesen segítenek!\n\n';
		alert(msg);
		}
	else 
		{
		set_humancheck(document.MainForm.humancheck);
		document.MainForm.submit();
		}
	}
