function windowOpen(href, width, height, scrollbar)
{
	if (width == '' && height == '') {
		window.open(href, '_blank', 'toolbar=no,location=no,status=yes,menubar=no,personalbar=no,scrollbars=yes,resizable=yes,screenx=50,left=50,screenY=50,top=50');
	} 
	else if (scrollbar != '') {
		window.open(href, '_blank', 'toolbar=no,location=no,status=no,menubar=no,personalbar=no,scrollbars=' + scrollbar + ',width=' + width + ',height=' + height + ',resizable=yes,screenx=50,left=50,screenY=50,top=50')
	}
	else {
		window.open(href, '_blank', 'toolbar=no,location=no,status=no,menubar=no,personalbar=no,scrollbars=no,width=' + width + ',height=' + height + ',resizable=yes,screenx=50,left=50,screenY=50,top=50')
	}
}

function windowOpenDMS(href, width, height, scrollbar)
{
	if (width == '' && height == '') {
		window.open(href, '_blank', 'toolbar=no,location=yes,status=yes,menubar=no,personalbar=no,scrollbars=yes,resizable=yes,screenx=50,left=50,screenY=50,top=50');		
	} 
	else if (scrollbar != '') {
		window.open(href, '_blank', 'toolbar=no,location=yes,status=yes,menubar=no,personalbar=no,scrollbars=' + scrollbar + ',width=' + width + ',height=' + height + ',resizable=yes,screenx=50,left=50,screenY=50,top=50')		
	}
	else {
		window.open(href, '_blank', 'toolbar=no,location=yes,status=yes,menubar=no,personalbar=no,scrollbars=yes,width=' + width + ',height=' + height + ',resizable=yes,screenx=50,left=50,screenY=50,top=50')		
	}
}

function del_confirm(msg, url) {
  if(confirm(msg)) {
  	location.href = url;
  }
}

function CheckMandatoryFields(oForm) {

	var i, j, sElementName, sElementType, bCheck;
	var bError = 0;
	var bgColor = "#DCE2E7";

	for (i = 0; i < oForm.elements.length; i++) {
	
		oElement = oForm.elements[i];

		sElementName = oElement.name;
		sElementType = oElement.type;
		if(sElementName == "")
		{
			sElementName = oElement.id
		}		
		
		if (sElementName != "") {
			
			if (sElementName.length > 3) {
						
				if (sElementName.substr(sElementName.length - 3, 3) == "_mf") {
					
					switch (sElementType) {
						case "text":
							if (oElement.value == "") {
								bError = 1;
								oElement.style.backgroundColor = bgColor;
							}
							else {
								oElement.style.backgroundColor = "";
							}
							break;
							
							
						case "password":
							if (oElement.value == "") {
								bError = 1;
								oElement.style.backgroundColor = bgColor;
							}
							else {
								oElement.style.backgroundColor = "";
							}
							break;
						
																			
						case "textarea":
						
							if (oElement.value == "") {
								bError = 1;
								oElement.style.backgroundColor = bgColor;
							}
							else {
								oElement.style.backgroundColor = "";
							}
							break;

						case "checkbox":
						
				            bCheck = 0;
							for(j = 0; j < oForm[sElementName].length; j++) 
							{  
								if(oForm[sElementName][j].checked == true)
								{
									bCheck = 1;
								}
							}         
			                  
			             	if(bCheck == 0) 
							{
								bError = 3;
								oElement.style.backgroundColor = "#94adc6";
								oElement.style.outline = "#94adc6 solid 2px";
								oElement.style.marginLeft = "2px";
								oElement.style.marginTop = "2px";
								oElement.style.paddingRight = "2px";
							}
							else 
							{
								oElement.style.outline = "";
							}
							break;
							
						
						case "radio":

				            bCheck = 0;
							for(j = 0; j < oForm[sElementName].length; j++) 
							{  
								if(oForm[sElementName][j].checked == true)
								{
									bCheck = 1;
								}
							}         
			                  
			             	if(bCheck == 0) 
							{
								bError = 1;
								oElement.style.backgroundColor = "#94adc6";
								oElement.style.outline = "#94adc6 solid 2px";
								oElement.style.marginLeft = "2px";
								oElement.style.marginTop = "2px";
								oElement.style.paddingRight = "2px";
							}
							else 
							{
								oElement.style.backgroundColor = "#FFFFFF";
								oElement.style.outline = "#FFFFFF solid 2px";
								oElement.style.marginLeft = "2px";
								oElement.style.marginTop = "2px";
								oElement.style.paddingRight = "2px";
							}
							break;
							
						case "select-one":
						
							if (oElement[oElement.selectedIndex].value == "" || oElement[oElement.selectedIndex].value == "null") {
								bError = 1;
								oElement.style.backgroundColor = bgColor;
							}
							else {
								oElement.style.backgroundColor = "";
							}
							break;
							
							
						case "select-multiple":

							bCheck = 0;

							for (j = 0; j < oElement.options.length; j++) {
							
								if (oElement.options[j].selected) {
									bCheck++;
								}
							}

							if (bCheck == 0) {
								bError = 1;
								oElement.style.backgroundColor = bgColor;
							}
							else {
								oElement.style.backgroundColor = "";
							}
							break;
						
						case "file":
							if (oElement.value == "") {
								bError = 1;
								oElement.style.backgroundColor = bgColor;
							}
							else {
								oElement.style.backgroundColor = "";
							}
							break;
					}
				}
					
				if(sElementName.indexOf('mail_') != -1 && oElement.value != "") 
				{
					if(checkEmail(oElement.value) == false)
					{
						bError = 2;
						oElement.style.backgroundColor = bgColor;
					}
					else 
					{
						oElement.style.backgroundColor = "";
					}
				}
				
				if(sElementName.indexOf('_postcode_') != -1 && oElement.value != "") 
				{
					if(checkNumber(oElement.value) == false)
					{
						bError = 5;
						oElement.style.backgroundColor = bgColor;
					}
					else 
					{
						oElement.style.backgroundColor = "";
					}
				}				
			}
		}
	}
	
	//checks for special forms
	if (bError == 0) {
		if (oForm.contact_subject && oForm.contact_fax) {
			if(getRadioValue(oForm.contact_subject) == 'fax' && oForm.contact_fax.value == "") {
				oForm.contact_fax.style.backgroundColor = bgColor;
				bError = 4;
			}
		}
	}
	
	if (bError == 0) {
		return true;
	}
	if (bError == 1) {
		alert("Nicht jedes Mussfeld ist ausgefuellt oder selektiert. Bitte korrigieren.");
		return false;
	}
	if (bError == 2) {
		alert("Bitte geben Sie eine gueltige E-Mail Adresse an.");
		return false;
	}
	if (bError == 3) {
		alert("Nicht jedes Mussfeld ist ausgefuellt oder selektiert. Bitte korrigieren.");
		return false;
	}
	if (bError == 4) {
		alert("Bitte geben Sie die Fax-Nummer an.");
		return false;
	}
	if (bError == 5) {
		alert("Bitte geben Sie eine-Nummer an.");
		return false;
	}	
}



