﻿function searchModels(el) {
// If other than modelname search is activated, reset model name
var is_model = el;
if(is_model != 'model') {
// If other searches are activated, reset name
$('#model_name').find('option:first').attr('selected', 'selected').parent('select');
} else if (is_model = 'model')
{
// If model name search is activated, reset all others
$('#area').find('option:first').attr('selected', 'selected').parent('select');
$('#floors').find('option:first').attr('selected', 'selected').parent('select');
$('#building_type').find('option:first').attr('selected', 'selected').parent('select');
}

// Serialize formData
var formData= $("form#searchform").serialize();
// put default.asp on a variable
var queryStart= '/default.asp?';
// the whole querystring for search
var queryString = queryStart+formData;
// Add the queryString to a cookie
$.cookie('searchQuery', queryString , { path: '/' });
// Now change content!
changeContent(queryString);
// Dont send form expect with ajax, so return false
return false;
}

function changeContent(url) {

 $("#listContainer")
  <!-- fade out -->
    .fadeOut('fast', function() {
  <!-- after fadeout, bring in the ajax loader anim gif -->
      $("#listContainer")
      .addClass('loadingBig')
  <!-- throw the html out -->
      .html('')
  <!-- fade the resultpage in -->
      .fadeIn('slow', function() {
  <!-- load the content via ajax -->
    $("#listContainer").load(url + ' #searchResults',function(){
    <!-- Remove loading gif -->
      $("#listContainer")
        .removeClass('loadingBig');
        // If search is empty, write 
        if($("#listContainer").html() == '') {

        $("#listContainer").html("<p>" + no_results + "<a id='resetFields' onclick='resetOptions()' style='cursor:pointer'>" + reset_search_options + "</a>.</p>");
 
        }
        <!-- If IE, remove filter, IE7 clearType Bug. -->
        if(jQuery.browser.msie){
                  $("#listContainer").get(0).style.removeAttribute('filter');
	        }

        })

      })
    
    })	

}


// Reset fields 
function resetOptions() {
// Reset select 
$('#model_name').find('option:first').attr('selected', 'selected').parent('select');
$('#area').find('option:first').attr('selected', 'selected').parent('select');
$('#floors').find('option:first').attr('selected', 'selected').parent('select');
$('#building_type').find('option:first').attr('selected', 'selected').parent('select');
// Same default search
// Serialize formData
var formData= $("form#searchform").serialize();
// put default.asp on a variable
var queryStart= '/default.asp?';
// the whole querystring for search
var queryString = queryStart+formData;
// Add the queryString to a cookie
// $.cookie('searchQuery', queryString , { path: '/' });
// Now change content!
changeContent(queryString);
// Dont send form expect with ajax, so return false
return false;
// 
}


/****** SHOW INFO ON CONTACT PAGE */
function showInfo(el, back) {
var contactId = el;
var back = back;

// If no id selected, alert
if(contactId == '') {
alert(pleaseChoose);
return false;
}
// If contactid has name in it, i.e. "10062_EcoPlaza", get the id out of the string
if(contactId.indexOf('_') != -1){
var contactId = contactId.split('_');
var contactId = contactId[0]
}

if(back == 'true') {
var queryString = '/default.asp?docId=' + contactPageId + '&showInfo=' + contactId + '&back=true';
}
else if(contactId != '') {
var queryString = '/default.asp?docId=' + contactPageId + '&showInfo=' + contactId;
} else {
var queryString = '/default.asp?docId=' + contactPageId
}
// Add the queryString to a cookie
$.cookie('contactQuery', queryString , { path: '/' });
// Scroll up
$(document).scrollTo("#columnWrapper");
// hide Sendrequest 
$("#sendRequestForm form").fadeOut();

 $("#contactRight")
  <!-- feidataan pois -->
    .fadeOut('fast', function() {
  <!-- faden jälkeen vaihdetaan throbber näkyville -->
      $("#contactRight")
      .addClass('loadingBig')
  <!-- heitetään sisältö bittitaivaaseen -->
      .html('')
  <!-- tuodaan latausikoni näkyviin -->
      .fadeIn('slow', function() {
  <!-- ladataan sivun sisältö -->
    

    $("#contactRight").load(queryString+ ' #contactResult',function(){
    <!-- tämä suoritetaan latauksen jälkeen -->
      $("#contactRight")
        .removeClass('loadingBig');
        // If search is empty, write 
        if($("#contactRight").html() == '') {

        $("#contactRight").html("<p>Something went wrong, please reload the page</p>");
 
        } 
        <!-- If IE, remove filter, IE7 clearType Bug. -->
        if(jQuery.browser.msie){
                  $("#contactRight").get(0).style.removeAttribute('filter');
	        }

        })

      })
    
    })
// Dont send form expect with ajax, so return false
return false;


}

