function d(id){
	return document.getElementById(id);
}
function RND(){
	Stamp = new Date();
	return Stamp.getSeconds()+' '+Math.round(Math.random()*4);
}
function setCookie(name, value, expires, path, domain) {
	var never = new Date();
	never.setTime(never.getTime() + 24 * 60 * 60 * 1000 * 365);
	if(expires.toLowerCase() == "never") expires = never;

	var cookie = name+"="+escape(value);
	cookie = cookie + ((expires==null)?"":("; expires="+expires.toGMTString()));
	cookie = cookie + ((path==null)?"":("; path="+path));
	cookie = cookie + ((domain==null)?"":("; domain="+domain));
	document.cookie=cookie;
}
function emailCheck(emailStr) {
	var emailPat = /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/;
	var matchArray = emailStr.match(emailPat);
	if (matchArray == null) return false;
	var IPArray = matchArray[2].match(/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/);
	if (IPArray != null)
		for (var i=1;i<=4;i++)
			if (IPArray[i]>255)
				return false;
	return true;
}

function getPageX(event) {
	if (!event) event=window.event;
	return event.pageX || (event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft));
}
function getPageY(event) {
	if (!event) event=window.event;
	return event.pageY || (event.clientY + (document.documentElement.scrollTop || document.body.scrollTop));
}

function isPositionInElement(x, y, e, eX ,eY) {//page coordinates
	if (eX==null || eY==null) {
		var pos=getElementPosition(e);
		eX=pos.x;
		eY=pos.y;
	}
	return (x>eX && x<eX+e.offsetWidth && y>eY && y<eY+e.offsetHeight);
}
function get_radio_value(obj){
	for (var i=0; i < obj.length; i++){
		if (obj[i].checked){
			return obj[i].value;
		}
	}
	return false;
}

function showBannerFlash(flash, productId){
	var width = 90;
	var height = 170;
	document.write('<div class="divx" style="width:'+width+'px;height:'+height+'px;"><div style="width:'+width+'px;height:'+height+'px;" class="divxinner"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab" width="'+width+'" height="'+height+'" id="banner'+productId+'">');
	
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="'+flash+'" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="bgcolor" value="#eeeeee" />');
	
	document.write('<embed src="'+flash+'" quality="high" bgcolor="#eeeeee" width="'+width+'" height="'+height+'" name="banner'+productId+'" align="middle" allowScriptAccess="sameDomain" play="true" loop="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object></div></div>');
}

function showMyFlash(flash, image){
	document.write('<embed src="/mediaplayer.swf"');
	document.write('width="300" ');
	document.write('height="220" ');
	document.write('allowscriptaccess="always" ');
	document.write('allowfullscreen="true" ');
	document.write('flashvars="width=300&height=220&file='+flash+'&image='+image+'&displayheight=220&searchbar=false" ');
	document.write('/>');
}

function changeField(list, field, val){
	var state = document.getElementById(list);
	var notus = document.getElementById(field);
	(state.value == val)? notus.disabled=false : notus.disabled=true
}
function changeFieldDouble(list1, field1, val1, list2, field2, val2, list3, field3, val3, list4, field4, val4){
	var state1 = document.getElementById(list1);
	var notus1 = document.getElementById(field1);
	(state1.value == val1)? notus1.disabled=false : notus1.disabled=true;

	var state2 = document.getElementById(list2);
	var notus2 = document.getElementById(field2);
	(state2.value == val2)? notus2.disabled=false : notus2.disabled=true	

	var state3 = document.getElementById(list3);
	var notus3 = document.getElementById(field3);
	(state3.value == val3)? notus3.disabled=false : notus3.disabled=true

	var state4 = document.getElementById(list4);
	var notus4 = document.getElementById(field4);
	(state4.value == val4)? notus4.disabled=false : notus4.disabled=true
}

function hidesg(divid) {
	document.getElementById(divid).style.display='none';
}

function showsg(divid) {
	document.getElementById(divid).style.display='block';
}

var ids=new Array('hibas_kep','hibas_tartalom','fejlesztes');

function switchid(id){	
	hideallids();
	showdiv(id);
}

function hideallids(){
	for (var i=0;i<ids.length;i++){
		hidediv(ids[i]);
	}		  
}

function hidediv(id) {

	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) {
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}

function setURL(url, param){
	document.location = url + "&bill=" + param;
}

function share_iwiw() {
	window.open('http://iwiw.hu/pages/share/share.jsp?t='+encodeURIComponent(document.title)+'&u='+encodeURIComponent(location.href),'IWIW','toolbar=0,status=0,location=1, width=650,height=600,scrollbars=1');
}
function share_startlap() {
	window.open('http://www.startlap.hu/sajat_linkek/addlink.php?title='+encodeURIComponent(document.title)+'&url='+encodeURIComponent(location.href), 'Startlap', 'toolbar=0, status=0, location=1, width=650, height=600, scrollbars=1');
}
var AkcioSzinTomb3= new Array("#666666","#FF3333","#FF3333");
var AkcioSzinTombIndex3=0;