function CheckMandatoryFieldsJquery(sFormName) 
{
	var oForm = document.getElementById(sFormName).elements;
	var i, j, sElementName, sElementType, bCheck;
	var bError = 0;
	var bgColor = "#DCE2E7";

	for (i = 0; i < oForm.length; i++) 
	{
		oElement = oForm[i];

		sElementName = oElement.name;
		sElementType = oElement.type;
		if(sElementName == "")
		{
			sElementName = oElement.id
		}		
		
		if (sElementName != "") {
			
			if(sElementName.length > 3) 
			{
				if(sElementName.substr(sElementName.length - 3, 3) == "_mf") 
				{
					switch (sElementType) {
						case "text":
							if (oElement.value == "") {
								bError = 1;
								oElement.style.backgroundColor = bgColor;
							}
							else {
								oElement.style.backgroundColor = "";
							}
							break;
							
							
						case "password":
							if (oElement.value == "") {
								bError = 1;
								oElement.style.backgroundColor = bgColor;
							}
							else {
								oElement.style.backgroundColor = "";
							}
							break;
						
																			
						case "textarea":
						
							if (oElement.value == "") {
								bError = 1;
								oElement.style.backgroundColor = bgColor;
							}
							else {
								oElement.style.backgroundColor = "";
							}
							break;

						case "checkbox":
						
				            bCheck = 0;
							for(j = 0; j < oForm[sElementName].length; j++) 
							{  
								if(oForm[sElementName][j].checked == true)
								{
									bCheck = 1;
								}
							}         
			                  
			             	if(bCheck == 0) 
							{
								bError = 3;
								oElement.style.backgroundColor = "#94adc6";
								oElement.style.outline = "#94adc6 solid 2px";
								oElement.style.marginLeft = "2px";
								oElement.style.marginTop = "2px";
								oElement.style.paddingRight = "2px";
							}
							else 
							{
								oElement.style.outline = "";
							}
							break;
							
						
						case "radio":

				            bCheck = 0;
							for(j = 0; j < oForm[sElementName].length; j++) 
							{  
								if(oForm[sElementName][j].checked == true)
								{
									bCheck = 1;
								}
							}         
			                  
			             	if(bCheck == 0) 
							{
								bError = 1;
								oElement.style.backgroundColor = "#94adc6";
								oElement.style.outline = "#94adc6 solid 2px";
								oElement.style.marginLeft = "2px";
								oElement.style.marginTop = "2px";
								oElement.style.paddingRight = "2px";
							}
							else 
							{
								oElement.style.backgroundColor = "#FFFFFF";
								oElement.style.outline = "#FFFFFF solid 2px";
								oElement.style.marginLeft = "2px";
								oElement.style.marginTop = "2px";
								oElement.style.paddingRight = "2px";
							}
							break;
							
						case "select-one":
						
							if (oElement[oElement.selectedIndex].value == "" || oElement[oElement.selectedIndex].value == "null") {
								bError = 1;
								oElement.style.backgroundColor = bgColor;
							}
							else {
								oElement.style.backgroundColor = "";
							}
							break;
							
							
						case "select-multiple":

							bCheck = 0;

							for (j = 0; j < oElement.options.length; j++) {
							
								if (oElement.options[j].selected) {
									bCheck++;
								}
							}

							if (bCheck == 0) {
								bError = 1;
								oElement.style.backgroundColor = bgColor;
							}
							else {
								oElement.style.backgroundColor = "";
							}
							break;
						
						case "file":
							if (oElement.value == "") {
								bError = 1;
								oElement.style.backgroundColor = bgColor;
							}
							else {
								oElement.style.backgroundColor = "";
							}
							break;
					}
				}
					
				if(sElementName.indexOf('mail_') != -1 && oElement.value != "") 
				{
					if(checkEmail(oElement.value) == false)
					{
						bError = 2;
						oElement.style.backgroundColor = bgColor;
					}
					else 
					{
						oElement.style.backgroundColor = "";
					}
				}
				
				if(sElementName.indexOf('_postcode_') != -1 && oElement.value != "") 
				{
					if(checkNumber(oElement.value) == false)
					{
						bError = 5;
						oElement.style.backgroundColor = bgColor;
					}
					else 
					{
						oElement.style.backgroundColor = "";
					}
				}				
			}
		}
	}
	
	//checks for special forms
	if (bError == 0) {
		if (oForm.contact_subject && oForm.contact_fax) {
			if(getRadioValue(oForm.contact_subject) == 'fax' && oForm.contact_fax.value == "") {
				oForm.contact_fax.style.backgroundColor = bgColor;
				bError = 4;
			}
		}
	}
	
	if (bError == 0) {
		return true;
	}
	if (bError == 1) {
		alert("Nicht jedes Mussfeld ist ausgefuellt oder selektiert. Bitte korrigieren.");
		return false;
	}
	if (bError == 2) {
		alert("Bitte geben Sie eine gueltige E-Mail Adresse an.");
		return false;
	}
	if (bError == 3) {
		alert("Nicht jedes Mussfeld ist ausgefuellt oder selektiert. Bitte korrigieren.");
		return false;
	}
	if (bError == 4) {
		alert("Bitte geben Sie die Fax-Nummer an.");
		return false;
	}
	if (bError == 5) {
		alert("Bitte geben Sie eine-Nummer an.");
		return false;
	}	
}


