///Summary: The tools.js file contains commonly used functions
///Remarks: queryString(key) will return the key to search for, a 'false' if null
///Created By: sreichert, 9/24/07

//Summary: query object, retrieves entire page query and parses it
function PageQuery(q) {
  if(q.length > 1) this.q = q.substring(1, q.length);
  else this.q = null;
  
  this.keyValuePairs = new Array();
  
  if(q) {
    for(var i=0; i < this.q.split("&").length; i++) {
      this.keyValuePairs[i] = this.q.split("&")[i];
    }
  }
  
  this.getKeyValuePairs = function() { return this.keyValuePairs; }
  
  this.getValue = function(s) {
    for(var j=0; j < this.keyValuePairs.length; j++) {
      if(this.keyValuePairs[j].split("=")[0] == s){
        return this.keyValuePairs[j].split("=")[1];
      }
    }
    
    return false;
  }
  
  this.getParameters = function() {
    var a = new Array(this.getLength());
    
    for(var j=0; j < this.keyValuePairs.length; j++) {
      a[j] = this.keyValuePairs[j].split("=")[0];
    }
    
    return a;
  }
  
  this.getLength = function() { return this.keyValuePairs.length; } 
}

//Summary: retrieves a query key
function queryString(key){
  var page = new PageQuery(window.location.search); 
  return unescape(page.getValue(key)); 
}

//Summary: opens a pop up, retrieves size
function openPopUp(url, width, height, scrollbars){
  mywindow = window.open(url,"mywindow","location=0,status=0,scrollbars=" + scrollbars + ",width=" + width + ",height=" + height);
}

//author: LTello 7/3
//This wrapper function is used to make a google function call.

//Count the number of videos views when someone clicks on play.
/*
function googleVideoView(type, videoName){
    pageTracker._trackEvent("Advocates", "Video Name - "+videoName, ""+xmlDoc.FirstName+" "+xmlDoc.LastName);
    /* remove below
    if(type == "v"){
        pageTracker._trackEvent("Advocates", "Video Name - "+videoName, ""+xmlDoc.FirstName+" "+xmlDoc.LastName);
    }
    else if (type == "w"){
        pageTracker._trackEvent("Advocates", "Video Name - "+videoName, ""+xmlDoc.FirstName+" "+xmlDoc.LastName);
    }
    
}*/
/*
function googleVideoView(type, videoName) {
    if (type == "v") {
        videoTracker._trackEvent("Video View", "" + videoName);
    } else if (type == "w") {
        webcastTracker._trackEvent("Video View", "" + videoName);
    } else if (type == "a") {
        webcastTracker._trackEvent("Video View", "" + videoName);
    }
}*/

//tracking occurs every 25 percent
function googlePercentageView(type, percentage, videoName){
    pageTracker._trackEvent(""+type, ""+percentage, ""+videoName);
}
/*
function googlePercentageView(type, videoName) {
    if (type == "v") {
        videoTracker._trackEvent("Viewing Percentage", "" + videoName, 10);
    } else if (type == "w") {
        webcastTracker._trackEvent("Viewing Percentage", "" + videoName, 10);
    } else if (type == "a") {
        webcastTracker._trackEvent("Viewing Percentage", "" + videoName, 10);
    }
}*/

function capitalize(theString){
    return theString.charAt(0).toUpperCase() + theString.substring(1).toLowerCase();
}



function showHideVimpat(element){
    if (element.checked){
        $('.Q6_17_FLD div').show();
        $('.Q6_17_FLD').addClass('on');
    }else{
        $('.Q6_17_FLD div').hide();  
        $('.Q6_17_FLD').removeClass('on');     
    }
}

