/*
	+-----------------------------------------------------------------------+
	| openWindow()															|
	+-----------------------------------------------------------------------+
*/
function openWindow(theURL,winName,winWidth,winHeight,sb,rs) {
	
	var winLeft = ((screen.availWidth - winWidth) / 2);
	var winTop = ((screen.availHeight - winHeight) / 2);
	if(sb == "no") {
		sb_string = ",scrollbars=no";
	}
	else {
		sb_string = ",scrollbars=yes";
	}
	if(rs == "yes") {
		rs_string = ",resizable=yes";
	}
	else {
		rs_string = ",resizable=no";
	}
	
	window.open(theURL,winName,'toolbar=no,' + sb_string + ',status=no,menubar=no' + rs_string + ',location=no,dependent=yes,width=' + winWidth + ',height=' + winHeight + ',left=' + winLeft + ',top=' + winTop);
}


/*
	+-----------------------------------------------------------------------+
	| gotoPage()															|
	+-----------------------------------------------------------------------+
*/
function gotoPage(Url2Go) {
	window.location.href = Url2Go;
}


/*
	+-----------------------------------------------------------------------+
	| closer()																|
	+-----------------------------------------------------------------------+
*/
function closer() {
	opener.location.reload();
	self.close();
}


/*
	+-----------------------------------------------------------------------+
	| createMessage()														|
	+-----------------------------------------------------------------------+
*/
function createMessage(part1, part2){
	
	window.location.href = 'mailto:' + part1 + '@' + part2;
}


/*
	+-----------------------------------------------------------------------+
	| confirm_delete()														|
	+-----------------------------------------------------------------------+
*/
function confirm_delete(url, deletetext){
	
	if(deletetext == '') {
		if(confirm("Wollen Sie den ausgewählten Eintrag wirklich löschen?") == true) {
			window.location.href = url;
		}
	}
	else {
		if(confirm("Wollen Sie den Eintrag '" + deletetext + "' wirklich löschen?") == true) {
			window.location.href = url;
		}
	}
}


/*
	+-----------------------------------------------------------------------+
	| numbersonly()															|
	+-----------------------------------------------------------------------+
*/
function numbersonly(myfield, e, dec) {
	var key;
	var keychar;
	
	if(window.event) {
	   key = window.event.keyCode;
	}
	else if(e) {
	   key = e.which;
	}
	else {
	   return true;
	}
	keychar = String.fromCharCode(key);
	
	if((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27)) {
	   return true;
	}
	
	else if ((("0123456789").indexOf(keychar) > -1)) {
	   return true;
	}
	
	else if (dec && (keychar == ".")) {
	   myfield.form.elements[dec].focus();
	   return false;
	}
	else {
	   return false;
	}
}
// <input type='text' name='bla' size='20' onKeyPress="return numbersonly(this, event)">


/*
	+-----------------------------------------------------------------------+
	| showDiv()																|
	+-----------------------------------------------------------------------+
*/
function showDiv(object,e) {
    if (e != '') {
        if (document.all) {
            x = e.clientX;
            y = e.clientY;
        }
        if (document.layers) {
            x = e.pageX;
            y = e.pageY;
        }
    }

    if (document.layers && document.layers[object] != null) {
        document.layers[object].left = x;
        document.layers[object].top = y;
    }
    else if (document.all) {
        document.all[object].style.posLeft = x;
        document.all[object].style.posTop = y;
    }

    if (document.layers && document.layers[object] != null) {
        document.layers[object].visibility = 'visible';
    }
    else if (document.all) {
        document.all[object].style.visibility = 'visible';
    }
}

// <a href="#" onMouseOver="if (window.event || document.layers) showDiv('text1',event)" onMouseOut="hideDiv('text1')">Layer</a>


/*
	+-----------------------------------------------------------------------+
	| hideDiv()																|
	+-----------------------------------------------------------------------+
*/
function hideDiv(object) {
    if (document.layers && document.layers[object] != null) {
        document.layers[object].visibility = 'hidden';
    }
    else if (document.all) {
        document.all[object].style.visibility = 'hidden';
    }
}


