function no_right_click() {
	if(event.button == 2)
	alert("copyright <?php echo SITENAME; ?>");
}

function ValidateForm(whichForm){ 
	var ok=true;
	var msg=""; 	

	if (checkrequired(whichForm)==false) {
		msg=msg+"Du har glömt att fylla i ett eller flera obligatoriska fält.\n";
		ok=false;
	}		
	if (checkEmail(whichForm)==false) {
		msg=msg+"Du har angett en ogiltig epost-adress.\n";
		ok=false;
	}		
	if (checkIfEmpty(whichForm)==false) {
		msg=msg+"Formuläret kan inte skickas om det är tomt!\n";
		ok=false;
	}	

	if (checkNumber(whichForm)==false) {
		msg=msg+"Siffran är i fel format..\n";
		ok=false;
	}
	if (ok==false) {
		alert(msg);
		return false;
	} else { return true; }		
}




function Trim(string) {
  while (string.substring(0,1) == ' ') {
    string = string.substring(1,string.length);
  }
  while (string.substring(string.length-1,string.length) == ' ') {
    string = string.substring(0,string.length-1);
  }
  return string;
}

function ValidateEmail(email){
	if (email.match(/^([a-zA-Z0-9]{1}([a-zA-Z0-9\.\-\_]*)[a-zA-Z0-9]{1})@([a-zA-Z0-9]{1}([a-zA-Z0-9\.\-\_]*)[a-zA-Z0-9]{1})\.([a-zA-Z]{2,4})$/)){
	return true;}
	 else { return false; }
}

function checkEmail(which){ 
	var pass=true
	if (document.images){
		for (i=0;i<which.length;i++){
			var tempobj=which.elements[i]
			if (tempobj.id.substring(0,6)=="email_"||tempobj.id.substring(0,10)=="req_email_"){
				if(tempobj.value!=''){
					if ((tempobj.type=="text"||tempobj.type=="textarea"||tempobj.type=="file")&&ValidateEmail(tempobj.value)==false){
						pass=false;
						break;
					}
				}
			}
		}
	}
	if (!pass){
		tempobj.focus();
		return false;
	}
	else {
		return true
	}
}

function checkIfEmpty(which){
	var pass=true
	if (document.images){ 
		for (i=0;i<which.length;i++){
			var tempobj=which.elements[i]
			if (tempobj.type=="text"||tempobj.type=="textarea"||tempobj.type=="file"){
				if (Trim(tempobj.value)==''){
					pass=false; 
				} else { pass=true; break; }
			} else {					
				if(tempobj.type.toString().charAt(0)=="s"&&tempobj.type!="submit"){
					if(tempobj.selectedIndex==''){ pass=false; } else { pass=true; break; }
				}
			}
		}
	}
	if (!pass){
		return false;
	}
	else {
		return true
	}
}

function checkrequired(which){
	var pass=true
	if (document.images){
		for (i=0;i<which.length;i++){
			var tempobj=which.elements[i]
			if (tempobj.id.substring(0,4)=="req_"){
				if (((tempobj.type=="text"||tempobj.type=="textarea"||tempobj.type=="file")&&Trim(tempobj.value)=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1)){
					pass=false;
					break;
				}
			}
		}
	}
	if (!pass){
		tempobj.focus();
		return false;
	}
	else {
		return true
	}
}

function checkNumber(which){ 
	var pass=true
	if (document.images){
		for (i=0;i<which.length;i++){
			var tempobj=which.elements[i]
			if (tempobj.id.substring(0,7)=="number_"||tempobj.id.substring(0,11)=="req_number_"){
				if(tempobj.value!=''){
					if ((tempobj.type=="text"||tempobj.type=="textarea"||tempobj.type=="file")&&ValidateIfNumber(tempobj.value)==false){
						pass=false;
						break;
					}
				}
			}
		}
	}
	if (!pass){
		tempobj.focus();
		return false;
	}
	else {
		return true
	}
}

function ValidateIfNumber(string){
	if(isNaN(string)){
		return false;
	} else { return true; }
}

function ValidateMinStringLength(string, value){
	if(string.length<value){
		return false;
	} else { return true; }
}

function ValidateMaxStringLength(string, value){
	if(string.length>value){
		return false;
	} else { return true; }
}

function OpenSmallWindow(url){
	newWindow=window.open(url, "Info", "width=357,height=600, scrollbars=yes");
}
