
var picpath = 'http://kamionshopkft.hu/pic/';

function htmlspecialchars (string, quote_style, charset, double_encode) {
    // Convert special characters to HTML entities  
    // 
    // version: 912.1315
    // discuss at: http://phpjs.org/functions/htmlspecialchars    // +   original by: Mirek Slugen
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Nathan
    // +   bugfixed by: Arno
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)    // +    bugfixed by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Ratheous
    // +      input by: Mailfaker (http://www.weedem.fr/)
    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
    // +      input by: felix    // +    bugfixed by: Brett Zamir (http://brett-zamir.me)
    // %        note 1: charset argument not supported
    // *     example 1: htmlspecialchars("<a href='test'>Test</a>", 'ENT_QUOTES');
    // *     returns 1: '&lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt;'
    // *     example 2: htmlspecialchars("ab\"c'd", ['ENT_NOQUOTES', 'ENT_QUOTES']);    // *     returns 2: 'ab"c&#039;d'
    // *     example 3: htmlspecialchars("my "&entity;" is still here", null, null, false);
    // *     returns 3: 'my &quot;&entity;&quot; is still here'
    var optTemp = 0, i = 0, noquotes= false;
    if (typeof quote_style === 'undefined' || quote_style === null) {        quote_style = 2;
    }
    string = string.toString();
    if (double_encode !== false) { // Put this first to avoid double-encoding
        string = string.replace(/&/g, '&amp;');    }
    string = string.replace(/</g, '&lt;').replace(/>/g, '&gt;');
 
    var OPTS = {
        'ENT_NOQUOTES': 0,        'ENT_HTML_QUOTE_SINGLE' : 1,
        'ENT_HTML_QUOTE_DOUBLE' : 2,
        'ENT_COMPAT': 2,
        'ENT_QUOTES': 3,
        'ENT_IGNORE' : 4    };
    if (quote_style === 0) {
        noquotes = true;
    }
    if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags        quote_style = [].concat(quote_style);
        for (i=0; i < quote_style.length; i++) {
            // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
            if (OPTS[quote_style[i]] === 0) {
                noquotes = true;            }
            else if (OPTS[quote_style[i]]) {
                optTemp = optTemp | OPTS[quote_style[i]];
            }
        }        quote_style = optTemp;
    }
    if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) {
        string = string.replace(/'/g, '&#039;');
    }    if (!noquotes) {
        string = string.replace(/"/g, '&quot;');
    }
 
    return string;
}


function torol(objid,c) {
	var x = xGetElementById(objid + '_item' + c);
	var y = xGetElementById(objid + c + '_act');
	var z = xGetElementById(objid + '_items');
	if ((x) && (y) && confirm('Biztos töröl?')) {
		x.style.display="none";
		if (y.value == 'ins') {
			y.value = 'nop';
		} else if (y.value == 'upd') {
			y.value = 'del';
		} else {
			y.value = 'del';
		}
//		z.value = parseInt(z.value) - 1; //nem kell csökkenteni mivel az elem ott marad rejtve
	}
//	alert(objid + '_items; ' + z.innerHTML);
}

function modosult(objid,c) {
	var x = xGetElementById(objid + '_item' + c);
	var y = xGetElementById(objid + c + '_act');
	if ((x) && (y) && confirm('Biztos módosít?')) {
		y.value = 'upd';
	}
//	var z = xGetElementById(objid + '_items');
//	alert(objid + '_items; ' + z.innerHTML);
}

function hozzaad(obj){
	var x=0,y=0,z=0;
	x = obj; //xGetElementById('ppic');
	y = xGetElementById(obj.id+'_items');
	z = xGetElementById(obj.id+'_num');
	var v = [], w, i, o;
	for (i = 0;i< z.value; i++){
		o = xGetElementById(obj.id+i+'_exact');
		if (o){
			v[v.length] = o.checked;
		}
		o = xGetElementById(obj.id+i+'_primary');

		if (o.checked == true) {
			w = o;
		}
	}
	y.innerHTML +=
	   '<li id="'
	  + x.id
	  + '_item'
	  + z.value
	  + '" class="'
	  + x.id
	  + '_item">'
	  + '<img src="'+picpath 
	  + x.options[x.selectedIndex].text 
	  + '" height="50px"> '
	  + x.options[x.selectedIndex].text
	  + ' <input type="checkbox" name="'
	  + x.id
	  + z.value
	  + '_exact'
	  + '" id="'
	  + x.id
	  + z.value
	  + '_exact'
	  + '"> Pontos modell'
	  + ' <input type="radio" name="'
	  + x.id
	  + '_primary'
	  + '" id="'
	  + x.id
	  + z.value
	  + '_primary'
	  + '" value="'
	  + x.options[x.selectedIndex].value
	  + '">Elsődleges'
	  + ' <input type="hidden" id="'
	  + x.id
	  + z.value
	  + '_act'
	  + '" name="'
	  + x.id
	  + z.value
	  + '_act'
	  + '" value="ins">'
	  + ' <input type="hidden" id="'
	  + x.id
	  + z.value
	  + '" name="'
	  + x.id
	  + z.value
	  + '" value="'
	  + x.options[x.selectedIndex].value
	  + '">'
	  + '<a href="#" onclick="torol(\''
	  + x.id
	  + '\','
	  + z.value
	  + ');"> [Mégse]</a>'
	  + '</li>\n'
	x.selectedIndex = 0;
	for (i = 0; i < z.value; i++){
//		alert(y.innerHTML+'\n'+obj.id+i+'_exact');
		o = xGetElementById(obj.id+i+'_exact');
		o.checked = v[i];
	}
	if (w) {
		w.checked = true;
	}
	z.value = parseInt(z.value) + 1;
//	alert(y.innerHTML);
	d = xGetElementById('debug');
	if (d) {
		d.innerHTML = htmlspecialchars(y.innerHTML, 'ENT_QUOTES');
	}
}

function hozzarendelesszam(objid){
//	var x = obj; //xGetElementById('ppic');
//	var y = xGetElementById(obj.id+'_items');
	var z = xGetElementById(objid+'_num');
	var i, o, n=0;
	for (i = 0;i< z.value; i++){
		o = xGetElementById(objid+i+'_act');
		if (o){
			if ((o.value=='ins') || (o.value=='upd') || (o.value=='sel')){
				n++;
			}
		}
	}
	if (n==0){
		alert('Legalább egy '+objid+' elemet hozzá kell rendelni a termékhez!');
		return false;		
	}
	return true;
}

function hozzaad_cat(obj){
	var x = obj;
	var y = xGetElementById(obj.id+'_items');
	var z = xGetElementById(obj.id+'_num');
/*
	var o;
	o = document.createElement('li');
	o.value = 'fssdfsdf';
	y[y.length+1] = o;
*/
	y.innerHTML +=
	   '<li id="'
	  + x.id
	  + '_item'
	  + z.value
	  + '" class="'
	  + x.id
	  + '_item">'
	  + x.options[x.selectedIndex].text
	  + ' <input type="hidden" id="'
	  + x.id
	  + z.value
	  + '_act'
	  + '" name="'
	  + x.id
	  + z.value
	  + '_act'
	  + '" value="ins">'
	  + ' <input type="hidden" id="'
	  + x.id
	  + z.value
	  + '" name="'
	  + x.id
	  + z.value
	  + '" value="'
	  + x.options[x.selectedIndex].value
	  + '">'
	  + '<a href="#" onclick="torol(\''
	  + x.id
	  + '\','
	  + z.value
	  + ');"> [Mégse]</a>'
	  + '</li>\n'
	x.selectedIndex = 0;
	z.value = parseInt(z.value) + 1;
//	alert(y.innerHTML);
	d = xGetElementById('debug');
	if (d) {
		d.innerHTML = htmlspecialchars(y.innerHTML, 'ENT_QUOTES')+"<br>";
	}
}

function mark_all_rows(objid)
{
	var o = xGetElementById(objid);
	var chkbxlist, chkbx;
	chkbxlist = o.getElementsByTagName( 'input' );
  for ( var i = 0; i < chkbxlist.length; i++ ) {
		chkbx = chkbxlist[i];
		if ( chkbx && chkbx.type == 'checkbox' ) {
			chkbx.checked = true;
		}
	}
}

function unmark_all_rows(objid)
{
	var o = xGetElementById(objid);
	var chkbxlist, chkbx;
	chkbxlist = o.getElementsByTagName( 'input' );
  for ( var i = 0; i < chkbxlist.length; i++ ) {
		chkbx = chkbxlist[i];
		if ( chkbx && chkbx.type == 'checkbox' ) {
			chkbx.checked = false;
		}
	}
}

function ujablakba(o){
	window.open(o.href);
	return false;
}