/*
	+-----------------------------------------------------------------------+
	| Datum ueberpruefen													|
	+-----------------------------------------------------------------------+
*/

function checkDate(date2check) {
	
	var date01_ori = date2check;
	var date01_tmp = date01_ori.split(".");
	
	if(date01_tmp.length == 3) {
		
		if(
		date01_tmp[0].length == 2 && 
		date01_tmp[1].length == 2 &&
		date01_tmp[2].length == 4
		) {
			
			var checkZero01 = date01_tmp[0].substring(0, 1);
			
			if(checkZero01 == 0) {
				
				date01_tmp[0] = date01_tmp[0].substr(1, 1)
			}
			
			var checkZero02 = date01_tmp[1].substring(0, 1);
			
			if(checkZero02 == 0) {
				
				date01_tmp[1] = date01_tmp[1].substr(1, 1)
			}
			
			date_day = parseInt(date01_tmp[0]);
			date_mon = parseInt(date01_tmp[1]);
			date_yea = parseInt(date01_tmp[2]);
			
			if(
			date_day < 32 && date_day > 0 && 
			date_mon < 13 && date_mon > 0 && 
			date_yea < 2010 && date_yea > 2000
			) {
				return true;
			}
			else {
				return false;
			}
		}
		else {
			return false;
		}
	}
	else {
		return false;
	}
}
	
/*
	+-----------------------------------------------------------------------+
	| Checkform input-fields												|
	+-----------------------------------------------------------------------+
*/
	
function checkform_storage(form) {
	if(form.storage_article) {
		if(form.storage_article.value == '') {
			alert('Das folgende Formular-Feld muss noch ausgefüllt werden: Artikel-Nummer.');
			form.storage_article.focus();
			return false;
		}
	}
	if(form.storage_name) {
		if(form.storage_name.value == '') {
			alert('Das folgende Formular-Feld muss noch ausgefüllt werden: Name.');
			form.storage_name.focus();
			return false;
		}
	}
	if(form.storage_amount) {
		if(form.storage_amount.value == '') {
			alert('Das folgende Formular-Feld muss noch ausgefüllt werden: Anzahl Exemplare.');
			form.storage_amount.focus();
			return false;
		}
	}
	if(form.storage_minimum) {
		if(form.storage_minimum.value == '') {
			alert('Das folgende Formular-Feld muss noch ausgefüllt werden: Min. Bestand.');
			form.storage_minimum.focus();
			return false;
		}
	}
	if(form.filename) {
		if(form.filename.value == '') {
			alert('Das folgende Formular-Feld muss noch ausgefüllt werden: File-Preview.');
			form.filename.focus();
			return false;
		}
	}
}

/*
	+---------------------------------------------------------------------------------------+
	| Ein- und ausblenden des input-feld Präfix beim anlegen oder editieren eines Clients	|
	+---------------------------------------------------------------------------------------+
*/
function show_prefix(id, strClientsId, request_client, getAppClientIdMigros) {

	var ok = 0;
	var str_erlaubte_id = strClientsId;
	var array_erlaubte_id = str_erlaubte_id.split(",");
	
	// console.debug(id,array_erlaubte_id,request_client,getAppClientIdMigros);
	
	for(i=0;i<array_erlaubte_id.length;i++) {
		if(id == array_erlaubte_id[i] || request_client == getAppClientIdMigros) {
			ok = 1;
		}
	}
	// console.debug(getAppClientIdMigros);
	// console.debug(ok);
	
	// if(ok == 1 && request_client != getAppClientIdMigros) {
	if(ok == 1) {
		$('prefix1').style.display = '';
		$('prefix2').style.display = '';
		return true;
	}
	else
	{
		$('client_prefix1').value = '';
		$('client_prefix2').value = '';
		$('prefix1').style.display = 'none';	
		$('prefix2').style.display = 'none';	
		return false;
	}
	return false;
}
