/*
    resultnext(resnum) = result navigation
    getCoord(e) = test for map coords
    pagetownsub(town_id) = submit from local maps
    pagesub(regid) = submit for region map
    openwin(str) = open normal js win no args
    gohotelsignup() = validation for online sign up form
    goquicksearch() = validation for something to search, quick
    gosuggestattr() = front end suggest attraction validation
    goonlineenquiry() = online enquiry for paid hotels
    checksub(str) = used for selecting/all on category search
    gorefinesearch() = validation for refine searching
    gorequestcatalogue() = validation for catalogue request
    gotownhead(pageto,tid) = for local town files
    gotownsubhead(pageto,pid,tid) = for local town files
*/


function gotownid(tid)
{
    document.form1.action = "search_result_town.html";
    document.form1.town_id.value = tid;
    if(document.form1['sermsql'])
    {
        document.form1.sermsql.value = "";
    }
    if(document.form1['multitown'])
    {
        document.form1.multitown.value = "";
    }
    document.form1.submit();
}

function gotownhead(pageto,tid)
{
    document.form1.action = pageto;
    if(document.form1['place_id'])
    {
        document.form1.place_id.value="";
    }
    document.form1.sermsql.value = "";
    if(document.form1['ser_town'])
    {
        document.form1.ser_town.value = "";
    }
    if(document.form1['ser_hotel'])
    {
        document.form1.ser_hotel.value = "";
    }
    if(document.form1['ser_post'])
    {
        document.form1.ser_post.value = "";
    }
    document.form1.town_id.value = tid;
    document.form1.submit();
}
function gotownsubhead(pageto,pid,tid)
{
    document.form1.place_id.value=pid;
    document.form1.action = pageto;
    document.form1.sermsql.value = "";
    if(document.form1['ser_town'])
    {
        document.form1.ser_town.value = "";
    }
    if(document.form1['ser_hotel'])
    {
        document.form1.ser_hotel.value = "";
    }
    if(document.form1['ser_post'])
    {
        document.form1.ser_post.value = "";
    }
    //town_id put back in to here for
    //local town, sub towns to work
    document.form1.town_id.value = tid;
    document.form1.submit();
}

function gorefinesearch()
{
    var obj_form = document.refinesearch;
    var incomp = "";
    var strval = "";

    if((isBlank(trim(obj_form.ser_town.value))) && (isBlank(trim(obj_form.ser_hotel.value))) && (isBlank(trim(obj_form.ser_post.value))))
    {
        incomp = "You Must enter at least one Search Criteria!\n";
        if(strval=="")strval = "ser_town";
    }else{
        //make search at least 2 chars
        if(!isBlank(trim(obj_form.ser_post.value)))
        {
        	var templen = obj_form.ser_post.value;
            if(templen.length>=2)
            {

            }else{
            	incomp = "You must enter at least 2 characters to search postcodes!";
                if(strval=="")strval = "ser_post";
            }
        }
        if(!isBlank(trim(obj_form.ser_town.value)))
        {
        	var templen = obj_form.ser_town.value;
            if(templen.length>=3)
            {

            }else{
            	incomp = "You must enter at least 3 characters to search towns!";
                if(strval=="")strval = "ser_town";
            }
        }
        if(!isBlank(trim(obj_form.ser_hotel.value)))
        {
        	var templen = obj_form.ser_hotel.value;
            if(templen.length>=3)
            {

            }else{
            	incomp = "You must enter at least 3 characters to search names!";
                if(strval=="")strval = "ser_hotel";
            }
        }
    }
    if(incomp=="")
    {
        obj_form.submit();
    }else{
          alert(incomp);
          eval("obj_form."+strval+".focus()");
          return;
    }
}

function checksub(str)
{
    if(str=="all")
    {
        //untick rest
        numberofcontrols = document.refinesearch.length;
        for (controlindex = 0; controlindex < numberofcontrols; controlindex++)
        {
            element = document.refinesearch[controlindex];
            var str = element.name
            strnam = str.slice(0,4);
            if((strnam =="sub_") && (str!="sub_all"))
            {
                document.refinesearch[controlindex].checked = false;
            }
        }
    }else{
        //untick all only
        document.refinesearch['sub_all'].checked = false;
    }
}

