

function showDeliveryDataFields(){
	
	var data = $("input[@name='deliveryCheckbox']:checked").val();
	if( $("input[@name='deliveryCheckbox']:checked").val() == 'SAME'){
		$('#deliveryDatas').css("display","none");	
	}
	else{
		$('#deliveryDatas').css("display","block");
	}
     
}

function findelement(id){
    return document.all ? document.all(id) : document.getElementById ? document.getElementById(id) : null;
}

function isEmail(str) {
	// regular expression - t támogat-e a böngésző?
	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 && (str.indexOf(" ") < 0)
	&& (str.indexOf("á") < 0)
	&& (str.indexOf("é") < 0)
	&& (str.indexOf("í") < 0)
	&& (str.indexOf("ü") < 0)
	&& (str.indexOf("ű") < 0)
	&& (str.indexOf("ö") < 0)
	&& (str.indexOf("ő") < 0)
	&& (str.indexOf("ú") < 0)
	&& (str.indexOf("ó") < 0) );

	//ha támogatja
	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) && (str.indexOf(" ") < 0)
	&& (str.indexOf("á") < 0)
	&& (str.indexOf("é") < 0)
	&& (str.indexOf("í") < 0)
	&& (str.indexOf("ü") < 0)
	&& (str.indexOf("ű") < 0)
	&& (str.indexOf("ö") < 0)
	&& (str.indexOf("ő") < 0)
	&& (str.indexOf("ú") < 0)
	&& (str.indexOf("ó") < 0));
}

function arSzamol() {
	var productdb = [];
	productdb[0] = findelement('productdb0').value;
	productdb[1] = findelement('productdb1').value;
	productdb[2] = findelement('productdb2').value;
	productdb[3] = findelement('productdb3').value;
	productdb[4] = findelement('productdb4').value;
	productdb[5] = findelement('productdb5').value;
	/*productdb[6] = findelement('productdb6').value;
	productdb[7] = findelement('productdb7').value;
	productdb[8] = findelement('productdb8').value;
	productdb[9] = findelement('productdb9').value;*/
	var price = [];
	price[0] = findelement('price0').value;
	price[1] = findelement('price1').value;
	price[2] = findelement('price2').value;
	price[3] = findelement('price3').value;
	price[4] = findelement('price4').value;
	price[5] = findelement('price5').value;
	/*price[6] = findelement('price6').value;
	price[7] = findelement('price7').value;
	price[8] = findelement('price8').value;
	price[9] = findelement('price9').value;*/
	ar = 0;
	if (productdb[0] != "" || productdb[0] != null || !isNaN(productdb[0]))
	{
		ar15 = productdb[0] * price[0];
		ar += ar15;
		

	}
	if (productdb[1] != "" || productdb[1] != null || !isNaN(productdb[1]))
	{
		ar30 = productdb[1] * price[1] ;
		ar += ar30;
	}
	if (productdb[2] != "" || productdb[2] != null || !isNaN(productdb[2]))
	{
		ar60 = productdb[2] * price[2];
		ar += ar60;
	}
	if (productdb[3] != "" || productdb[3] != null || !isNaN(productdb[3]))
	{
		arsl15 = productdb[3] * price[3];
		ar += arsl15;
	}
	if (productdb[4] != "" || productdb[4] != null || !isNaN(productdb[4]))
	{
		arsl45 = productdb[4] * price[4];
		ar += arsl45;
	}
	if (productdb[5] != "" || productdb[5] != null || !isNaN(productdb[5]))
	{
		arsl75 = productdb[5] * price[5];
		ar += arsl75;
	}
	/*if (productdb[6] != "" || productdb[6] != null || !isNaN(productdb[6]))
	{
		ar50_15 = productdb[6] * price[6];
		ar += ar50_15;
	}
	if (productdb[7] != "" || productdb[7] != null || !isNaN(productdb[7]))
	{
		ar50_30 = productdb[7] * price[7];
		ar += ar50_30;
	}
	if (productdb[8] != "" || productdb[8] != null || !isNaN(productdb[8]))
	{
		ar50_45 = productdb[8] * price[8];
		ar += ar50_45;
	}
	if (productdb[9] != "" || productdb[9] != null || !isNaN(productdb[9]))
	{
		ar50_60 = productdb[9] * price[9];
		ar += ar50_60;
	}*/
	
	if (isNaN(ar))
	{
		alert ("A csomag mezőbe csak számokat írhat!");
		ar = 0;
	}
	findelement('osszar').value = ar;
    
    var discount = 0;
    if( ar >= 15000 && ar < 30000 ) {
        discount = ar*0.1;
    }
    if( ar >= 30000 && ar < 50000 ) {
        discount = ar*0.15;
    }
    if( ar >= 50000 ) {
        discount = ar*0.2;
    }
    
    findelement('discount').value = discount;

}