function showHideKeppra(idName){
   if(idName == 'SubtierMaster_subtierContent_ProfileRegistration1_Q6_5_FLD_2'){
       document.getElementById('SubtierMaster_subtierContent_ProfileRegistration1_Q6_5_1_FLD_Container').style.display = 'block';
       $('.ques6_5').removeClass('whiteMotify');
       $('.ques6_5').addClass('blueMotify');
   }
   else if(idName == 'SubtierMaster_subtierContent_ProfileRegistration1_Q6_5_FLD_3'){
       document.getElementById('SubtierMaster_subtierContent_ProfileRegistration1_Q6_5_1_FLD_Container').style.display = 'none';
       $('.ques6_5').removeClass('blueMotify');
       $('.ques6_5').addClass('whiteMotify');
   }
   else if(idName == 'SubtierMaster_subtierContent_ProfileRegistration1_Q6_6_FLD_2'){
       document.getElementById('SubtierMaster_subtierContent_ProfileRegistration1_Q6_6_1_FLD_Container').style.display = 'block';
       $('.ques6_6').removeClass('whiteMotify');
       $('.ques6_6').addClass('blueMotify');
   }
   else if(idName == 'SubtierMaster_subtierContent_ProfileRegistration1_Q6_6_FLD_3'){
       document.getElementById('SubtierMaster_subtierContent_ProfileRegistration1_Q6_6_1_FLD_Container').style.display = 'none';
       $('.ques6_6').removeClass('blueMotify');
       $('.ques6_6').addClass('whiteMotify');
   }
   else if(idName == 'SubtierMaster_subtierContent_ProfileRegistration1_Q6_6_FLD_4'){
       document.getElementById('SubtierMaster_subtierContent_ProfileRegistration1_Q6_6_1_FLD_Container').style.display = 'none';
       $('.ques6_6').removeClass('blueMotify');
       $('.ques6_6').addClass('whiteMotify');
   }
   else if(idName == 'SubtierMaster_subtierContent_ProfileRegistration1_Q6_17_FLD_2'){
       document.getElementById('SubtierMaster_subtierContent_ProfileRegistration1_Q6_17_1_FLD_Container').style.display = 'block';
       $('.ques6_7').removeClass('whiteMotify');
       $('.ques6_7').addClass('blueMotify');
   }
   else if(idName == 'SubtierMaster_subtierContent_ProfileRegistration1_Q6_17_FLD_3'){
       document.getElementById('SubtierMaster_subtierContent_ProfileRegistration1_Q6_17_1_FLD_Container').style.display = 'none';
       $('.ques6_7').removeClass('blueMotify');
       $('.ques6_7').addClass('whiteMotify');
   }
   else if(idName == 'SubtierMaster_subtierContent_ProfileRegistration1_Q6_17_FLD_4'){
       document.getElementById('SubtierMaster_subtierContent_ProfileRegistration1_Q6_17_1_FLD_Container').style.display = 'none';
       $('.ques6_7').removeClass('blueMotify');
       $('.ques6_7').addClass('whiteMotify');
   }   
}

/************************************************************************
   created: LTello
   Date: 03/03/09
 
   Version: 0.1
   Description: Hide the purple can nation walk callouts on march 29
   
************************************************************************/

var UCB = UCB ||{};

UCB.Util = function(){
    var myDate=new Date();
    myDate.setFullYear(2009,2,29);
    
    var today = new Date();
    
    function checkDate(){
        var myDate=new Date();
        myDate.setFullYear(2009,2,29);
        var today = new Date();
        if(today < myDate){
            return true;
        }
        return false;
    }
    
    return{
       init: function(){        
         if(checkDate()){
           try{
             $('#middle_area').show();
             $('.purpleDay').show();
             $('.marchEvent').show();
             $('.nationalWalk').show();
             $('.marchEvent').show();
           }
           catch(e){
           }
         }
         else{
            $('.dadStory').show();
            $('.epilepsyCamp').show();
         }
       }
       
    }
}();

$(document).ready(function(){
	//$('a.toVimpat').append('&nbsp;<img src="/images/icon_external.gif" alt="" />');
    $('a[rel="external"]').click(function(){
		var dest = $(this).attr('href');
		openExternalWin(dest);
		return false;
    });
    $("a.share-link").attr('href', function(){
        var service = $(this).attr('href');
        var link = "http://api.addthis.com/oexchange/0.8/forward/" + service + "/offer?url=" + window.location + "&description=Here%2527s%20some%20interesting%20information%20about%20getting%20better%20seizure%20control.";
        return link;
    });
	
	$("a.share-link").click(function(){
	    //adds dynamic GA tag functionality
	    var tag = $(this).attr('tag-title');
	    if (tag!=null){
	        //Change below for site-specific tag function, Action, Category, etc
	        trackerTwo._trackEvent('Share', 'Click', tag);
	    };
	    openExternalWin(this.href);
	    return false;
	});
    $("a.share-link").attr('target', '_blank');
    
    UCB.Util.init();
//    var path = document.location.pathname;
//    if (path == "/living-with-epilepsy/epilepsy-specialist-questions.aspx" || path == "/epilepsy-support/articles.aspx" || path == "/community/featuredarticlearchive7.aspx" || path == "/community/featuredarticlearchive8.aspx" || path == "/community/featuredarticlearchive9.aspx")
//    {
//        document.getElementById("SubtierMaster_webcast_callout").className = "webcast-callout-show";   
//    }
});

function showdiv(id){
    var temp = document.getElementById(id);
    temp.style.display = "block";
}
function hidediv(id){
    var temp = document.getElementById(id);
    temp.style.display = "none";
}
function openWindow(){
    window.open("http://www.connect.facebook.com/login.php?connect_id=126245912663&popup=true","mywindow","menubar=1,resizable=1,scrollable=1width=650,height=450");
    //window.open("http://www.connect.facebook.com/login.php?connect_id=126245912663&popup=true","mywindow","menubar=1,resizable=1,width=650,height=450");
}

// Function to pop up an interstitial when linking to external sites
function openExternalWin(url) {
    if(! confirm("You are leaving EpilepsyAdvocate.com, a website sponsored by UCB, Inc. If you arrive at a site that is not sponsored by UCB, note that UCB, Inc. is not responsible for the content or services on these sites.\n\nDo you wish to continue?"))
        return;

    window.open(url);
}
