﻿/**
 * @author rodridia
 */

/*  Onload Functions    //---------------------------*/

var tickeritems;
var curritem=0;
var iPause=0;

$(document).ready(function(){




$(".mailLink").click(function(){
	window.open(this.href,'tipafriend','width=470,height=380')
 	return false;
 });
 /*
 $(".subscribeButton").click(function(){
	window.open(this.href,'tipafriend','width=470,height=320')
 	return false;
 });
 
 */
 
 /*
  * Makes the left menu column extend till the bottom of the mainContent div 
 */
 var pageHeight = $("#mainContent").height();
//alert(pageHeight);
 pageHeight = pageHeight - 60;
 $(".leftMenuBoxMiddle").css("height",(pageHeight-15)+"px");
  /*
  * Sets the mainContent div height to 440px 
 */
 var searchpageHeight = $("#mainContent").height();
	 if(searchpageHeight < 440){
		$("#mainContent").css("height",440+"px");	
	 }
 

 
 /*
 Content Anchors
 */
 $(".linkBox").css("margin-left","-13px");
 
 
 $("a[name]").parent("h2").each(function () {
      var anchor =$(this).find("a").attr("name");
      var str =$(this).find("a").text();
      $(this).wrapAll("<div class=\"toTopTitle\" style='margin-left:-30px;'></div>");
      $(this).find("a[name]").remove();
      $(this).before("<span><a href=\"#top\" class=\"toTopLink\" name="+anchor+"><span>top</span></a></span>");
      $(this).text(str);
      
  });
    
/**
FORMS
	 * Customize this function as you wish!
     * Add your validation below the email if.
     *
     * Change the behaviour of the plugin by editing this line:
     * 		$(this).blur( function() { validateField(this) } );
     * To:
     *      $(this).keyup( function() { validateField(this) } );
     *
     *  You can find it around the line number 64.
	 */
	function validateField(field) {
		var error = false;
		
		// required fields
		if ($(field).attr("class").indexOf("required") != -1) {
			if (!$(field).val().length || $(field).val().length < 2)
				error = true;
				
		}
		// numeric fields
		if ($(field).attr("class").indexOf("numeric") != -1) {
			if (!/^[0-9]*$/.test($(field).val()))
				error = true;
		}
		// characters (letters)
		
		if ($(field).attr("class").indexOf("character") != -1) {
			if (!/^[a-zA-ZöÖäÄåÅ]*$/.test($(field).val()))
				error = true;
		}
		// emails
		if ($(field).attr("class").indexOf("email") != -1) {
			if (!/^[a-zA-Z0-9]{1}([\._a-zA-Z0-9-]+)(\.[_a-zA-Z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+){1,3}$/.test($(field).val()))
				error = true;
		}
		
		if (error) {
			$(field).addClass("error");
		} else {
			$(field).removeClass("error");
		}
		
		return !error;
	}
	
	$("form").each( function() {
		// handle submissions without filling any field
		$(this).submit(function () {
			var validationError = false;
			// for each field test it
			$("input, select, textarea", this).each( function() {
				if ($(this).attr("class")) {
					if (!validateField(this))
						validationError = true;
				}
			});
			return !validationError;
		});
	
		// handle changes on the fly
		$("input, select, textarea", this).each( function() {
			if ($(this).attr("class")) {
				$(this).blur( function() { validateField(this) } );
    			}
		});
	});
 
/*
/FORMS

Case ticker for references
*/

		
        var tickerSelector = ".case";
        tickeritems = $(tickerSelector).hide().hover(function(){
            $(this).addClass("hovered");
            iPause = 1;
			
        }, function(){
            $(this).removeClass("hovered");
            iPause = 0;
        }).filter(":eq(0)").show().add(tickerSelector).size();
		
		
		// Pause Case Menu on mouseover and carry on onmouseout
        $(".butHolder").hover(function(){
            $(this).addClass("hovered");
            iPause = 1;
			
        }, function(){
            $(this).removeClass("hovered");
            iPause = 0;
        });
		$(".butHolder").css("display","block");
		// Previous button
		//$(".butHolder").prepend("<a href='javascript:void(0)' class='prevLink btnPrev'><span>prev</span></a>");
		$(".btnPrev").click(function(){
			if(curritem != 0){
				$(".case:eq(" + curritem + ")").fadeOut("slow");
				$(".case:eq(" + curritem + ")").prev().fadeIn("slow");
				curritem = curritem-1;
					$("#totalCases").text((curritem+1)+"/"+$(".case").length);
			}
		});
		$(".btnPrev").attr("class","btnPrev prevLink");
		
		// Next button
        //$(".butHolder").append("<a href='javascript:void(0)' class='nextLink btnPrev'><span>next</span></a>");
		$(".btnNext").click(function(){
			if(curritem+1  <  $(".case").length){
				$(".case:eq(" + curritem + ")").fadeOut("slow");
				$(".case:eq(" + curritem + ")").next().fadeIn("slow");
				curritem = curritem+1;
					$("#totalCases").text((curritem+1)+"/"+$(".case").length);
			}
			
		});	
		$(".btnNext").attr("class","btnNext nextLink");
		$("#totalCases").text((curritem+1)+"/"+$(".case").length);
        setInterval(tickCase, 12000); //time in milliseconds
    
	});

    //-----------------------
    function tickCase(){
        if (iPause == 0) {
            $(".case:eq(" + curritem + ")").hide("normal", function(){
                $(this).hide();
            });
            curritem = ++curritem % (tickeritems - 1);
            $(".case:eq(" + curritem + ")").show("normal");
			$("#totalCases").text((curritem+1)+"/"+$(".case").length);
        }
    }
    
    
    function submitToEvent(){
    if($('.error').length == 0){
        document.mainform.action="/Global/SubscribeToEvent/ThankYou.aspx?p=popup";
	    document.mainform.__VIEWSTATE.name ="NOVIEWSTATE";
	    document.mainform.submit();
     };
    }



jQuery(document).ready(function(){
    var version = jQuery.browser.version; 
    if (version instanceof Object) version=version.number(); 
    // Fix PNG bugs on IE6/5 
    if (jQuery.browser.msie && version < 7) { 
         $("img[@src$=png]").pngfix();
    } 
    
    
  
    
      
});

