﻿/* 
Correctly handle PNG transparency in Win IE 5.5 & 6.
*/

function fixPng() {
  var arVersion = navigator.appVersion.split("MSIE")
  var version = parseFloat(arVersion[1])

  if ((version >= 5.5 && version < 7.0) && (document.body.filters)) {
    for(var i=0; i<document.images.length; i++) {
      var img = document.images[i];
      var imgName = img.src.toUpperCase();
      if (imgName.indexOf(".PNG") > 0) {
        var width = img.width;
        var height = img.height;
        var sizingMethod = (img.className.toLowerCase().indexOf("scale") >= 0)? "scale" : "image"; 
        img.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img.src.replace('%23', '%2523').replace("'", "%27") + "', sizingMethod='" + sizingMethod + "')";
        img.src = "/images/sites/blank.gif";
        img.width = width;
        img.height = height;
      }
    }
    
    var imgs = document.getElementById("lcimg").getElementsByTagName("img");
    
    for(var i=0; i<imgs.length; i++) {
      var img = imgs[i];
      var imgName = img.src.toUpperCase();
      if (imgName.indexOf(".JPG") > 0) {
        var width = img.width;
        var height = img.height;
        var sizingMethod = (img.className.toLowerCase().indexOf("scale") >= 0)? "scale" : "image"; 
        img.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img.src.replace('%23', '%2523').replace("'", "%27") + "', sizingMethod='" + sizingMethod + "')";
        img.src = "/images/sites/blank.gif";
        img.width = width;
        img.height = height;
      }
    }
  }
}



function emailPop()
{
	openwin('/' + getlanguage() + '/pages/sendPage.htm');
}

function printPop()
{
	openwin('/' + getlanguage() + '/pages/printPage.aspx');
}

function feedback()
{
	openwin('/' + getlanguage() + '/pages/userFeedback_form.aspx');
}

function getlanguage()
{
	if (document.location.href.toLowerCase().indexOf("/es/")>=0)
		return "es";
	else
		return "en";	
}

function openwin(url)
{
	var windowHandle = window.open(url,'openWin','left=10,top=10,width=562,height=500,scrollbars=yes,menubar=no,resizable=no,toolbar=no,status=yes');
    if (!windowHandle.opener)
         windowHandle.opener = self;	
}

function openwinResize(url)
{
	var windowHandle = window.open(url,'openWin','left=10,top=10,width=562,height=500,scrollbars=yes,menubar=no,resizable=yes,toolbar=no,status=yes');
    if (!windowHandle.opener)
         windowHandle.opener = self;	
}

function writePopWinUrl(url,title_en,title_es)
{
	var urlRoot="";
	if (url!="") 
		urlRoot= "<a href='" +  url + "' target=_blank>";
	if (getlanguage()=="en")
		document.write(urlRoot + title_en + ((urlRoot!="")?"</a>":""));
	else
		document.write(urlRoot + title_es + ((urlRoot!="")?"</a>":""));
	
}


function writeLanguageAndUrl(url,title_en,title_es)
{	
	var urlRoot="";
	if (url!="") urlRoot="<a href='/" + getlanguage() + url + "'>";
	if (getlanguage()=="en")
		document.write(urlRoot + title_en + ((urlRoot!="")?"</a>":""));
	else
		document.write(urlRoot + title_es + ((urlRoot!="")?"</a>":""));
		
}

function writeLanguageAndJSUrl(url,title_en,title_es)
{	
	var urlRoot="";
	if (url!="") urlRoot="<a href=javascript:openwin('/" + getlanguage() + url + "')>";
	if (getlanguage()=="en")
		document.write(urlRoot + title_en + ((urlRoot!="")?"</a>":""));
	else
		document.write(urlRoot + title_es + ((urlRoot!="")?"</a>":""));
}

function printLanguageText(title_en,title_es)
{	
	if (getlanguage()=="en")
		document.write(title_en);
	else
		document.write(title_es);
}

function skipLanguageUrl()
{	
	if (document.location.href.toLowerCase().indexOf("/en/")>=0)		
		document.location.href = document.location.href.toLowerCase().replace("/en/","/es/").replace("s=en","s=es");
	else
		document.location.href = document.location.href.toLowerCase().replace("/es/","/en/").replace("s=es","s=en");
}

function writeLanguageImages(filename,postfix)
{	
	if (filename!="")
	{
		var img_html="<img src='/images/sites/" + filename + "_" + getlanguage() + "." + postfix + "'  border='0'/>";
		document.write(img_html);
	}
}

function clickLinkforLanguage(link)
{	
	document.location.href = "/" + getlanguage() + link;
}


function openJSVideo()
{
	window.open("/SystemImages/joetorre.swf", "newwindow", "height=400px, width=640px, top=100, left=100, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no");	
}

function openJTSVideo()
{
	if (getlanguage()=="en")
		window.open("/SystemImages/videoplayer/JTS_Video.htm", "newwindow", "height=360px, width=640px, top=100, left=100, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no");
	else
		window.open("/SystemImages/videoplayer/JTS_Video.htm?es=1", "newwindow", "height=360px, width=640px, top=100, left=100, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no");		
	return false;
}

