// BUTTON IMAGE SWITCH

function kepvalt(selfObj) {
	imagePath = selfObj.src;
	pLength = imagePath.length;
	imageState = imagePath.slice(pLength - 7, pLength - 4);
	if(imageState == "off") {
		imagePath = imagePath.slice(0, pLength - 7);
		imagePath = imagePath + "on.gif";
	} else {
		imagePath = imagePath.slice(0, pLength - 6);
		imagePath = imagePath + "off.gif";
	}
	selfObj.src = imagePath;
}

// PAGE HEIGHT CLAC 

function pageHeightCalc(parentContener) {
	var maxHeight = 0;
	var x = document.getElementById(parentContener);
	
	for(i=0; i<=x.childNodes.length - 1; i++) {
		if((x.childNodes[i].id) && (x.childNodes[i].tagName == 'DIV')) {
			//alert('ID = ' + x.childNodes[i].id + ' / HEIGHT = ' + x.childNodes[i].offsetHeight);
			if(maxHeight < x.childNodes[i].offsetHeight) {
				maxHeight = x.childNodes[i].offsetHeight;
			}
		}
	}
	for(i=0; i<=x.childNodes.length - 1; i++) {
		if((x.childNodes[i].id) && (x.childNodes[i].tagName == 'DIV')) {
			x.childNodes[i].style.height = maxHeight + "px";
			//alert('*** ID = ' + x.childNodes[i].id + ' / HEIGHT = ' + x.childNodes[i].style.height);
		}
	}
	x.style.height = maxHeight + "px";	
}

// TESZT ***************************************

function divHeightCalc(parentContener) {
	var maxDivHeight = 0;
	var divx = document.getElementById(parentContener);
	
	for(divi=0; divi<=divx.childNodes.length - 1; divi++) {
		if((divx.childNodes[divi].id) && (divx.childNodes[divi].tagName == 'DIV')) {
			if(maxDivHeight < divx.childNodes[divi].offsetHeight) {
				maxDivHeight = divx.childNodes[divi].offsetHeight;
			}
		}
	}
	divx.style.height = maxDivHeight + 140 + "px";
}



// STATUS BAR

function statusBar() {
	var curURL = new String(document.URL);

	curURLCount = curURL.length;
	locCount = curURL.lastIndexOf("/");
	curURL = curURL.slice(locCount + 1, curURLCount);
	locCount = curURL.indexOf(".");
	pageName = curURL.slice(0, locCount);

/*	if((document.getElementById(pageName)) || (pageName == 'login') || (pageName == 'login_chk')) {
		if(pageName == 'login' || pageName == 'login_chk') {pageName = 'personal';}

		document.getElementById(pageName).style.fontSize ="10px";
		document.getElementById(pageName).style.color ="#333333"; 
		document.getElementById(pageName).style.fontWeight ="bold"; 
	} 
*/
}

// STORE LAYER SWITCH

var timerId;
var divId;
var divIdLength;
var	divPos;
var	divStat;

function start(obj, ido) {
	divId = obj.id;
	divCount = divId.length;
	divTemp = divId.slice(18, divCount);
	divPos = divTemp.slice(0, divTemp.indexOf("-"));
	divStat = divTemp.slice(divTemp.indexOf("-") + 1, divTemp.length);
	timerId =  setTimeout("kapcs()", ido);
}

function kapcs() {
	if(divStat != 'a') {
		if(divPos == 'left') {
			document.getElementById('qbe-store-devhand-left-n').id = 'qbe-store-devhand-left-a';
			document.getElementById('qbe-store-devhand-right-a').id = 'qbe-store-devhand-right-n';
			document.getElementById('qbe-utbizt-lay').style.visibility = 'visible';
			document.getElementById('qbe-repjegy-lay').style.visibility = 'hidden';
		} else {
			document.getElementById('qbe-store-devhand-right-n').id = 'qbe-store-devhand-right-a';
			document.getElementById('qbe-store-devhand-left-a').id = 'qbe-store-devhand-left-n';
			document.getElementById('qbe-utbizt-lay').style.visibility = 'hidden';
			document.getElementById('qbe-repjegy-lay').style.visibility = 'visible';
		}
	} 
	
}

function re_set() {
	clearTimeout(timerId);
	timerId = 0;
}

function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}

var backSpace = false;

function dateMask(self, event) {
	dateLength = self.value.length;
	//alert(event.which);
	if(window.event) {
		esemeny = window.event.keyCode;
	} else {
		esemeny = event.which;
		//self.focus;
	}
	
	if((dateLength == 4) || (dateLength == 7)) {
		if(esemeny != 8) {
			// alert('pontot teszek BACKSPACE = ' + backSpace + ' KEY = ' + esemeny);
			self.value = self.value + '.';
		} else {
			// alert("törlés");
			backSpace = true;		
		}
	} else if((dateLength == 5) || (dateLength == 8)) {
		if(backSpace) {
			if(self.value.slice(dateLength-1, dateLength) != '.') {
				// alert('törlés után');
				self.value = self.value.slice(0, dateLength - 1) + '.' + self.value.slice(dateLength - 1, dateLength);
				backSpace = false;
			}
		}
	} else if(dateLength > 10) {
		self.value = self.value.slice(0, 10);
	}
}

var initValue;

function emptyCell(self) {
	if(self.value.slice(0, 1) == ' ') {
		self.value = ltrim(self.value);
	}
	if(self.value != '') {
		initValue = self.value;
		initDetect = self.value.slice(0, 1);
	}
	if(initDetect == '*') {
		self.value = '';
		self.select();
	} else if(initDetect == '') {
		self.value = initValue;
	}
}

function requiredCell(self) {
	self.value = ltrim(self.value);
	if(self.value == '') {
		self.value = initValue;
		initValue = '';
	} 
}

function infoSwitchOn (infoWindow) {
	wTop = document.getElementById('qbe-info').offsetTop;
	document.getElementById(infoWindow).style.visibility = 'visible';
	document.getElementById(infoWindow).style.top = wTop-200 + 'px';
}


