function trim(str){
  return str.replace(/^\s*|\s*$/g,"");
}
function CheckLength(iForm,iTextbox,iMessage,iMiniLength){
  //for textbox and selectbox
  iStr = eval("document." + iForm + "." + iTextbox + ".value")
  iStr = trim(iStr)
  if (iStr.length < iMiniLength){
    alert(iMessage);
    eval("document." + iForm + "." + iTextbox + ".focus()")
    return false;
  }
  return true;
}
function CheckEmail(iForm,iTextbox,iMessage){
  iStr = eval("document." + iForm + "." + iTextbox + ".value")
  iStr = trim(iStr)
  if ((iStr.indexOf('@') < 0)||(iStr.indexOf('.')) < 0||(iStr.length < 8)){
    alert(iMessage);
    eval("document." + iForm + "." + iTextbox + ".focus()")
    return false;
  }
  return true;
}
function CheckRadio(iForm,iRadio,iMessage){
  //kollar så att något alternativ är markerat i en eller flera radio-buttons
  var radioLength = eval("document." + iForm + "." + iRadio + ".length")
  var radioObj = eval("document." + iForm + "." + iRadio + "")
  for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked){
      return true;
      break
		}
  }
  alert(iMessage);
  return false;
}
function CheckIfEmpty(theform, fieldname, errormess) {
  var checkstring = "document." + theform + "." + fieldname + ".value.length"
  if (eval(checkstring) == 0) {
    if (errormess.length > 0)
      alert(errormess)
      eval("document." + theform + "." + fieldname + ".focus()")
      return false
  }
  else
  return true
}

function CheckIfNumber(TheForm,TheText,Message){
	var inputVal = eval("document."+TheForm+"."+TheText+".value")
	oneDecimal = true
	inputStr = inputVal.toString()
	for (var i = 0; i < inputStr.length; i++){
		var oneChar = inputStr.charAt(i)
		if (i == 0 && oneChar == "-"){
			continue
		}
		if (oneChar == "," && !oneDecimal){
			oneDecimal = true
			continue
		}
		if (oneChar < "0" || oneChar > "9"){
			alert (Message);
			eval("document."+TheForm+"."+TheText+".focus()")
			return false
		}
	}
	//return true
}


function Confirm(url,thetext){ 
  if(confirm(thetext)){ 
    location.href = url; 
  }
}
function CheckFile(myForm,myField,myType){
  //x = document.myForm.myUploadField.value.substring(document.myForm.myUploadField.value.length-4)
  myType = myType.toUpperCase();
  myValue = eval("document."  + myForm + "."  + myField + ".value")
  myExtension = myValue.substring(myValue.length-3)
  myExtension = myExtension.toUpperCase();
  if(myValue.length==0){
    alert('Du måste välja en bild. Klicka på bläddra!')
    return false;
	}
	if (myExtension!=myType){
    alert ('Fel filtyp!');
    return false;
	}
	else{
    alert('Filen kommer nu att laddas upp till webbsidan. Det kan ta ca en minut!');
    return true;
	}
}
function PopupBild(sida,namn,bredd,hojd) {
	//if(window.showModalDialog){
	//	hojd = parseInt(hojd) + 36 + 4
	//	bredd = parseInt(bredd) + 10
	//	window.showModalDialog(sida, namn,'dialogHeight:'+hojd+'px;dialogWidth:'+bredd+'px; center:yes; resizable:no; status:no; help:no; edge:sunken'); 
	//}
	//else{
		window.open(sida,namn,'width='+bredd+',height='+hojd+',location=no,menubar=no,directories=no,scrollbars=no,resizable=no,status=no')
	//}
}
function PopupVideo(sida,namn,bredd,hojd) {
	window.open(sida,namn,'width='+bredd+',height='+hojd+',location=no,menubar=no,directories=no,scrollbars=no,resizable=yes,status=no')
}
function Popup(sida,namn,bredd,hojd) {
	window.open(sida,namn,'width='+bredd+',height='+hojd+',location=no,menubar=no,directories=no,scrollbars=no,resizable=yes,status=no')
}



