window.defaultStatus = "dewag.de";

function rtclickcheck(keyp) { 
	message = "test";
	if (navigator.appName == "Netscape" && keyp.which == 3) {
		return false;
	} 
	if (navigator.appVersion.indexOf("MSIE") != -1 && event.button == 2) {
		return false;
	}
} 
document.onmousedown = rtclickcheck;

function hideStatus(theId) {
	if (document.getElementById(theId)) {
		document.getElementById(theId).style.display = 'none';
	}
}

function changeColor(theId, theColor) {
	if (document.getElementById(theId)) {
		document.getElementById(theId).style.color = theColor;
	}
}

function submit(theForm, theValue) {
	if (document.getElementById('curLang')) {
		langId = document.getElementById('curLang').value;
	}
	if (theForm == 'searchform') {
		sword = document.getElementById('searchField').value;
		if (sword.length > 2) {
			document.searchform.submit();
		}
		else {
			if (langId == 1) {
				alert('A search term has to have at least 3 characters.');
			}
			else {
				alert('Ein Suchwort muss aus mindestens 3 Buchstaben bestehen.');
			}
		}
	}
}

function toogleItem(theId, caller, state) {
	if (document.getElementById(theId)) {
		document.getElementById(theId).style.display = state;
	}
}

function submitMAF(theForm, hiddenId, hiddenVal, langID) {
	errorMessage = '';
	if (document.getElementById('email')) {
		tmpactid = theForm + '_action';
		tmpMail = document.getElementById('email').value;
		if (!isValidEmail(tmpMail)) {
			if (langID == 1) {
				errorMessage = unescape("Your e-mail address seems to be invalid.%0A%0APlease check your input.");
			}
			else {
				errorMessage = unescape("Ihre E-Mail Adresse ist ung%FCltig.%0A%0ABitte %FCberpr%FCfen Sie Ihre Eingabe.");
			}
		}
		else if ((isValidEmail(tmpMail)) && (getCheckedValue(document[theForm]['acttype']) == 'subscribe')) {
			tmpchckd = 0;
			for (var i=0; i < document[theForm]['categories[]'].length; i++) {
				tmpItm = 'categories[' + i + ']';
				if (document[theForm]['categories[]'][i].checked) {
					tmpchckd++;
				}
			}
			if (tmpchckd < 1) {
				if (langID == 1) {
					errorMessage = unescape("Please select at least one category.");
				}
				else {
					errorMessage = unescape("Bitte w%E4hlen Sie mindestens eine Kategorie aus.");
				}
			}
			if (document.getElementById(tmpactid)) {
				document.getElementById(tmpactid).value = 'submit';
			}
			else {
				if (langID == 1) {
					errorMessage = unescape("There seems to be a problem with the webform.%0A%0APlease try again later.");
				}
				else {
					errorMessage = unescape("Das Webformular kann nicht abgeschickt werden.%0A%0ABitte versuchen Sie es sp%E4ter erneut.");
				}
			}
		}
		else if ((isValidEmail(tmpMail)) && (getCheckedValue(document[theForm]['acttype']) == 'unsubscribe')) {
			if (document.getElementById(tmpactid)) {
				document.getElementById(tmpactid).value = 'submit';
			}
		}
	}
	else {
		if (langID == 1) {
			errorMessage = unescape("Your e-mail address seems to be invalid.%0A%0APlease check your input.");
		}
		else {
			errorMessage = unescape("Ihre E-Mail Adresse ist ung%FCltig.%0A%0ABitte %FCberpr%FCfen Sie Ihre Eingabe.");
		}
	}
	if (errorMessage != '') {
		alert (errorMessage);
	}
	else document[theForm].submit();
}

// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


function isValidEmail(str) {
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0) && (str.indexOf(".") < str.length - 2);
}
//change cursor to hand
function hand(theId) {

	if (!document.all) {
		document.getElementById(theId).style.cursor ='pointer';
	}
	else {
		document.all(theId).style.cursor ='hand';
	}
}

function changeImg(theId,theFile) {
	tempId = theId.split(",");
	tempFile = theFile.split(",");
	x = 0;
	do {
		if (document.getElementById(tempId[x]) && (tempFile[x])) {
			document.getElementById(tempId[x]).src = tempFile[x];
		}
	  x = x + 1;
	} while (x < tempId.length);
}

function changeImage(imageId, thePath, theImg, linkId, color) {
	//alert (thePath);
	if (document.getElementById(imageId)) {
		document.getElementById(imageId).src = thePath+theImg;
	}
	if (document.getElementById(linkId)) {
		document.getElementById(linkId).style.color = color;
	}
}

function highlightThis(imageId, thePath, theImg, linkId, color) {
	if (document.getElementById(imageId)) {
		document.getElementById(imageId).src = thePath+theImg;
	}
	if (document.getElementById(linkId)) {
		document.getElementById(linkId).style.color = color;
	}
}

function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {
	var i, j;
	var prompt;

	// empty existing items
	for (i = selectCtrl.options.length; i >= 0; i--) {
		selectCtrl.options[i] = null; 
	}
	prompt = (itemArray != null) ? goodPrompt : badPrompt;
	if (prompt == null) {
		j = 0;
	} else {		
		selectCtrl.options[0] = new Option(prompt);
		j = 1;
	}
	if (itemArray != null) {
		// add new items
		for (i = 0; i < itemArray.length; i++) {
			selectCtrl.options[j] = new Option(itemArray[i][0]);
			if (itemArray[i][1] != null) {
				selectCtrl.options[j].value = itemArray[i][1]; 
			}
			j++;
		}
		// select first item (prompt) for sub list
		selectCtrl.options[0].selected = true;
	}
}