function goonlineenquiry()
{
    var obj_form = document.form1;
    var incomp = "The Following Fields are incomplete:\n\n";
    var strval = "";

    if(isBlank(trim(obj_form.eqname.value)))
    {
        incomp = incomp + "Name\n";
        if(strval=="")strval = "eqname";
    }
    if(isBlank(trim(obj_form.eqphone.value)))
    {
        incomp = incomp + "Telephone\n";
        if(strval=="")strval = "eqphone";
    }else{
    	if(!isTelephoneNumber(obj_form.eqphone.value))
        {
            incomp = incomp + "Telephone Number must be Numbers Only\n";
	        if(strval=="")strval = "eqphone";
        }
    }
    if(isBlank(trim(obj_form.eqemail.value)))
    {
        incomp = incomp + "Email Address\n";
        if(strval=="")strval = "eqemail";
    }else{
        if (invalidemail(obj_form.eqemail.value))
        {
            incomp = incomp + "Invalid Email Address\n";
            if(strval=="")strval = "eqemail";
        }
    }
    if(isBlank(trim(obj_form.eqtext.value)))
    {
        incomp = incomp + "Enquiry\n";
        if(strval=="")strval = "eqtext";
    }

    if(incomp.length == 38)
    {
        obj_form.submit();
    }else{
          alert(incomp);
          eval("obj_form."+strval+".focus()");
          return;
    }
}

function gosuggestattr()
{
    var obj_form = document.form1;
    var incomp = "The Following Fields are incomplete:\n\n";
    var strval = "";

    if(isBlank(trim(obj_form.yourname.value)))
    {
        incomp = incomp + "Your Name\n";
        if(strval=="")strval = "yourname";
    }
    if(isBlank(trim(obj_form.youremail.value)))
    {
        incomp = incomp + "Your Email Address\n";
        if(strval=="")strval = "youremail";
    }else{
        if(invalidemail(obj_form.youremail.value))
        {
            incomp = incomp + "Invalid Your Email Address\n";
            if(strval=="")strval = "youremail";
        }
    }

    if(isBlank(trim(obj_form.busname.value)))
    {
        incomp = incomp + "Business Name\n";
        if(strval=="")strval = "busname";
    }
    if(!isBlank(trim(obj_form.email.value)))
    {
        if (invalidemail(obj_form.email.value))
        {
            incomp = incomp + "Invalid Attraction Email Address\n";
            if(strval=="")strval = "email";
        }
    }

    if(incomp.length == 38)
    {
        obj_form.submit();
    }else{
          alert(incomp);
          eval("obj_form."+strval+".focus()");
          return;
    }
}

function goquicksearch(showtownbox)
{
    var obj_form = document.refinesearch;
    var incomp = "";
    var strval = "";
    if(showtownbox==1)
    {
    	if((isBlank(trim(obj_form.ser_town.value))) && (isBlank(trim(obj_form.ser_hotel.value))) && (isBlank(trim(obj_form.ser_post.value))))
	    {
	        incomp = "You Must enter at least one Search Criteria!\n";
	        if(strval=="")strval = "ser_town";
	    }else{
	        //make search at least 2 chars
	        if(!isBlank(trim(obj_form.ser_post.value)))
	        {
	            var templen = obj_form.ser_post.value;
	            if(templen.length>=2)
	            {

	            }else{
	                incomp = "You must enter at least 2 characters to search postcodes!";
	                if(strval=="")strval = "ser_post";
	            }
	        }
	        if(!isBlank(trim(obj_form.ser_town.value)))
	        {
	            var templen = obj_form.ser_town.value;
	            if(templen.length>=3)
	            {

	            }else{
	                incomp = "You must enter at least 3 characters to search towns!";
	                if(strval=="")strval = "ser_town";
	            }
	        }
	        if(!isBlank(trim(obj_form.ser_hotel.value)))
	        {
	            var templen = obj_form.ser_hotel.value;
	            if(templen.length>=3)
	            {

	            }else{
	                incomp = "You must enter at least 3 characters to search names!";
	                if(strval=="")strval = "ser_hotel";
	            }
	        }
	    }
    }else{
        //make search at least 2 chars
        if(!isBlank(trim(obj_form.ser_post.value)))
        {
            var templen = obj_form.ser_post.value;
            if(templen.length>=2)
            {

            }else{
                incomp = "You must enter at least 2 characters to search postcodes!";
                if(strval=="")strval = "ser_post";
            }
        }
        if(!isBlank(trim(obj_form.ser_hotel.value)))
        {
            var templen = obj_form.ser_hotel.value;
            if(templen.length>=3)
            {

            }else{
                incomp = "You must enter at least 3 characters to search names!";
                if(strval=="")strval = "ser_hotel";
            }
        }
    }

    if(incomp=="")
    {
        obj_form.submit();
    }else{
          alert(incomp);
          eval("obj_form."+strval+".focus()");
          return;
    }
}

