/**
 *  File for validation of values in advancedserhform.jsp before search is done
 */

// ---- validation-methods --------

function validateLMS(){
  var allrequired=true;
  var params= new Array(1);
  unColorAllElements();
  
  //if county is not choosen
  /*if(document.getElementById("countyLMS").selectedIndex==-1 || document.getElementById("countyLMS").selectedIndex==0){
    allrequired=false;
    params[0]=propertyCommonCounty;
    document.getElementById("countyLMS").style.backgroundColor="#F0E68C";
  }*/
  if(allrequired){


   //if user search with only 1 wildcard (*)
     if(document.getElementById("countyLMSradio").checked && document.getElementById("countyLMS").selectedIndex=="0"){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.public.countymaptype",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("countyLMS").style.backgroundColor="#F0E68C";
      return false;
     }

	 //if user har choosen maptype but not specified an map i dropdownlist
	 if(document.getElementById("maptypeLMSradio").checked && document.getElementById("mapType").selectedIndex=="0"){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.public.countymaptype",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("mapType").style.backgroundColor="#F0E68C";
      return false;
     }

   //if user search with only 1 wildcard (*)
     if(document.getElementById("surveyor").value=="*"){
      PropertyClass.getPropertyValue("validation.commons.invalid.value",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("surveyor").style.backgroundColor="#F0E68C";
      return false;
     }
  //if opensearch AND surveyor has illegal characters (member)
     if((document.getElementById("user").value=="member")&&hasIllegalCharacter(document.getElementById("openSearchLMS").value)&&hasIllegalCharacter(document.getElementById("surveyor").value)){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.illegalcharacter.member.opensearchAndSurveyor",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("openSearchLMS").style.backgroundColor="#F0E68C";
      document.getElementById("surveyor").style.backgroundColor="#F0E68C";
      return false;
    }
    //if opensearch search with only 1 wildcard (*)
     if(document.getElementById("user").value=="member"&&document.getElementById("openSearchLMS").value=="*"){
      PropertyClass.getPropertyValue("validation.commons.invalid.value",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("openSearchLMS").style.backgroundColor="#F0E68C";
      return false;
    }
     //if opensearch has illegal characters (member)
     if(document.getElementById("user").value=="member"&&hasIllegalCharacter(document.getElementById("openSearchLMS").value)){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.illegalcharacter.member.opensearch",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("openSearchLMS").style.backgroundColor="#F0E68C";
      return false;
    }
    //if opensearch has less than 4 characters (member)
     //if((document.getElementById("user").value=="member")&&(document.getElementById("openSearchLMS").value.length>0)&&(document.getElementById("openSearchLMS").value.length<4)){
      //PropertyClass.getPropertyValue("advancedSearchForm.error.validation.characters",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      //document.getElementById("openSearchLMS").style.backgroundColor="#F0E68C";
      //return false;
    //}

    //if opensearch (member) AND surveyor has more than one star (*)
    else if(document.getElementById("user").value=="member"&&hasTwoStars(document.getElementById("openSearchLMS").value)&&hasTwoStars(document.getElementById("surveyor").value)){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.stars.member.opensearchAndSurveyor",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("openSearchLMS").style.backgroundColor="#F0E68C";
      document.getElementById("surveyor").style.backgroundColor="#F0E68C";
      return false;
    }
    //if opensearch (member) has more than one star (*)
    else if(document.getElementById("user").value=="member"&&hasTwoStars(document.getElementById("openSearchLMS").value)){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.stars.member.opensearch",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("openSearchLMS").style.backgroundColor="#F0E68C";
      return false;
    }
     //if both years contain character other than number
    else if(((document.getElementById("yearMinLMS").value!="")&&(!isNumber(document.getElementById("yearMinLMS").value)))&&((document.getElementById("yearMaxLMS").value!="")&&(!isNumber(document.getElementById("yearMaxLMS").value)))){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.year.NaN",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("yearMinLMS").style.backgroundColor="#F0E68C";
      document.getElementById("yearMaxLMS").style.backgroundColor="#F0E68C";
      return false;
    }
    //if year min contains character other than number
    else if((document.getElementById("yearMinLMS").value!="")&&(!isNumber(document.getElementById("yearMinLMS").value))){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.year.NaN",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("yearMinLMS").style.backgroundColor="#F0E68C";
      return false;
    }
    //if year max contains character other than number
    else if((document.getElementById("yearMaxLMS").value!="")&&(!isNumber(document.getElementById("yearMaxLMS").value))){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.year.NaN",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("yearMaxLMS").style.backgroundColor="#F0E68C";
      return false;
    }
    //if year max and year min has not 4 characters
    else if((document.getElementById("yearMaxLMS").value!=""&&document.getElementById("yearMinLMS").value!="")&&((document.getElementById("yearMaxLMS").value.length!=4)&&(document.getElementById("yearMinLMS").value.length!=4))){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.year.format",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("yearMaxLMS").style.backgroundColor="#F0E68C";
      document.getElementById("yearMinLMS").style.backgroundColor="#F0E68C";
      return false;
    }
    //if year max has more than 4 characters
    else if(document.getElementById("yearMaxLMS").value!=""&&document.getElementById("yearMaxLMS").value.length!=4){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.year.format",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("yearMaxLMS").style.backgroundColor="#F0E68C";
      return false;
    }
    //if year min has more than 4 characters
    else if(document.getElementById("yearMinLMS").value!=""&&document.getElementById("yearMinLMS").value.length!=4){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.year.format",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("yearMinLMS").style.backgroundColor="#F0E68C";
      return false;
    }
    //if yearmin is bigger than yearmax
    else if(((document.getElementById("yearMinLMS").value!="")&&(document.getElementById("yearMaxLMS").value!=""))&&(parseInt(document.getElementById("yearMinLMS").value)>parseInt(document.getElementById("yearMaxLMS").value))){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.year.size",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("yearMaxLMS").style.backgroundColor="#F0E68C";
      document.getElementById("yearMinLMS").style.backgroundColor="#F0E68C";
      return false;
    }
     //if  both years are earlier than 1600
    else if(((document.getElementById("yearMaxLMS").value!="")&&(document.getElementById("yearMinLMS").value!=""))&&((parseInt(document.getElementById("yearMaxLMS").value)<parseInt(propertyArchiveStartYear))&&(parseInt(document.getElementById("yearMinLMS").value)<parseInt(propertyArchiveStartYear)))){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.year.old",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("yearMaxLMS").style.backgroundColor="#F0E68C";
      document.getElementById("yearMinLMS").style.backgroundColor="#F0E68C";
      return false;
    }
     //if  yearmin is earlier than 1600
     else if((document.getElementById("yearMinLMS").value!="")&&(parseInt(document.getElementById("yearMinLMS").value)<parseInt(propertyArchiveStartYear))){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.year.old",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("yearMinLMS").style.backgroundColor="#F0E68C";
      return false;
    }
    //if yearmax is earlier than 1600
     else if((document.getElementById("yearMaxLMS").value!="")&&(parseInt(document.getElementById("yearMaxLMS").value)<parseInt(propertyArchiveStartYear))){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.year.old",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("yearMaxLMS").style.backgroundColor="#F0E68C";
      return false;
    }
    //if yearmax is bigger than 1928 and not member
    /* else if(document.getElementById("user").value!="member" && parseInt(document.getElementById("yearMaxLMS").value)>1928){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.year.public.pul",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("yearMaxLMS").style.backgroundColor="#F0E68C";
      return false;
    }*/


    //if surveyor has illegal characters
    else if(hasIllegalCharacter(document.getElementById("surveyor").value)){
     PropertyClass.getPropertyValue("advancedSearchForm.error.validation.illegalcharacter.surveyor",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("surveyor").style.backgroundColor="#F0E68C";
      return false;
    }
    //if surveyor  has more than one star (*)
    else if(hasTwoStars(document.getElementById("surveyor").value)){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.stars.surveyor",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("surveyor").style.backgroundColor="#F0E68C";
      return false;
    }
    setLMSTextCookies();
    createLMSCookies();
    return true;

  }
  else{
    //prints errormessage
    validationErrorHandler(params);
    return false;
  }

}
function validateRAK(){

  var validates=true;
  var params= new Array(3);
  unColorAllElements();

  //if series is not choosen
  if(document.getElementById("series").selectedIndex==-1 || document.getElementById("series").selectedIndex==0){
    validates=false;
    params[0]=propertyCommonSeries;
    document.getElementById("series").style.backgroundColor="#F0E68C";
  }
  //if county is not choosen
  if(document.getElementById("countyRAK").selectedIndex==-1 || document.getElementById("countyRAK").selectedIndex==0){
    validates=false;
    params[1]=propertyCommonCounty;
    document.getElementById("countyRAK").style.backgroundColor="#F0E68C";
  }
  //if page is not choosen
  if(document.getElementById("page").selectedIndex==-1 || document.getElementById("page").selectedIndex==0){
    validates=false;
    params[2]=propertyCommonPage;
    document.getElementById("page").style.backgroundColor="#F0E68C";
  }
  if(validates){
    createRAKCookies();
    return true;
  }
  else{
    //prints errormessage
    validationErrorHandler(params);
    return false;
  }
}

function validateREG(){
  var allrequired=true;
  var params= new Array(2);
  unColorAllElements();

  //if county is not choosen
  if(document.getElementById("countyREG").selectedIndex==-1 || document.getElementById("countyREG").selectedIndex==0){
    allrequired=false;
    params[0]=propertyCommonCounty;
    document.getElementById("countyREG").style.backgroundColor="#F0E68C";
  }

  if(document.getElementById("user").value!="member"){
    //if municipality or parish is not choosen
    if(document.getElementById("munParREG") && (document.getElementById("munParREG").selectedIndex==-1 || document.getElementById("munParREG").selectedIndex==0)){
      allrequired=false;
      params[1]=propertyErrorMunicipality+"/"+propertyErrorParish;;
      document.getElementById("munParREG").style.backgroundColor="#F0E68C";
    }
  }

  //if public and village is not written
  if(document.getElementById("searchTypeM") && document.getElementById("searchTypeM").checked){//if not parish then must search ort/akt
    if((document.getElementById("user").value!="member")&&((document.getElementById("openSearchREG").value=="")||(document.getElementById("openSearchREG").value==" "))){
      allrequired=false;
      params[2]=propertyCommonVillage;
      document.getElementById("openSearchREG").style.backgroundColor="#F0E68C";
    }
  }
  
  
  
  //if public and parish is chosen and opensearch is to short
  if(document.getElementById("searchTypeP") && document.getElementById("searchTypeP").checked){//if  parish 
    if((document.getElementById("user").value!="member")&&((document.getElementById("openSearchREG").value!="")&&(document.getElementById("openSearchREG").value!=" "))){
	  if(document.getElementById("openSearchREG").value.length > 0 && document.getElementById("openSearchREG").value.length < 4 && document.getElementById("searchTypeD").checked){
		allrequired=false;
		PropertyClass.getPropertyValue("validation.commons.length",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
		document.getElementById("openSearchREG").style.backgroundColor="#F0E68C";
	  }
    }
  }
  
  
  if(document.getElementById("searchTypeM") && document.getElementById("searchTypeM").checked){//if kommun 
	if(document.getElementById("searchTypeD") && document.getElementById("searchTypeD").checked){//if kommun 
		if(document.getElementById("openSearchREG").value.length > 0 && document.getElementById("openSearchREG").value.length < 4){
			allrequired=false;
			PropertyClass.getPropertyValue("validation.commons.length",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
			document.getElementById("openSearchREG").style.backgroundColor="#F0E68C";
	  }
	}
	
  }



    /*if(document.getElementById("user").value!="member"){
      if(document.getElementById("openSearchREG")&&((document.getElementById("openSearchREG").value=="")||(document.getElementById("openSearchREG").value==" "))){
        allrequired=false;
        params[1]=propertyCommonVillage;
        document.getElementById("openSearchREG").style.backgroundColor="#F0E68C";
      }
    }*/

  if(allrequired){
      //if user search with only 1 wildcard (*)
      if(document.getElementById("openSearchREG").value=="*"){
      PropertyClass.getPropertyValue("validation.commons.invalid.value",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
        document.getElementById("openSearchREG").style.backgroundColor="#F0E68C";
        return false;
      }

      //if member and only county is choosen
      if((document.getElementById("user").value=="member")&&(document.getElementById("openSearchREG").value=="")&&(document.getElementById("yearMinREG").value=="")&&(document.getElementById("yearMaxREG").value=="")&&(document.getElementById("document").value=="")&&(document.getElementById("taskREG").selectedIndex==-1 || document.getElementById("taskREG").selectedIndex==0)){
      //if((document.getElementById("user").value=="member")&&(document.getElementById("openSearchREG").value=="")&&(document.getElementById("yearMinREG").value=="")&&(document.getElementById("yearMaxREG").value=="")&&(document.getElementById("taskREG").selectedIndex==-1 || document.getElementById("taskREG").selectedIndex==0)){
        PropertyClass.getPropertyValue("advancedSearchForm.error.validation.member.allempty",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
        document.getElementById("openSearchREG").style.backgroundColor="#F0E68C";
        document.getElementById("yearMinREG").style.backgroundColor="#F0E68C";
        document.getElementById("yearMaxREG").style.backgroundColor="#F0E68C";
        document.getElementById("document").style.backgroundColor="#F0E68C";
        document.getElementById("taskREG").style.backgroundColor="#F0E68C";
        return false;
      }
      //if opensearch AND document has illegal characters (public)
     //if(document.getElementById("user").value!="member"&&(hasIllegalCharacter(document.getElementById("openSearchREG").value))&&(hasIllegalCharacter(document.getElementById("document").value))){
     if(document.getElementById("user").value!="member"&&(hasIllegalCharacter(document.getElementById("openSearchREG").value))){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.illegalcharacter.public.opensearchAndDocumentReg",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("openSearchREG").style.backgroundColor="#F0E68C";
      //document.getElementById("document").style.backgroundColor="#F0E68C";
      return false;
     }
     //if opensearch AND document has illegal characters (member)
     if(document.getElementById("user").value=="member"&&(hasIllegalCharacter(document.getElementById("openSearchREG").value))&&(hasIllegalCharacter(document.getElementById("document").value))){
     //if(document.getElementById("user").value=="member"&&(hasIllegalCharacter(document.getElementById("openSearchREG").value))){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.illegalcharacter.member.opensearchAndDocumentReg",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("openSearchREG").style.backgroundColor="#F0E68C";
      document.getElementById("document").style.backgroundColor="#F0E68C";
      return false;
    }
    //if opensearch has illegal characters (public)
    else if((document.getElementById("user").value!="member")&&(hasIllegalCharacter(document.getElementById("openSearchREG").value))){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.illegalcharacter.public.opensearch",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("openSearchREG").style.backgroundColor="#F0E68C";
      return false;
    }
		//if opensearch has illegal characters (member)
    else if((document.getElementById("user").value=="member")&&(hasIllegalCharacter(document.getElementById("openSearchREG").value))){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.illegalcharacter.member.opensearchReg",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("openSearchREG").style.backgroundColor="#F0E68C";
      return false;
    }
    //if opensearch (member) AND document has more than one star (*)
    else if(document.getElementById("user").value=="member"&&hasTwoStars(document.getElementById("openSearchREG").value)&&hasTwoStars(document.getElementById("document").value)){
    //else if(document.getElementById("user").value=="member"&&hasTwoStars(document.getElementById("openSearchREG").value)){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.stars.member.opensearchAndDocument",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("openSearchREG").style.backgroundColor="#F0E68C";
      document.getElementById("document").style.backgroundColor="#F0E68C";
      return false;
    }
    //if opensearch (public) AND document has more than one star (*)
    //else if(document.getElementById("user").value!="member"&&hasTwoStars(document.getElementById("openSearchREG").value)&&hasTwoStars(document.getElementById("document").value)){
    else if(document.getElementById("user").value!="member"&&hasTwoStars(document.getElementById("openSearchREG").value)){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.stars.public.opensearchAndDocument",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("openSearchREG").style.backgroundColor="#F0E68C";
      //document.getElementById("document").style.backgroundColor="#F0E68C";
      return false;
    }
    //if opensearch (member) has more than one star (*)
    else if(hasTwoStars(document.getElementById("openSearchREG").value)){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.stars.member.opensearch",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("openSearchREG").style.backgroundColor="#F0E68C";
      return false;
    }
		else if(document.getElementById("user").value!="member"&& (!document.getElementById("searchTypeD").checked && !document.getElementById("searchTypeV").checked)){
			if(document.getElementById("openSearchREG").value.length > 0 && document.getElementById("openSearchREG").value.length < 4){
				PropertyClass.getPropertyValue("advancedSearchForm.error.validation.characters",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
				document.getElementById("openSearchREG").style.backgroundColor="#F0E68C";
				return false;
			}
		}
		//if opensearch has less than 4 characters
			//else if((document.getElementById("openSearchREG").value.length > 0) && (document.getElementById("openSearchREG").value.length < 4)){
				//PropertyClass.getPropertyValue("advancedSearchForm.error.validation.characters",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
				//document.getElementById("openSearchREG").style.backgroundColor="#F0E68C";
				//return false;
			//}
    //if both years are not numbers
    else if(((document.getElementById("yearMinREG").value!="")&&(!isNumber(document.getElementById("yearMinREG").value)))&&((document.getElementById("yearMaxREG").value!="")&&(!isNumber(document.getElementById("yearMaxREG").value)))){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.year.NaN",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("yearMinREG").style.backgroundColor="#F0E68C";
      document.getElementById("yearMaxREG").style.backgroundColor="#F0E68C";
      return false;
    }
    //if yearmin is not a number
    else if((document.getElementById("yearMinREG").value!="")&&(!isNumber(document.getElementById("yearMinREG").value))){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.year.NaN",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("yearMinREG").style.backgroundColor="#F0E68C";
      return false;
    }
    //if yearmax is not a number
    else if((document.getElementById("yearMaxREG").value!="")&&(!isNumber(document.getElementById("yearMaxREG").value))){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.year.NaN",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("yearMaxREG").style.backgroundColor="#F0E68C";
      return false;
    }
    //if year max and year min has more than 4 characters
    else if((document.getElementById("yearMaxREG").value.length!="")&&(document.getElementById("yearMinREG").value.length!="")&&(document.getElementById("yearMaxREG").value.length!=4)&&(document.getElementById("yearMinREG").value.length!=4)){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.year.format",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("yearMaxREG").style.backgroundColor="#F0E68C";
      document.getElementById("yearMinREG").style.backgroundColor="#F0E68C";
      return false;
    }
    //if year max has more than 4 characters
    else if(document.getElementById("yearMaxREG").value!=""&&document.getElementById("yearMaxREG").value.length!=4){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.year.format",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("yearMaxREG").style.backgroundColor="#F0E68C";
      return false;
    }
    //if year min has more than 4 characters
    else if(document.getElementById("yearMinREG").value.length!=""&&document.getElementById("yearMinREG").value.length!=4){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.year.format",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("yearMinREG").style.backgroundColor="#F0E68C";
      return false;
    }
    //if yearmin is i bigger than yearmax
    else if(((document.getElementById("yearMinREG").value!="")&&(document.getElementById("yearMaxREG").value!=""))&&(parseInt(document.getElementById("yearMinREG").value)>parseInt(document.getElementById("yearMaxREG").value))){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.year.size",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("yearMaxREG").style.backgroundColor="#F0E68C";
      document.getElementById("yearMinREG").style.backgroundColor="#F0E68C";
      return false;
    }
     //if  both years are earlier than 1600

    else if(((document.getElementById("yearMaxREG").value!="")&&(document.getElementById("yearMinREG").value!=""))&&((parseInt(document.getElementById("yearMaxREG").value)<parseInt(propertyArchiveStartYear))&&(parseInt(document.getElementById("yearMinREG").value)<parseInt(propertyArchiveStartYear)))){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.year.old",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("yearMaxREG").style.backgroundColor="#F0E68C";
      document.getElementById("yearMinREG").style.backgroundColor="#F0E68C";
      return false;
    }
     //if  yearmin is earlier than 1600
     else if((document.getElementById("yearMinREG").value!="")&&(parseInt(document.getElementById("yearMinREG").value)<parseInt(propertyArchiveStartYear))){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.year.old",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("yearMinREG").style.backgroundColor="#F0E68C";
      return false;
    }
    //if yearmax is earlier than 1600
     else if((document.getElementById("yearMaxREG").value!="")&&(parseInt(document.getElementById("yearMaxREG").value)<parseInt(propertyArchiveStartYear))){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.year.old",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("yearMaxREG").style.backgroundColor="#F0E68C";
      return false;
    }
    //if pul and public and both years are bigger than 1928
    else if(((document.getElementById("pul").value=="true")&&(document.getElementById("user").value!="member"))&&((parseInt(document.getElementById("yearMaxREG").value)>parseInt(propertyPulYear))&&(parseInt(document.getElementById("yearMinREG").value)>parseInt(propertyPulYear)))){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.year.public.pul",{callback:pulErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("yearMaxREG").style.backgroundColor="#F0E68C";
      document.getElementById("yearMinREG").style.backgroundColor="#F0E68C";
      return false;
    }
     //if pul and public and yearmin is bigger than 1928
     else if((document.getElementById("pul").value=="true")&&(document.getElementById("user").value!="member")&&(parseInt(document.getElementById("yearMinREG").value)>parseInt(propertyPulYear))){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.year.public.pul",{callback:pulErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("yearMinREG").style.backgroundColor="#F0E68C";
      return false;
    }
    //if pul and public and yearmax is bigger than 1928
     else if((document.getElementById("pul").value=="true")&&(document.getElementById("user").value!="member")&&(parseInt(document.getElementById("yearMaxREG").value)>parseInt(propertyPulYear))){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.year.public.pul",{callback:pulErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("yearMaxREG").style.backgroundColor="#F0E68C";
      return false;
    }
		else if((document.getElementById("user").value=="member")&&(document.getElementById("document").value=="*")){
      PropertyClass.getPropertyValue("validation.commons.invalid.value",{callback:pulErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("document").style.backgroundColor="#F0E68C";
      return false;
    }
		//if opensearch has illegal characters (public)
    else if((document.getElementById("user").value=="member")&&(hasIllegalCharacter(document.getElementById("document").value))){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.illegalcharacter.document",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("document").style.backgroundColor="#F0E68C";
      return false;
    }
		else if(document.getElementById("user").value=="member"&&hasTwoStars(document.getElementById("document").value)){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.illegalcharacter.member.document",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("document").style.backgroundColor="#F0E68C";
      return false;
    }
		else if((document.getElementById("user").value=="member")&&(document.getElementById("document").value.length>0)&&(document.getElementById("document").value.length<4)){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.characters",{callback:pulErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("document").style.backgroundColor="#F0E68C";
      return false;
    }
    //if pul and member and both years are bigger than 1928
    /* else if((document.getElementById("pul").value=="true")&&(document.getElementById("user").value=="member")&&(parseInt(document.getElementById("yearMaxREG").value)>1928)&&(parseInt(document.getElementById("yearMinREG").value)>1928)){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.year.member.pul",{callback:alternatePulErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("yearMaxREG").style.backgroundColor="#F0E68C";
      document.getElementById("yearMinREG").style.backgroundColor="#F0E68C";
      return false;
    }*/
     //if pul and member and yearmin is bigger than 1928
     /*else if((document.getElementById("pul").value=="true")&&(document.getElementById("user").value=="member")&&(parseInt(document.getElementById("yearMinREG").value)>1928)){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.year.member.pul",{callback:alternatePulErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("yearMinREG").style.backgroundColor="#F0E68C";
      return false;
    }*/
    //if pul and member and yearmax is bigger than 1928
     /*else if((document.getElementById("pul").value=="true")&&(document.getElementById("user").value=="member")&&(parseInt(document.getElementById("yearMaxREG").value)>1928)){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.year.member.pul",{callback:alternatePulErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("yearMaxREG").style.backgroundColor="#F0E68C";
      return false;
    }*/
    //if document has illegal characters (member)
    /*else if(hasIllegalCharacter(document.getElementById("document").value)){
     PropertyClass.getPropertyValue("advancedSearchForm.error.validation.illegalcharacter.document",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("document").style.backgroundColor="#F0E68C";
      return false;
    }*/
    //if document has more than one star (*)
    /*else if(hasTwoStars(document.getElementById("document").value)){
      PropertyClass.getPropertyValue("advancedSearchForm.error.validation.stars.document",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
      document.getElementById("document").style.backgroundColor="#F0E68C";
      return false;
    }*/

    setREGTextCookies();
    createREGCookies();
    return true;
  }
  else{
    //prints errormessage
    validationErrorHandler(params);
    return false;
  }
}


function isNumber(input){
     for (var i = 0; i<input.length; i++)
      {
        if(((input.charAt(i)!=0)&&(!parseFloat(input.charAt(i))))||input.charAt(i)==" ")
          return false;
      }
      return true;
}

function validateSavedDocument(){

 if(document.getElementById("savedId").selectedIndex=="0"){
    return false;
  }

  var validates=true;
  unColorAllElements();

  //if searchhistory is not choosen
  if(document.getElementById("savedId").selectedIndex==-1 || document.getElementById("savedId").selectedIndex==0){
    validates=false;
    document.getElementById("savedId").style.backgroundColor="#F0E68C";
  }
  if(validates){
    return true;
  }
  else{
    //prints errormessage
    PropertyClass.getPropertyValue("advancedSearchForm.error.validation.saveddocument",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
    return false;
  }
}

function validateHistory(){

  if(document.getElementById("historyId").selectedIndex=="0"){
    return false;
  }

  var validates=true;
  unColorAllElements();

  //if searchhistory is not choosen
  if(document.getElementById("historyId").selectedIndex==-1 || document.getElementById("historyId").selectedIndex==0){
    validates=false;
    document.getElementById("historyId").style.backgroundColor="#F0E68C";
  }
  if(validates){
    return true;
  }
  else{
    //prints errormessage
    PropertyClass.getPropertyValue("advancedSearchForm.error.validation.history",{callback:alternateValidationErrorHandler, errorHandler:majorErrorHandler});
    return false;
  }
}

function hasIllegalCharacter(input){
var filter;
var ok=true;

	 for(var i = 0; i<input.length; i++){
		if((input.charCodeAt(i)>96 && input.charCodeAt(i)<123) || input.charCodeAt(i)==228 || input.charCodeAt(i)==229 || input.charCodeAt(i)==246|| input.charCodeAt(i)==196 || input.charCodeAt(i)==197 || input.charCodeAt(i)==214 || input.charCodeAt(i)==44 || input.charCodeAt(i)==45 || input.charCodeAt(i)==58 || input.charCodeAt(i)==95 || input.charCodeAt(i)==42 || input.charCodeAt(i)==47){
			ok=true;
		}
		else{
			ok=false;
		}
	}


  /*if(document.getElementById("user").value=="member"){
    filter  = /^([a-zA-Z0-9_\-\,\*\.\å\ä\ö\Å\Ä\Ö\)\(\ \/\:])+$/;
  }
  else if(document.getElementById("user").value!="member"){
    filter  = /^([a-zA-Z0-9_\-\,\*\.\å\ä\ö\Å\Ä\Ö\)\(\ \/\:])+$/;
  }
    for(var i = 0; i<input.length; i++)
    {
	if (!filter.test(input.charAt(i))){
          return true;
        }
    }*/
}

function hasTwoStars(input){
  var temp = new Array();
  temp = input.split(' ');
  for(var i = 0; i<temp.length; i++)
  {
       if(countStars(temp[i])>1)
        return true;
  }
  return false;
}

function countStars(input){
  var stars=0;
    for(var i = 0; i<input.length; i++)
    {
        if((input.charAt(i)=="*")) //count stars (*)
        stars++;
    }
    return stars;
}

// ---- / validation-methods ------------
// ----- error-methods ----------

function validationErrorHandler(params) {
  var ele=document.getElementById('infoContainer');
  while (ele.childNodes.length > 0)
     ele.removeChild(ele.firstChild); //remove original text

  var img = document.createElement("img");
  img.src="../images/warning.gif";
  img.alt="";
  ele.appendChild(img); //add warning image

  ele.appendChild(document.createTextNode(propertyGeneralError)); //sets error-message text

  //prints list with missing parameters
  var list = document.createElement("ul");
  for(var i=0; i<params.length; i++){
    if(params[i]!=null && params[0]!=""){
      var item = document.createElement("li");
      item.appendChild(document.createTextNode(params[i]))
      list.appendChild(item);
    }
  }
  ele.appendChild(list);

  //animates message
  setColor(0);
  ele.style.border="1px solid #f00";
  ele.style.padding="10px";
}
function alternateValidationErrorHandler(text) {
  var ele=document.getElementById('infoContainer');
  while (ele.childNodes.length > 0)
     ele.removeChild(ele.firstChild); //remove original text

  var img = document.createElement("img");
  img.src="../images/warning.gif";
  img.alt="";
  ele.appendChild(img); //add warning image

  var th1 = document.createElement("th");
     if(document.getElementById("user").value=="member"){
      th1.setAttribute("colSpan", "4");
     }
  ele.appendChild(document.createTextNode(text)); //sets error-message text

  //animates message
  setColor(0);
  ele.style.border="1px solid #f00";
  ele.style.padding="10px";

}
function pulErrorHandler(data) {
  var ele=document.getElementById('infoContainer');
  while (ele.childNodes.length > 0)
     ele.removeChild(ele.firstChild); //remove original text

  var img = document.createElement("img");
  img.src="../images/warning.gif";
  img.alt="";
  ele.appendChild(img); //add warning image

  ele.appendChild(document.createTextNode(data)); //sets error-message text

  //link to become member
  //var link = document.createElement("a");
  //link.setAttribute("href", propertySignUpUrl);
  //link.appendChild(document.createTextNode(propertySignUp));
  //ele.appendChild(link);

  //animates message
  setColor(0);
  ele.style.border="1px solid #f00";
  ele.style.padding="10px";

}
function alternatePulErrorHandler(data) {
  var ele=document.getElementById('infoContainer');
  while (ele.childNodes.length > 0)
     ele.removeChild(ele.firstChild); //remove original text

  var img = document.createElement("img");
  img.src="../images/warning.gif";
  img.alt="";
  ele.appendChild(img); //add warning image

  ele.appendChild(document.createTextNode(data)); //sets error-message text

  //link to become full member
  var link = document.createElement("a");
  link.setAttribute("href", propertySignFullUrl);
  link.appendChild(document.createTextNode(propertySignFull));
  ele.appendChild(link);

  //animates message
  setColor(0);
  ele.style.border="1px solid #f00";
  ele.style.padding="10px";

}


// ---- / error- methods ----------