/****** SHOW INFO ON CONTACT PAGE */
function sendRequest(el) {
var request_id = el;
var queryString = '/default.asp?docId=' + contactPageId + '&sendRequest=' + request_id;
$("#contactLeft").hide();
$("#contactRight").hide();
<!-- change selected state -->
$("a#resellersLink").removeAttr("class");
$("a#contactLink").attr("class", "active");
$("#salesBox")
  <!-- feidataan pois -->
    .fadeOut('fast', function() {
  <!-- faden jälkeen vaihdetaan throbber näkyville -->
      $("#salesBox")
      .addClass('loadingBig')
  <!-- heitetään sisältö bittitaivaaseen -->
      .html('')
  <!-- tuodaan latausikoni näkyviin -->
      .fadeIn('slow', function() {
  <!-- ladataan sivun sisältö -->
    

    $("#salesBox").load(queryString+ ' #sendRequestForm',function(){
    <!-- tämä suoritetaan latauksen jälkeen -->
      $("#salesBox")
        .removeClass('loadingBig');
        // If search is empty, write 
        if($("#salesBox").html() == '') {

        $("#salesBox").html('<p>Something went wrong, please reload the page</p>');
 
        } 
        <!-- If IE, remove filter, IE7 clearType Bug. -->
        if(jQuery.browser.msie){
                  $("#salesBox").get(0).style.removeAttribute('filter');
	        }

        })

      })
    
    })

// Dont send form expect with ajax, so return false
return false;

}

/* BACK TO REQUEST */
function backToRequest() {
$("#contactRight").fadeOut('fast');
$("#sendRequestForm form").fadeIn();
}

// SHOW INFO PAGE JQUERY STUFF
function showImages() {
var showID = $("a.showImages").attr("id");
if(showID == 'show_more') {
// Change id and show image
$("#hidden_images").slideDown();
$("a.showImages").attr("id", "show_less");
$("a.showImages").html(show_less_images);
// enable lightbox for all images
$('#all_images a.boxLink').lightBox();
}
else {
//Change id back , hide images
$("#hidden_images").hide();
$("a.showImages").attr("id", "show_more");
$("a.showImages").html(show_more_images);
}

}

// show textfield if answered yes in existing building site question, sales and contact
function existingBuildingSite() {

if($("#existing_building_site").val() == 'yes' ) {
$("#existingDiv").show('slow');
} else
{
// Clear value and hide
$("input#existing_building_site_zip_city").val("");
$("#existingDiv").hide();
}
}

// SHOW VIDEOS
function showVideos() {
var showID = $("a.showVideos").attr("id");
if(showID == 'show_more') {
// Change id and show image
$(".hidden_video").show();
$("a.showVideos").attr("id", "show_less");
$("a.showVideos").html(show_less_videos);
// enable lightbox for all images
}
else {
//Change id back , hide images
$(".hidden_video").hide();
$("a.showVideos").attr("id", "show_more");
$("a.showVideos").html(show_more_videos);
}

}
 
// SALES CONTACT SELECT ONCHANGE
$(document).ready(function(){
   $("select#closest_office").change(function () {
          var str = "";
          $("select#closest_office option:selected").each(function () {
                str += $(this).attr('class');
              });
          $('#recipient').val(str);
        })
        .change();
        
});

function changeRecipient() {
var str = "";
          $("select#closest_office option:selected").each(function () {
                str += $(this).attr('class');
              });
$('#recipient').val(str);
}

/* *************** 

NEWS AND EVENT PAGE FUNCTION 

**************** */

// Get caption on mouseover
function getCaption() {
// Get href from link
var query = this.href;
// Erase previous caption
$("#caption").html('');
// Add loading image
$("#caption").addClass('loadingBig');
// Jquery load function, remove loadingbig after loading
$("#caption").load(query + ' #newsCaption',function(){
if($("#newsCaption").html() == '') {
 $("#newsCaption").html('');
}
$("#caption").removeClass('loadingBig');
});
return false;

}

// Erase on mouseover
function removeCaption() { 
$("#caption").html('');
}