setTimeout('akcio_villog()' , 500);
function akcio_villog() {
	setTimeout('akcio_villog()' , 500);
	if(document.getElementById('akcio')) {
		document.getElementById('akcio').style.color = AkcioSzinTomb3[AkcioSzinTombIndex3];
		}
	AkcioSzinTombIndex3 ++;
	if(AkcioSzinTombIndex3 == AkcioSzinTomb3.length) AkcioSzinTombIndex3 = 0;
}

function editOrderDetails(container_id, width, type)
{
	var originalValue = $("#"+container_id+"_value").html();
	if (originalValue == null) originalValue = '';
	$("#"+container_id).html("");
	if (type == 'text')
		$("#"+container_id+"_value_new").html("<input style='width: "+width+"px; font-size: 12px;' type='text' name='"+container_id+"' value='"+originalValue+"'>");
	else
		//$("#"+container_id+"_value_new").html("<textarea style='width: "+width+"px; height: 50px; font-size: 12px;' name='"+container_id+"'>"+originalValue+"</textarea>");
		$("#"+container_id+"_value_new").html("<textarea style='width: "+width+"px; height: 50px; font-size: 12px;' name='"+container_id+"'></textarea>");
	
}

function editOrderDetailsShipmentMethod(container_id, old_method)
{
	if (old_method == 'post') {
		$("#"+container_id).html("");
		$("#"+container_id+"_value_new").html("Személyes átvétel <input type='button' value='Váltás futárszolgálatra' style='font-size: 12px' onClick='javascript: editOrderDetailsShipmentMethod(\"order_data_shipment_method\", \"personal\");'>");
		$("#"+container_id+"_value_id").val("personal");
	}
	else {
		$("#"+container_id).html("");
		$("#"+container_id+"_value_new").html("Futárszolgálat <input type='button' value='Váltás személyes átvételre' style='font-size: 12px' onClick='javascript: editOrderDetailsShipmentMethod(\"order_data_shipment_method\", \"post\");'>");
		$("#"+container_id+"_value_id").val("post");
	}
}

function editOrderDetailsAmount(id)
{
	var original_value = $("#order_current_price_"+id).html();
	var original_amount = $("#order_amount_"+id).html();
	$("#order_amount_container_"+id).html("");
	$("#order_amount_container_"+id).html("<input style='width: 25px; font-size: 12px;' id='order_amount_new_"+id+"' onBlur='javascript: changeOrderDetailsAmount("+id+", "+original_amount+")' type='text' name='order_amount_new_"+id+"' value='"+original_amount+"'>");
	$("#order_shipment_price").hide('slow');
}

function changeOrderDetailsAmount(id, original_amount)
{
	var original_value = $("#order_current_price_"+id).html().replace('&nbsp;', '');
	var amount_new = $("#order_amount_new_"+id).val().replace('&nbsp;', '');;
	if (amount_new > 0)
	{
		var amount_total_original = $("#order_total_"+id).html().replace('&nbsp;', '');;
		var amount_total_new = amount_new*original_value;
		$("#order_total_"+id).html(number_format(amount_total_new, 0, ',', ' '));
	}
	else
	{
		alert("A rendeléseid között a mennyiség oszlopban nem megengedett érték szerepelt.");
		$("#order_amount_new_"+id).val(original_amount);
	}
}

function number_format (number, decimals, dec_point, thousands_sep) {
	// discuss at: http://phpjs.org/functions/number_format
	var n = number, prec = decimals;
	
	var toFixedFix = function (n,prec) {
	    var k = Math.pow(10,prec);
	    return (Math.round(n*k)/k).toString();
	};
	
	n = !isFinite(+n) ? 0 : +n;
	prec = !isFinite(+prec) ? 0 : Math.abs(prec);
	var sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep;
	var dec = (typeof dec_point === 'undefined') ? '.' : dec_point;
	
	var s = (prec > 0) ? toFixedFix(n, prec) : toFixedFix(Math.round(n), prec); //fix for IE parseFloat(0.55).toFixed(0) = 0;
	
	var abs = toFixedFix(Math.abs(n), prec);
	var _, i;
	
	if (abs >= 1000) {
	    _ = abs.split(/\D/);
	    i = _[0].length % 3 || 3;
	
	    _[0] = s.slice(0,i + (n < 0)) +
		  _[0].slice(i).replace(/(\d{3})/g, sep+'$1');
	    s = _.join(dec);
	} else {
	    s = s.replace('.', dec);
	}
	
	var decPos = s.indexOf(dec);
	if (prec >= 1 && decPos !== -1 && (s.length-decPos-1) < prec) {
	    s += new Array(prec-(s.length-decPos-1)).join(0)+'0';
	}
	else if (prec >= 1 && decPos === -1) {
	    s += dec+new Array(prec).join(0)+'0';
	}
	return s;
}