function gohotelsignup()
{
    var obj_form = document.form1;
    var incomp = "The Following Fields are incomplete:\n\n";
    var strval = "";

    if(obj_form.title_id.value==0)
    {
        incomp = incomp + "Your Title\n";
        if(strval=="")strval = "title_id";
    }
    if(isBlank(trim(obj_form.surname.value)))
    {
        incomp = incomp + "Your Surname\n";
        if(strval=="")strval = "surname";
    }
    if(isBlank(trim(obj_form.initial.value)))
    {
        incomp = incomp + "Your Initial\n";
        if(strval=="")strval = "initial";
    }
    if(isBlank(trim(obj_form.position.value)))
    {
        incomp = incomp + "Your Position\n";
        if(strval=="")strval = "position";
    }

    if(isBlank(trim(obj_form.busname.value)))
    {
        incomp = incomp + "Business Name\n";
        if(strval=="")strval = "busname";
    }

    if(isBlank(trim(obj_form.postcode.value)))
    {
        incomp = incomp + "Business Postcode\n";
        if(strval=="")strval = "postcode";
    }
    if(isBlank(trim(obj_form.telephone.value)))
    {
        incomp = incomp + "Business Telephone Number\n";
        if(strval=="")strval = "telephone";
    }else{
    	if(!isTelephoneNumber(obj_form.telephone.value))
        {
            incomp = incomp + "Business Telephone Number must be Numbers Only\n";
	        if(strval=="")strval = "telephone";
        }
    }
    if(!isBlank(trim(obj_form.con_email.value)))
    {
        if (invalidemail(obj_form.con_email.value))
        {
            incomp = incomp + "Invalid Your Email Address\n";
            if(strval=="")strval = "email";
        }
    }
    if(!isBlank(trim(obj_form.email.value)))
    {
        if (invalidemail(obj_form.email.value))
        {
            incomp = incomp + "Invalid Business Email Address\n";
            if(strval=="")strval = "email";
        }
    }

    if(incomp.length == 38)
    {
        obj_form.submit();
    }else{
          alert(incomp);
          eval("obj_form."+strval+".focus()");
          return;
    }
}

function openwin(str)
{
    window.open(str,"","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
}

function goenquiry()
{
    var obj_form = document.form1;
    var incomp = "The Following Fields are incomplete:\n\n";
    var strval = "";

    if(isBlank(trim(obj_form.eqname.value)))
    {
        incomp = incomp + "Your Name\n";
        if(strval=="")strval = "eqname";
    }
    if(isBlank(trim(obj_form.eqphone.value)))
    {
        incomp = incomp + "Telephone\n";
        if(strval=="")strval = "eqphone";
    }else{
    	if(!isTelephoneNumber(obj_form.eqphone.value))
        {
            incomp = incomp + "Telephone Number must be Numbers Only\n";
	        if(strval=="")strval = "eqphone";
        }
    }
    if(isBlank(trim(obj_form.eqemail.value)))
    {
        incomp = incomp + "Email Address\n";
        if(strval=="")strval = "eqemail";
    }else{
        if (invalidemail(obj_form.eqemail.value))
        {
            incomp = incomp + "Invalid Email Address\n";
            if(strval=="")strval = "eqemail";
        }
    }
    if(isBlank(trim(obj_form.eqtext.value)))
    {
        incomp = incomp + "Enquiry\n";
        if(strval=="")strval = "eqtext";
    }

    if(incomp.length == 38)
    {
        obj_form.submit();
    }else{
          alert(incomp);
          eval("obj_form."+strval+".focus()");
          return;
    }
}

function getCoord(e)
{
    var x = e.layerX || e.offsetX ;
    var y = e.layerY || e.offsetY ;
    window.status = "x = "+x+" , y = "+y
}

function pagecountysub(county_page)
{
    document.uktownmapform.action = "/counties/"+county_page;
    document.uktownmapform.submit();
}

function pagetownsub(town_id)
{
    document.uktownmapform.town_id.value = town_id;
    document.uktownmapform.submit();
}

function pagesub(regid)
{
    document.ukmapform.region_id.value = regid;
    document.ukmapform.submit();
}

function resultnext(resnum,pageto)
{
    var obj_form = document.form1;
    obj_form.resnum.value = resnum;
    obj_form.action = pageto;
    //obj_form.sermsql.value = sermsql;
    obj_form.submit();
}