/*
This file includes the functions needed for checking and handling the qa-forms 
The functions are


function LimitText(fieldObj,maxChars)	Used to limit the Value of a field to a certain length e.g. for <textarea>
										example: onkeypress="LimitText(this, 2048)"

function colorize(element, colorized)   Adds a red highlighting to the desired element works for <p><input(no checkbox)><textarea>

function goBack()                       Before Navigating to the tab before the user is asked for a confirmation
										(Needed as long as no Database support for navigating back in contribution forms is implemented)
										
function isInteger(s)				 	Checks if a string consist of digits - also true if string is empty

function checkradio(radioname)			Checks a group of radiobuttons named the same way if one of them is checked --- returns false if none is checked

function setdisplaystyle(style,element)	Sets the displaystyle to the desired string, element caught by getElementById

*/


function LimitText(fieldObj,maxChars){
  if (fieldObj.value.length >= maxChars) fieldObj.value=fieldObj.value.substring(0,(maxChars-1));
}

function colorize(element,colorized)	{
	if (colorize.arguments[2]) {
		color = colorize.arguments[2]; 
	}
	else { 
		if (colorized==true)
			color = 'FF0000'; 
		else
			color = '000000'; 
	}
	try {
		if (colorized==true) {
			if (element.type != "") {
				if ((element.type=="text") || (element.type=="password")) {
					element.style.borderColor=color;
					element.style.borderStyle="solid";
					element.style.borderWidth="1px";
				}
				else if (element.type=="radio") {
					element.style.background=color;
				}
				else if (element.type=="checkbox") {
					element.style.color=color;
					element.style.borderColor=color;
					element.style.borderStyle="solid";
					element.style.borderWidth="1px";
				}
				else if (element.type=="select-one") {
					element.style.color=color;
					element.style.borderColor=color;
					element.style.borderStyle="solid";
					element.style.borderWidth="1px";
				}
				else if (element.type=="select-multiple") {
					element.style.color=color;
					element.style.borderStyle="solid";
					element.style.borderWidth="1px";
				}
				else if (element.type=="textarea") {
					element.style.borderStyle="solid";
					element.style.borderWidth="1px";
					element.style.borderColor=color;
				}
				else if (element.type=="button") {
					element.style.color=color;
				}
				else 
					element.style.color=color;
			}
			else {
				element.style.color=color;
			}
		}
		if (colorized!=true) {
			if (element.type != "") {
				if ((element.type=="text") || (element.type=="password")) {
					element.style.borderColor=color;
					element.style.borderStyle="solid";
					element.style.borderWidth="1px";
				}
				else if (element.type=="checkbox"){
				}
				else if (element.type=="select-one") {
					element.style.color=color;
					element.style.borderStyle="solid";
					element.style.borderWidth="1px";
				}
				else if (element.type=="select-multiple") {
					element.style.color=color;
					element.style.borderStyle="solid";
					element.style.borderWidth="1px";
				}
				else if (element.type=="textarea") {
					element.style.color=color;
					element.style.borderStyle="solid";
					element.style.borderWidth="1px";
					element.style.borderColor=color;
				}
				else if (element.type=="button") {
					element.style.color=color;
				}
				else
					element.style.color=color;
			}
			else {
				element.style.color=color;
			}
		}
	}
	catch(e) {
		try{
		alert(e.description+"#"+element + "type"+element.type);
		}catch(e){
			//alert(element);
		}
	}
}

function goBack()	{
	Check = confirm("Unfortunally at the moment all changes to this page will be lost if you continue.\nDo you still want to go backwards?");
	if(Check) {
		history.go(-1);
		if (navigator.appName!="Netscape") window.location.reload();
	}
}	

function isInteger(s){
	var i;
    if (s.length=0) return true;
    for (i = 0; i < s.length; i++){   
       	var c = s.charAt(i);
        if (isNaN(c)) return false;
   	}
    return true;
}
	
function checkradio(radioname){	
	var t_error=false;
	element=document.getElementsByName(radioname);
	for (i=0; i<element.length; i++){ 
		try	{ 
			if(element[i].checked==true) t_error=true; 
		}
		catch(e){}
	}
	return t_error;
}

function setdisplaystyle(style, element){
	if (document.getElementById(element).style.display) document.getElementById(element).style.display=style;
}

function isEmail(str){
		filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (filter.test(str))		{
			return true;
		}
		else return false;	
}
/*
function validate_email(mailerror,str){
	//str=document.invite_form.email.value;
	if (str != ""){
		str=str.split(',');
		var err = 0;
		var badmails = "";
		filter=/^(\w+((?:\.\w+)||(?:\-\w+))*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		
		for (j=0;j<str.length;j++){
			if (filter.test(str[j]) != true){
				badmails += str[j] + "\n";
				err = 1;
			}
		}
		
		if (err){
			alert(mailerror += "\n" + badmails);
		//}else document.invite_form.submit();
		//}else alert(empty);
		}else{
			return true;
		}
	}
	
}*/
