﻿
/* =================================================================== */
// function to add events crossbrowser
// from: http://www.dustindiaz.com/rock-solid-addevent/
// uncomment the EventCache lines if using EventCache function from code lib
function addEvent( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
		//EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
		//EventCache.add(obj, type, fn);
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
}
/* =================================================================== */


/* =================================================================== */
// various link functionality - popups, external, onstate
// original script taken from Jeremy Keith
// dependencies: cssjs(), addEvent()
var anchors = {
	a : Object,
	doPopups : function() {
		if (!document.getElementsByTagName) return false;
		var links = document.getElementsByTagName("a");
		for (var i=0; i < links.length; i++) {
			var anchor = links[i];
			if (anchor.getAttribute('href') && anchor.rel.match('external')) {
				anchor.onclick = function() {
					return anchors.openWin(this,"newWin","");
				}
				cssjs('add',anchor,'external');
			}
		
		      if (cssjs('check',anchor,'pdf')) {
				anchor.onclick = function() {
					return anchors.openWin(this,"pdfWin","width=700, height=550,toolbar=yes, resizable=yes");
				}
		    }
		 
			if (anchor.href == location.href) {
				cssjs('add',anchor,'onstate');
			}
		}
	},
	openWin : function(o,winName,params) {
		var win=window.open(o.href,"" + winName + "","" + params + "");
		win.focus();
		return false;
	}
}
addEvent(window,'load',anchors.doPopups);
/* =================================================================== */

/* =================================================================== */
// function to add/remove classes from elements
// written by Christian Heilmann 
// more info here http://www.onlinetools.org/articles/unobtrusivejavascript/cssjsseparation.html
// call like cssjs('add',containerOBJ,classname);
function cssjs(a,o,c1,c2){
	switch (a){
		case 'swap':
			o.className=!cssjs('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
		break;
		case 'add':
			if(!cssjs('check',o,c1)){o.className+=o.className?' '+c1:c1;}
		break;
		case 'remove':
			var rep=o.className.match(' '+c1)?' '+c1:c1;
			o.className=o.className.replace(rep,'');
		break;
		case 'check':
			return new RegExp("(^|\\s)" + c1 + "(\\s|$)").test(o.className)
		break;
	}
}

/* =================================================================== */

function swapTabContent(sName)
{
	var sActiveTabClass = "active";
	$("ul#tabs li").removeClass(sActiveTabClass);
	$("//div[@id='tabsContainer']/div").hide();
	$("#tabsContainer div#content" + sName).show();
	$("#tab" + sName).parent().addClass(sActiveTabClass);
	return false;
}


/* =================================================================== */
// use this to automatically clear a text box of it's default value
// if nothing is typed in the box, the script will put the default value back
// useful on sites where search boxes don't have a seperate label
// you can use it for more than one box per page using the txtBoxes array
search = {
	txtBoxes : ['searchField'],
	init: function() {
		for (i=0;i<search.txtBoxes.length;i++) {
			var oCurrentTxtBox = document.getElementById(search.txtBoxes[i]);
			if (!oCurrentTxtBox) { continue; }
			oCurrentTxtBox.defaultVal = oCurrentTxtBox.defaultValue;
			search.clearBox(oCurrentTxtBox);
		}
	},
	clearBox : function(txtBox) {
		txtBox.onfocus = function() {
			if (txtBox.value == txtBox.defaultVal) { txtBox.value = ''; } 
		};
		txtBox.onblur = function() {
			if (txtBox.value == '') { txtBox.value = txtBox.defaultVal; }
		};
	}
};
addEvent(window,'load',search.init);
/* =================================================================== */





var partners = {
	mfrDivPaddingVert	: 26,
	mfrDivPaddingLeft	: 189,
	init : function() {
		$('html').addClass('js');
		$(document).ready(function(){
			//partners.hideImages();
		});
		addEvent(window,'load',partners.centerImages);
	},
	hideImages : function() {
		$('div.partner img').css( { visibility: "hidden" });
	},
	centerImages : function() {
		// you got it - centers the images in their alloted space
		var aLogoDivs = $('div.partner');
		for (i=0;i<aLogoDivs.length;i++) {
			var oCurrentDiv = aLogoDivs[i];
			var iDivHeight = oCurrentDiv.offsetHeight - partners.mfrDivPaddingVert;
			var oChildImg = oCurrentDiv.getElementsByTagName('img')[0];
			var iImgHeight = oChildImg.height;
			var iImgWidth = oChildImg.scrollWidth;
			if (iImgHeight > iDivHeight) {
				iDivHeight = iImgHeight;
				oCurrentDiv.style.height = iDivHeight + 'px';
			}
	//$(oCurrentDiv).append("<p>img width: " + iImgWidth);
			var iMarginTop = (iDivHeight/2) - (iImgHeight/2);
			var iMarginLeft = (partners.mfrDivPaddingLeft - iImgWidth)/2;
	//$(oCurrentDiv).append("<p>marginleft: " + iMarginLeft);
			//oChildImg.style.marginTop = iMarginTop + 'px';
			//oChildImg.style.marginRight = iMarginLeft + 'px';
			oChildImg.style.top = iMarginTop + 'px';
			oChildImg.style.right = iMarginLeft + 'px';
			oChildImg.style.visibility = "visible";
			
			
			partners.createLinks(oCurrentDiv);
			
		}
		//$('div.mfr img').css( { visibility: "visible" });
	},
	createLinks : function(oDiv) {
		// links the images based on the textual link
		var oLink = $(oDiv).find('p a');
		if (oLink.length > 0) {
			$(oLink).click(function() {
				 window.open(this.href);
				 return false;
			});
			var sHref = $(oLink).attr('href');
			if (sHref) {
				$(oDiv).find('img').wrap('<a href="' + sHref + '"></a>').click( function() {
					window.open($(this).parent().attr('href'));
					return false;
				});
			}
		}
	}
}

// Rakefet - For FAQ toogles...
function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
    if(document.layers)	   //NN4+
    {
       document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
    }
}

var prevID =1;
function show(id) {

	// Hide Previous
	toggleBox("d"+prevID,0);

	// Show next
	toggleBox("d"+id,1);

	prevID=id;
};
