// Dreamweaver standard function to identify objects
function MM_findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

// Register all fields that must be checked here
function checkRequiredPressFieldsEn() {
	var errormessage = new String();
	if (withoutContent("mailform_presse_name")) {
		errormessage += "\n\nPlease fill in the field \"Name\".";
	}
	if (withoutContent("mailform_presse_company")) {
		errormessage += "\n\nPlease fill in the field \"Company\".";
	}
	if (withoutContent("mailform_presse_mail")) {
		errormessage += "\n\nPlease fill in the field \"E-Mail\".";
	} else {
		if (noValidEmail("mailform_presse_mail")) {
			errormessage += "\n\nPlease write a valid E-Mail address into the field \"E-Mail\".";
		}
	}
	if (withoutContent("mailform_presse_street")) {
		errormessage += "\n\nPlease fill in the field \"Street\".";
	}
	if (withoutContent("mailform_presse_city")) {
		errormessage += "\n\nPlease fill in the field \"Zip, City\".";
	}
	if (withoutContent("mailform_presse_purpose")) {
		errormessage += "\n\nPlease fill in the field \"Purpose\".";
	}
	if (withoutContent("mailform_presse_tel")) {
		errormessage += "\n\nPlease fill in the field \"Telephone No.\".";
	}
	if (errormessage.length > 2) {
		alert("Please note:" + errormessage);
		return false;
	}
	return true;
}

// Check whether a field is not empty
function withoutContent(ssObj) {
	var ss = MM_findObj(ssObj).value;
	if (ss.length > 0) {
		return false;
	}
	return true;
}

// Check whether a field is a valid E-Mail address
function noValidEmail(inputObjName) {
	var specialCharsSet = new Array("%","!","\”","§","$","&","/","(",")","=","?","ß","´","´`","+","*","#","'",",",";",":","ä","ö","ü","<",">","€");

	var inputObj = MM_findObj(inputObjName);
	var strParts = inputObj.value.split("@");
	if (strParts.length !=  2 || strParts[0].length < 1 || strParts[1].length < 6) {
		return true; 
	} else if (strParts[1].lastIndexOf(".") < 3 || strParts[1].lastIndexOf(".") > (strParts[1].length-3)) {
		return true;
	} else {
		strParts[0] = strParts[0].toLowerCase();
		strParts[1] = strParts[1].toLowerCase();
		for (i=0; i<specialCharsSet.length; i++) {
			if (strParts[0].indexOf(specialCharsSet[i]) != -1) {
				return true;
			} else if (strParts[1].indexOf(specialCharsSet[i]) != -1) {
				return true;
			}
		}
	}
	return false;
}