function logoUrl()
{
	window.location.href="/"+getlanguage();
}

function getlangPath(objA)
{				
	if (document.location.href.toLowerCase().indexOf("/es/")>=0)			
	objA.href= objA.href.toLowerCase().replace("/en/","/es/");
}

function JTSearchKeyDown(event)
{
	if (event.keyCode == 13)
	{
		goSearchResult();
		return false;
	}
	
}
function goSearchResult(){
var objSearch=document.getElementById("idSearchString");
if (objSearch){
	var k =  objSearch.value;
	if (k=="Search")
		k= "";
	window.location.href="/"+getlanguage()+"/pages/results.aspx?k="+k+"&s="+getlanguage();
	// alert(window.location);
	return true;
	
}	
}

function openWindowFacebook()
{	window.open("http://apps.facebook.com/causes/219461/46875562?m=cc366e79", "newwindow");	
}
function openWindowTwitter()
{	window.open("http://www.twitter.com/joetorrecharity", "newwindow");	
}

function openWindowNewsletter()
{	
	var ea=document.getElementById("idea");
	window.open("http://visitor.constantcontact.com/d.jsp?m=1102509756621&p=oi&ea=" + ea.value, "newwindow");	
}

// input box function -- handle 
function ClearText( obj,defaulttext )
{
    if(obj.value == defaulttext )
    {
        obj.value = "";
    }
}
function BlurText( obj,defaulttext )
{
    if( jQuery.trim(obj.value) == "" )
    {
        obj.value = defaulttext;
    }
}

// get html from server
function modulehtml(htmlUrl)
{
    this._url = htmlUrl;

    //Get Survey Result via ajax
    this.GetResult = function(objId)
    {
        //alert(this.getSelectedChoices('radio'));
        jQuery.ajax({
                type: "GET",
                url: this._url ,
                dataType: "html",
                success: function(html) {
                   jQuery("#"+ objId ).html(html);
                }
            });
    }
}

// event list

var first_load_image=true;

function moduleEventImages(url)
{
    this._url = url;

    //Get Survey Result via ajax
    this.Build = function(objId)
    {
        //alert(this.getSelectedChoices('radio'));
        jQuery.ajax({
                type: "GET",
                url: this._url + "&rnd="+Math.random(),
                dataType: "html",
                success: function(html) {
                   jQuery("#"+ objId ).html(html);
                   if(jQuery("#diveventimgs div").length>0)
                   {	
                   	 jQuery("#diveventimgs div img").eq(0).click();
                   }
                }
            });
    }
}

function clickThumbnailImg(obj,img)
{
	jQuery("#lcimg").html("<IMG src='" + img + "'/>");
	if (!first_load_image)
	{
		openwinResize(img);
	}	
	jQuery("#diveventimgs div img").removeClass();
	jQuery("#diveventimgs div img").addClass("eventimg");
	jQuery(obj).removeClass();
	jQuery(obj).addClass("eventimg_selected");
	first_load_image = false;
}

var Sliders = function(container){
    this._container = container;
    this._currentIndex = -1;
    this.Sliders = new Array();
    var counter = -1;
    
    for(var i = 0; i< this._container.childNodes.length; i++){  
                     
        if(this._container.childNodes[i].tagName != null){
            //alert(this._container.childNodes[i].tagName); 
            counter = counter +1;
            this.Sliders[counter] = this._container.childNodes[i];
            this.Sliders[counter].className = "slider_hide";
            
            if(counter == 0){
                this._currentIndex = counter;
                //this.Sliders[this._currentIndex].style.display = "";
                this.Sliders[counter].className = "slider_visible";
            }
        }
    }
    //alert(this.Sliders.length);
}


Sliders.prototype.getCurrentSlider = function(){
    if(this._currentIndex>=0){
        return this.Sliders[this._currentIndex];
    } 
}

Sliders.prototype.setCurrentSlider = function(slider){
    var originalIndex = this._currentIndex;
    for(var i=0; i<this.Sliders.length;i++){
        if(slider === this.Sliders[i]){
            this._currentIndex = i;
        }
    }
    
    //alert(originalIndex + "/" +this._currentIndex);
    if(originalIndex>=0){
        this.Sliders[originalIndex].className = "slider_hide";
    }
    
    if(this._currentIndex>=0){
        this.Sliders[this._currentIndex].className = "slider_visible";
    }
}

Sliders.prototype.Next = function(){
    if(this._currentIndex>=0){
        var nextIndex = this._currentIndex + 1;
        if(this._currentIndex == this.Sliders.length - 1){
            nextIndex = 0;
        }
        this.setCurrentSlider(this.Sliders[nextIndex]);
    }            
}

Sliders.prototype.Preview = function(){
    if(this._currentIndex>=0){
        var nextIndex = this._currentIndex - 1;
        if(this._currentIndex == 0){
            nextIndex = this.Sliders.length -1;
        }
        
        this.setCurrentSlider(this.Sliders[nextIndex]);
    } 
}