function ujr_formEllenoriz(){
	error = 0;
	emailAddress = findelement('email').value;
	nev = findelement('nev').value;
	nev = trim(nev);
	
	var productdb = [];
	productdb[0] = findelement('productdb0').value;
	productdb[1] = findelement('productdb1').value;
	productdb[2] = findelement('productdb2').value;
	productdb[3] = findelement('productdb3').value;
	productdb[4] = findelement('productdb4').value;
	productdb[5] = findelement('productdb5').value;
	
	/*productdb[6] = findelement('productdb6').value;
	productdb[7] = findelement('productdb7').value;
	productdb[8] = findelement('productdb8').value;
	productdb[9] = findelement('productdb9').value;*/
	ok_submit = findelement('ok_submit').value;
	irsz = findelement('irsz').value;
	irsz = trim(irsz);
	varos = findelement('varos').value;
	varos = trim(varos);
	cim = findelement('cim').value;
	cim = trim(cim);
	tel = findelement('tel').value;
	mobil = findelement('mobil').value;
	korzet = findelement('korzet').value;
	ok_submit = findelement('ok_submit').value;

	// telefonszám ellenőrzés
	if ((tel == null || tel == '' || tel == ' ' || korzet == null || korzet == '' || korzet ==' ') && (mobil == null || mobil == '' || mobil ==' ') && error == 0)
	{
		error = 9;
	}
	if ((isNaN(tel) || isNaN(korzet)) && error == 0) {
			error = 7;

		}
	if (isNaN(mobil) && error == 0) {
		error = 8;
	}
	// telefon vége

	// név és címadatok
	if ((nev == "" || nev == null || nev.length == 0) && error == 0)
	{
		error = 1;
	}
	 if ((irsz == '' || irsz == null || isNaN(irsz) || irsz == ' ') && error == 0) {
		error = 2;
	}
	 if ( (varos == '' || varos == ' ' || !isNaN(varos))  && error == 0) {
		error = 3;
	}
	 if ( (cim == '' || cim == ' ')  && error == 0) {
		error = 4;
	}
	// vége név és cím


	// email ha van ellenőrzése
	if (emailAddress!='' && emailAddress !=' ' && emailAddress != null && error == 0){
        if ( !isEmail(emailAddress) && error == 0) {
			error = 5;
		}
	}
	
	// email vége

	//termék ellenőrzés 
	
	termekures = 0;
    /*for (var i=0; i < 10; i++){*/
    for (var i=0; i < 6; i++){
        if (productdb[i] == "" || productdb[i] == null || isNaN(productdb[i]) || productdb[i] == 0 ) { 
	        termekures += 1;
	        productdb[i].value = 0;
	         
	    }      
    }
	

    /*if (termekures == 10 && error == 0){*/
	if (termekures == 6 && error == 0){ 
	    error = 6; 
	} 
	//termék vége



	switch(error)
	{

		case 1:
			alert ("A 'Megrendelő neve' mező kitöltése kötelező!");
			break;
		case 2:
			alert("A 'Irányítószám' mező helyes kitöltése kötelező!");
			break;
		case 3:
			alert("A 'Város' mező helyes kitöltése kötelező!");
			break;
		case 4:
			alert("A 'Szállítási cím' mező helyes kitöltése kötelező!");
			break;
		case 5:
			alert("Kérem létező e-mail címet adjon meg!");
			break;
		case 6:
			alert("A megrendelés elküldéséhez adja, hogy mely termékből hány csomagot kíván rendelni!");
			break;
		case 7:
			alert("Kérem helyes formátumban töltse ki a 'Telefonszám' mezőt!");
			break;
		case 8:
			alert("Kérem helyes formátumban töltse ki a 'Mobiltelefon' mezőt!");
			break;
		case 9:
			alert("Kérem legalább egyet töltsön ki a 'Telefonszám' és 'Mobiltelefon' mezők közül!");
			break;
		case 0:
			ok_submit = true;
			findelement('megrendeloiadatok').submit();
	}



}
function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function torzsr_formEllenoriz(){

	error = 0;
	nev = findelement('nev').value;
	nev = trim(nev);
	torzsid = findelement('torzsid').value;
	torzsid = trim(torzsid);
	
	var productdb = [];
	productdb[0] = findelement('productdb0').value;
	productdb[1] = findelement('productdb1').value;
	productdb[2] = findelement('productdb2').value;
	productdb[3] = findelement('productdb3').value;
	productdb[4] = findelement('productdb4').value;
	productdb[5] = findelement('productdb5').value;
	/*productdb[6] = findelement('productdb6').value;
	productdb[7] = findelement('productdb7').value;
	productdb[8] = findelement('productdb8').value;
	productdb[9] = findelement('productdb9').value;*/
	ok_submit = findelement('ok_submit').value;
	ok_submit = findelement('ok_submit').value;
	//megrendeloiadatok = findelement('megrendeloiadatok')

	if ((nev == "" || nev == null || nev.length == 0) && error == 0)
	{
		error = 1;
	}
	if ((torzsid == "" || torzsid == null || isNaN(torzsid) || torzsid.length != 6) && error == 0)
	{
		error = 2;
	}
	termekures = 0;
    /*for (var i=0; i < 10; i++){*/
	for (var i=0; i < 6; i++){
        if (productdb[i] == "" || productdb[i] == null || isNaN(productdb[i]) || productdb[i] == 0 ) { 
	        termekures += 1;
	        productdb[i].value = 0;
	        
	    }      
    }
    /*if (termekures == 10 && error == 0)*/
	if (termekures == 6 && error == 0)
	{
		error = 3;
	}
    else {
    
    }


	switch(error)
	{	case 1:
			alert ("A 'Megrendelő neve' mező kitöltése kötelező!");

			break;
		case 2:
			alert("A 'Törzsvásárlói azonosító' hibás'");

			break;
		case 3:
			alert("A megrendelés elküldéséhez adja, hogy mely termékből hány csomagot kíván rendelni!");
			break;
		case 0:
			ok_submit = true;
			findelement('megrendeloiadatok').submit();
	}

}
