// JavaScript Document
function doGlobalOpen(url,name, width, height, typ){
	width = (width ? width : 350);
	height = (height ? height : (screen.height < 700 ? 525 : 625 ));
	//if ( url.indexOf("http://") == 0 || url.indexOf("https://") == 0 ) url = url;
	//else if ( url.toLowerCase().indexOf("readform") > -1 || url.toLowerCase().indexOf("openform") > -1 || url.toLowerCase().indexOf("openview")  > -1) url = window.base + url;
	//else url = window.base + url +".html";
	winPopup = window.open(url,name,"width=" + width + ",height=" + height + ",screenX=0,screenY=0,left=100,top=50,dependent=yes,status=no,copyhistory=no,toolbar=no,location=no,scrollbars=yes");
	if (typ==false) {
		var winPopupLoc=winPopup;
		winPopupLoc.focus();
		winPopup=null;
	}else {
		winPopup.focus();
	}
	return false;
}

/* V A L I D A T I O N */

function isValidMail(strMail) {
	return (strMail != null
		&& strMail.length > 0 
		&& strMail.indexOf('@') > 0 
		&& strMail.length - strMail.lastIndexOf('.') > 2 
		&& strMail.lastIndexOf('.') - strMail.indexOf('@') > 2);
}
/**
 * Validiert ob Felder gefüllt bzw. bei Select-Felder etwas ausgewählt ist
 * @param objForm	-	Formular-Objekt
 * @param fields	-	Array mit den zu testenden Feldern ( Bsp.: "Feldname1", "Bezeichnung 1", "Feldname2", "Bezeichnung 2", ... )
 */
function checkCommonFields( objForm, fields) {
	if ( fields == null || objForm == null ) return true;
		
	for ( i = 0; i < fields.length; i+=2 ) {
		if (!objForm.elements[ fields[i] ]) continue;
		var status = false;
 		var focus = true;
 		switch (objForm.elements[ fields[i] ].type) {
 		case "select-one": 
 			status = (objForm.elements[ fields[i] ].selectedIndex > 0 ? true : false);
 			break;
 		case "hidden": continue; break;
		default: if ( objForm.elements[ fields[i] ].length ) { // wenn undefined dann else zweig
				// Radiobox oder Checkbox
				for ( j = 0; j < objForm.elements[ fields[i] ].length; j++ ) {
 
					if ( objForm.elements[ fields[i] ][j].checked == true ) { 
						status = true;
					}
				}
			}else{
				// Normales Inputfeld
 				status = (objForm.elements[ fields[i] ].value.length > 0 ? true : false);
			}
			break;
 		}
  		if ( !status ) {
   			alert( "Bitte fuellen Sie alle gekennzeichneten Felder aus. Die Angabe - " + fields[i+1] + " - fehlt.");
   			if ( objForm.elements[ fields[i] ].focus ) objForm.elements[ fields[i] ].focus();
   			return false;
  		}
 	}
 	return true;
}
/**
 * Validiert auf korrektes E-Mail-Format
 * @param objForm	-	Formular-Objekt
 * @param fields	-	Array mit den zu testenden Feldern ( Bsp.: "Feldname1", "Bezeichnung 1", "Feldname2", "Bezeichnung 2, ... )
 */
function checkMailFields( objForm, fields ) {
	if ( fields == null || objForm == null ) return true;
	for ( i = 0; i < fields.length; i+=2 ) {
		if (!objForm.elements[ fields[i] ]) continue;
		if ( !isValidMail( objForm.elements[ fields[i] ].value) ) {
			alert("Bitte geben Sie im Feld - " + fields[i+1] + " - eine korrekte E-Mail-Adresse ein.");
			objForm.elements[ fields[i] ].focus();
			return false;  		
		}
	}
	return true;
}