function lengthRestriction(elem, min, max)
{
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("Please enter between " +min+ " and " +max+ " characters");
		elem.focus();
		return false;
	}
} 

function getRadioValue(obj) 
{
    for (var i=0; i < obj.length; i++) {
		if (obj[i].checked) return obj[i].value;
	}
}

function checkEmail(emailAddress) 
{
	var re = /^(([^<>()[\]\\.,;:@\"]+(\.[^<>()[\]\\.,;:@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
	return re.test(emailAddress);
}

function checkNumber(sNumber) 
{
	var re = /^[0-9]+$/;
	return re.test(sNumber);
}

function scrollToTop(x, y) {

	window.scrollTo(x, y);
}

function fill_documentid(selected_documentid, docArray)
{
	opener.document.getElementById(docArray).value = selected_documentid;
			
	opener.focus();
	window.close();

}

function resize_fontsize(fontSize, value) 
{
	var styleSheet, cssRule;
    if (document.styleSheets)
    {
    	styleSheet = document.styleSheets[0];		// IE und FF
		
        if (styleSheet)
        {
        	if (styleSheet.cssRules)
            	cssRule = styleSheet.cssRules[1];	// Firefox
            else if (styleSheet.rules)
                cssRule = styleSheet.rules[0];      // IE
            
			if (cssRule)
            {
            	cssRule.style.fontSize = value;
            }
         }
     }
}

//Used to write a server side cookie to Airlock
function xmlhttpPost(strURL, strCookieName, strCookieValue, strPath, strExpire, bDeleteCookie)
{
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest)
	{
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject)
	{
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, false);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	
    self.xmlHttpReq.send("cookiedata=" + strCookieName + ";" + strCookieValue + ";" + strPath + ";" + strExpire + ";" + bDeleteCookie);
}
