var defaultProgressText = 'Mentés...';

function copyRegUserBillAddress(){
	document.getElementById('UsersSzamlaNev').value = document.getElementById('UsersNev').value;
	document.getElementById('UsersSzamlaCimIrszam').value = document.getElementById('UsersPostaCimIrszam').value;
	document.getElementById('UsersSzamlaCimVaros').value = document.getElementById('UsersPostaCimVaros').value;
	document.getElementById('UsersSzamlaCimUtca').value = document.getElementById('UsersPostaCimUtca').value;
}

function copyCheckoutUserBillAddress(){
	document.getElementById('OrdersSzamlaNev').value = document.getElementById('OrdersPostaNev').value;
	document.getElementById('OrdersSzamlaCimIrszam').value = document.getElementById('OrdersPostaCimIrszam').value;
	document.getElementById('OrdersSzamlaCimVaros').value = document.getElementById('OrdersPostaCimVaros').value;
	document.getElementById('OrdersSzamlaCimUtca').value = document.getElementById('OrdersPostaCimUtca').value;
}

function openImg(image,title){
	base_url = trim(document.getElementById('base_url').innerHTML);
	open(base_url + '/' + image,title,"scrollbars=0,width=492,height=305,top=0,left=0").focus();
}	

function showDetailsDiv(div){
	//Kinyitja a details divet és megoldja az ikonokat is
	//Element.show(document.getElementById(div));
	showIcons('close' + div,'open' + div);
	Effect.SlideDown(document.getElementById(div));
}

function showIcons(show,hide){
	new Effect.Opacity(document.getElementById(hide), { from: 1, to: 0 });
	document.getElementById(hide).style.display="none";
	document.getElementById(show).style.display="inline";
	new Effect.Opacity(document.getElementById(show), { from: 0, to: 1 })
}

function hideDetailsDiv(div){
	 //Element.hide(document.getElementById(div));
	 Effect.DropOut(document.getElementById(div));
	 showIcons('open' + div,'close' + div);
}


function need2load(div){
	/* Ha már van valami e divben, akkor nem kell újra lekérni.
		Illetve ez elvégzi az Open/Close divcserét is */
	show = (document.getElementById(div).innerHTML.length==0);

	if (!show) {
	   showDetailsDiv(div);
	}
	return show;
}

function deleteRowFromBasket(id){
	document.getElementById('showtable').deleteRow(document.getElementById(id).rowIndex);

	c = (document.getElementById('showtable').rows.length);

	if (c == 1){
		bu = trim(document.getElementById('base_url').innerHTML);
		window.location=bu + "orderItems/emptyList";
}
}	

function showScreenHelpSection(page,section,notFoundDiv){
	wantedDiv = document.getElementById(page + '-' + section);
	if (wantedDiv == null) {
		wantedDiv=document.getElementById(notFoundDiv);
	} 

	wantedDiv.style.display='inline';
}

function showClearboxPopup(resultDiv){
	CB_Open('href=inner#' + resultDiv + ',,width=400,,closeonh=off'); 
}

function setCursorWait(){
	document.body.style.cursor = 'wait';
}

function setCursorDefault(){
	document.body.style.cursor = 'default';
}

function iwiwshare_click(){
	u=location.href;
	t=document.title;
	window.open('http://iwiw.hu/pages/share/share.jsp?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'iwiwshare','toolbar=0,status=0,location=1, width=650,height=600,scrollbars=1');
	return false;
}

function isIE(){
	var br = navigator.appName;
	return (br.indexOf("Microsoft") != -1);
}

// Flip html table row by row tag value
function flipTableRow(it,tableId,tagname,tagvalue){
	var visibleTag = 'table-row';
	if (isIE()){
		visibleTag = 'block';
	}
	
	var tbl = document.getElementById(tableId);
	
	for (var i = 0;i<tbl.rows.length;i++){
		if (tbl.rows[i].getAttribute(tagname) == tagvalue){
			if (it.checked){
				tbl.rows[i].style.display = visibleTag;
			} else {
				tbl.rows[i].style.display="none";
			}
		}
	}
}

/* Select boxok közötti option átpumpálás */	
function addOption(theSel, theText, theValue){
	var newOpt = new Option(theText, theValue);
	var selLength = theSel.length;
	theSel.options[selLength] = newOpt;
}

function deleteOption(theSel, theIndex){ 
	var selLength = theSel.length;
	if (selLength>0){
		theSel.options[theIndex] = null;
	}
}

function moveOptions(theSelFrom, theSelTo){
	var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);

	var selLength = theSelFrom.length;
	var selectedText = new Array();
	var selectedValues = new Array();
	var selectedCount = 0;

	var i;

	// Find the selected Options in reverse order
	// and delete them from the 'from' Select.
	for (i=selLength-1; i>=0; i--){
		if (theSelFrom.options[i].selected){
		  selectedText[selectedCount] = theSelFrom.options[i].text;
		  selectedValues[selectedCount] = theSelFrom.options[i].value;
		  deleteOption(theSelFrom, i);
		  selectedCount++;
		}
	}
  
	// Add the selected text/values in reverse order.
	// This will add the Options to the 'to' Select
	// in the same order as they were in the 'from' Select.
	for (i=selectedCount-1; i>=0; i--){
		addOption(theSelTo, selectedText[i], selectedValues[i]);
	}
  
	if (NS4) history.go(0);
}

/* Ajax progress indicator */

//wrappers

function workOn(str){
	showNotify(str); 
	return false;
}

function workOff(){
	hideNotify(); 
	return false;
}

// Cores
function getScrollTop() {
  if ( document.documentElement.scrollTop )
    return document.documentElement.scrollTop;

  return document.body.scrollTop;
}

function scrollHandler() {
   var e = document.getElementById('rc_notify');
   e.style.top = getScrollTop();
}

function showNotify( str ) { 
	var elem = document.getElementById('rc_notify');
	elem.style.display = 'block'; 
	elem.style.visibility = 'visible';

	if ( elem.currentStyle && 
	   elem.currentStyle.position == 'absolute' ) 
	{
		elem.style.top = getScrollTop();
		window.onscroll = scrollHandler;
	}

	if (typeof str == "undefined") {
		elem.innerHTML = defaultProgressText;
	} else {
		elem.innerHTML = str;
	}
}

function hideNotify() {
  var elem = document.getElementById('rc_notify');
  elem.style.display = 'none';
  elem.style.visibility = 'hidden';
  window.onscroll = null;
}

