		 function isInt(x) {
       if (!x){
        return true;
			 }
       var y=parseInt(x); 
       if (isNaN(y)) return false; 
       return x==y && x.toString()==y.toString() && x>0; 
     } 

     function isYear(x) {
       if (!x){
        return true;
			 }
       var y=parseInt(x); 
       if (isNaN(y)) return false; 
       var curdate=new Date();
       var currentyear = curdate.getFullYear();
       return x==y && x.toString()==y.toString() && x>=1000 && x<=currentyear; 
     } 

/*	function GetParameters()
	{
		var arg = new Object();
		var href = document.location.href;

		if ( href.indexOf("?") != -1)
		{
		var params = href.split("?")[1];
		var param = params.split("&");

			for (var i = 0; i < param.length; ++i)
			{
			var name = param[i].split( "=")[0];
			var value = param[i].split( "=")[1];

			arg[name] = value;
			}
		}
		return arg;
	}
*/


    function dosearch(){
        var check = true;
        if (
            !document.getElementById('search_artstyle').value &&
            !document.getElementById('search_author').value &&
            !document.getElementById('search_keywords').value &&
            !document.getElementById('search_fromyear').value &&
            !document.getElementById('search_fromyear').value &&
						!document.getElementById('search_toyear').value &&
						!document.getElementById('search_minsaleprice').value &&
						!document.getElementById('search_maxsaleprice').value &&
						!document.getElementById('search_minrentprice').value &&
						!document.getElementById('search_maxrentprice').value &&
						!document.getElementById('search_minwidth').value &&
						!document.getElementById('search_maxwidth').value &&
						!document.getElementById('search_minheight').value &&
						!document.getElementById('search_maxheight').value &&
            !document.getElementById('search_genre').value &&
            !document.getElementById('search_tonality').value &&
            !document.getElementById('search_palette').value && 
            document.getElementById('search_onsale').checked == false
        ){
            check = false;
            document.getElementById('err_nofilters').style.display = 'block';
        } else {
            document.getElementById('err_nofilters').display = 'none';
        }


        // aastaarvu kontroll
        if (!(isYear(document.getElementById('search_fromyear').value)) || !(isYear(document.getElementById('search_toyear').value))) {
            check = false;
            document.getElementById('td_year').style.color = "red";
        } else {
            document.getElementById('td_year').style.color = "white";
        }

        if (document.getElementById('search_fromyear').value &&
            document.getElementById('search_toyear').value && check==true
        ){
            fromyear = (document.getElementById('search_fromyear').value.replace(/^\s+|\s+$/g, ''));
            toyear = (document.getElementById('search_toyear').value.replace(/^\s+|\s+$/g, ''));
            if (fromyear.length && toyear.length && ((parseInt(fromyear) > parseInt(toyear))) )  {
                check = false;
								document.getElementById('td_year').style.color = "red";
						} else {
								document.getElementById('td_year').style.color = "white";
						}
				}



				// hinnavahemiku kontroll = myyk
				if (!(isInt(document.getElementById('search_minsaleprice').value)) || !(isInt(document.getElementById('search_maxsaleprice').value))){
						check = false;
						document.getElementById('td_saleprice').style.color = "red";
				} else {
						document.getElementById('td_saleprice').style.color = "white";
				}

				if (document.getElementById('search_minsaleprice').value &&
						document.getElementById('search_maxsaleprice').value && check==true
				){
						minsaleprice = (document.getElementById('search_minsaleprice').value.replace(/^\s+|\s+$/g, ''));
						maxsaleprice = (document.getElementById('search_maxsaleprice').value.replace(/^\s+|\s+$/g, ''));
						if (minsaleprice.length && maxsaleprice.length && ((parseInt(minsaleprice) > parseInt(maxsaleprice))) )  {
								check = false;
								document.getElementById('td_saleprice').style.color = "red";
						} else {
								document.getElementById('td_saleprice').style.color = "white";
						}
				}


				// hinnavahemiku kontroll = rent
				if (!(isInt(document.getElementById('search_minrentprice').value)) || !(isInt(document.getElementById('search_maxrentprice').value))){
						check = false;
						document.getElementById('td_rentprice').style.color = "red";
				} else {
						document.getElementById('td_rentprice').style.color = "white";
				}

				if (document.getElementById('search_minrentprice').value &&
						document.getElementById('search_maxvprice').value && check==true
				){
						minrentprice = (document.getElementById('search_minrentprice').value.replace(/^\s+|\s+$/g, ''));
						maxrentprice = (document.getElementById('search_maxvprice').value.replace(/^\s+|\s+$/g, ''));
						if (minrentprice.length && maxrentprice.length && ((parseInt(minrentprice) > parseInt(maxrentprice))) )  {
								check = false;
								document.getElementById('td_rentprice').style.color = "red";
						} else {
								document.getElementById('td_rentprice').style.color = "white";
						}
				}
				
				
				// min ja max laiuse kontroll
				if (!(isInt(document.getElementById('search_minwidth').value)) || !(isInt(document.getElementById('search_maxwidth').value))){
						check = false;
						document.getElementById('td_width').style.color = "red";
				} else {
						document.getElementById('td_width').style.color = "white";
				}

				if (document.getElementById('search_minwidth').value &&
						document.getElementById('search_maxwidth').value && check==true
				){
						minwidth = (document.getElementById('search_minwidth').value.replace(/^\s+|\s+$/g, ''));
            maxwidth = (document.getElementById('search_maxwidth').value.replace(/^\s+|\s+$/g, ''));
            if (minwidth.length && maxwidth.length && ((parseInt(minwidth) > parseInt(maxwidth))) )  {
                check = false;
                document.getElementById('td_width').style.color = "red";
            } else {
                document.getElementById('td_width').style.color = "white";
            }
        }

        if (!(isInt(document.getElementById('search_minheight').value)) || !(isInt(document.getElementById('search_maxheight').value))){
            check = false;
            document.getElementById('td_height').style.color = "red";
        } else {
            document.getElementById('td_height').style.color = "white";
        }

        if (document.getElementById('search_minheight').value &&
            document.getElementById('search_maxheight').value && check==true
        ){
            minheight = (document.getElementById('search_minheight').value.replace(/^\s+|\s+$/g, ''));
            maxheight = (document.getElementById('search_maxheight').value.replace(/^\s+|\s+$/g, ''));
            if (minheight.length && maxheight.length && ((parseInt(minheight) > parseInt(maxheight))) )  {
                check = false;
                document.getElementById('td_height').style.color = "red";
            } else {
                document.getElementById('td_height').style.color = "white";
            }
        }

        if (check){
//			document.getElementById('getparams').value=GetParameters();
            document.getElementById('searchform').submit();
        } else {
            return false;
        }

    }
