function ka_ping(){	setInterval(function(){
     		KickAppsBizComponent.pingAlive();
   }, 300000);
}
	
	
//side-wide DOM ready code
$j(document).ready(function(){
	// fix wbr on safari
	if($j.browser.safari) {
		$j("wbr").after("&shy;");
	}
	
	//if user not logged in
	if(Ka.Info.USERID ===''){

    	if ( $('ka_loginPopup') ){
    			$j('#ka_loginPopup input').keypress(function(event){
					return ka_loginPopupInputCheck(this,event);
				});
    		
	    	$j('a.ka_memberAction').click(function(){
			    ka_toggleDiv('form#ka_loginPopup',function(){
			    	$('username').focus();
			    });
			    return false;
			});
	    	$j('input.ka_memberAction').click(function(){
			    ka_toggleDiv('form#ka_loginPopup',function(){
			    	$('username').focus();
			    });
			    return false;
			});
		}
		
		
	}else{
		//ka_ping();

	    // if the LE should launch automatically
		if(document.location.href.indexOf('LE=launch')!=-1 && $('ka_LE_open_anchor')) {
		    // open it up
			$('ka_LE_open_anchor').onclick();
		}
	}
	
	if ($('ka_mainContainer')){
		if($j.browser.msie){
			if($j('body > div:first').attr('id')!=='ka_mainContainer'){
				jQuery.extend({
					dimScreen: function(speed,opacity,callback){
						jQuery('embed,object').each(function(){
							jQuery(this).css('visibility','hidden');
						});
						
						if(navigator.appVersion.indexOf('MSIE 6.0')!=-1){
							jQuery('select').each(function(){
								jQuery(this).css('visibility','hidden');
							});
						}
						
						return jQuery();
					},
					
					dimScreenStop:function(callback){
					    // if the site style isn't open
					    if(!$('ka_le') || ($('ka_le') && Ka.LE.$('ka_le').style.display!=='block')) {
						    jQuery('embed,object').each(function(){
							    jQuery(this).css('visibility','visible');
						    });
						}
						
						if(navigator.appVersion.indexOf('MSIE 6.0')!=-1){
							jQuery('select').each(function(){
								jQuery(this).css('visibility','visible');
							});
						}
						
						if(typeof callback=='function'){
							callback();
						}
						
						return jQuery();
					}
				});
			}
		}
	}
});	

function ka_LEAssets(type)
{
	// if it's Safari
	if(navigator.userAgent.indexOf(' Safari')!=-1)
	{
		// 
		Ka.confirm
		(
			'We\'re currently working on some changes to the Site Styler, '+
			'and it will temporarily only work in Internet Explorer 6 (Windows), '+
			'Internet Explorer 7 (Windows), or FireFox (MAC & Windows).<br /><br />'+
			'Thanks for your understanding.'
		);
	}
	// otherwise if it's not safari
	else
	{
		// load the html first
		var node          =    document.createElement('script');
		node.type         =    'text/javascript';
		node.src	      =    Ka.Info.STATICSERVERJS+'/LE/LEHTML.js';
		document.getElementsByTagName('head')[0].appendChild(node);
	
		// set an interval to check whether the page is ready to launch the LE
		Ka.LEInterval    =    setInterval
							(
								function()
								{
									if(typeof ka_LEMedia=='function')
									{
										// clear the interval
										clearInterval(Ka.LEInterval);
										// add it to the dom
										var OLE          =    document.createElement('div');
										OLE.id	   		 =	  'ka_le';
										OLE.className    =    'ka_le_br';
										OLE.innerHTML	 =    LEHTML;
										OLE.style.display    =    'none';
										document.getElementById('ka_mainContainer').parentNode.insertBefore(OLE,document.getElementById('ka_mainContainer'));
	
										// call media loading function
										ka_LEMedia(type);
									}
								},
								100
							);
    }
}
function ka_loginPopupInputCheck(input,event){
	//13 enter /mac return
	//3 mac enter
	//9 tab
	var keyCode = event.keyCode;
	if ((keyCode == 13 && input.value != '') || keyCode == 3){
		
		if (input.id=='username'){
			if(input.value != '' && $('password').value != ''){
				return true;
			}else if(input.value != ''){
				setTimeout(function(){$('password').focus();},1);
				
			}
			return false;
		}
	//prevent Safari from submitting the form on enter
	}else if(keyCode == 13 || keyCode == 3){
		return false;
	}
	return true;
}

function basicAdvancedSearch(thisLink){
	//add advanced search listener
	var searchLink = thisLink;
	//save "basic" list	
	var basicSearchId;
	$j('#ka_searchAdv1 > ul > li > input').each(function(){
		if (this.checked == 'true'){
					basicSearchId = this.id;
					return;
				}			    
			});
   
			//basic mode
			
	if (searchLink.innerHTML == Ka.Messages.ADVANCED){
		searchLink.innerHTML = Ka.Messages.BASIC;
		searchLink.id = 'ka_search_basic';
		$('ka_searchAdv1').style.display = 'block';

		$j('#ka_searchAdv1 < ul < li < input').each(function(){
			if (this.id == basicSearchId){
				this.checked = false;
			}else{
				this.checked = true;
			}		    
		});	
	//advanced mode
	}else{
		searchLink.innerHTML = Ka.Messages.ADVANCED;
		searchLink.id = 'ka_search_advanced';
		$('ka_searchAdv1').style.display = 'none';
		
	}
	return false;
}

		
/**********************************************/
/* Browser Detection                          */
/**********************************************/

function ka_BrowserDetector( ) {

	this.detect = navigator.userAgent.toLowerCase();
	this.OS = null;
	this.browser = null;
	this.version = null;
	this.total = null;
	this.thestring = null;
	
	this.checkIt = function(string){
		place = this.detect.indexOf(string) + 1;
		this.thestring = string;
		return place;
	};
	
	if (this.checkIt('konqueror')){
		this.browser = "Konqueror";
		this.OS = "Linux";
	}else if (this.checkIt('safari')){ this.browser = "Safari";}
	else if (this.checkIt('omniweb')){ this.browser = "OmniWeb";}
	else if (this.checkIt('opera')){ this.browser = "Opera";}
	else if (this.checkIt('webtv')){ this.browser = "WebTV";}
	else if (this.checkIt('icab')){ this.browser = "iCab";}
	else if (this.checkIt('msie')){ this.browser = "Internet Explorer";}
	else if (!this.checkIt('compatible')){
		this.browser = "Netscape Navigator";
		this.version = this.detect.charAt(8);
	}else{ this.browser = "An unknown browser";}
	
	if (!this.version){ this.version = this.detect.charAt(place + this.thestring.length);}
	
	if (!this.OS){
		if (this.checkIt('linux')){ this.OS = "Linux";}
		else if (this.checkIt('x11')){ this.OS = "Unix";}
		else if (this.checkIt('mac')){ this.OS = "Mac";}
		else if (this.checkIt('win')){ this.OS = "Windows";}
		else{ this.OS = "an unknown operating system";}
	}

}

ka_bd = new ka_BrowserDetector();


/**********************************************/
/* End Browser Detection                      */
/**********************************************/


ka_imagesArray = [];
function ka_preloadImage(src) {
	if(document.images) {
		i = ka_imagesArray.length;
		ka_imagesArray[i] = new Image( );
	    ka_imagesArray[i].src = src;
	}
}

function ka_getOffsetLeft(el) {
	var ol = el.offsetLeft;
	while ((el = el.offsetParent) != null)
		ol += el.offsetLeft;
	return ol;
}

function ka_getOffsetTop(el) {
	var ot = el.offsetTop;
	while((el = el.offsetParent) != null){
		ot += el.offsetTop;
	}
	return ot;
}

function ka_findObj(id) {
	return document.getElementById(id);
}

function ka_disabledInputElement(inptObjName, decision) {
	var o = ka_findObj(inptObjName);
	
	if(o == undefined || o == null ){
		return;
	}
	o.disabled = decision;
}

function ka_getWindowDimensions() {
		var w = $j(window).innerWidth();
		var h = $j(window).innerHeight();
	return {width: w,height: h};
}


function ka_getComputedStyle(_10, _11) {
	if (document.defaultView && document.defaultView.getComputedStyle) {
		var computedStyle = document.defaultView.getComputedStyle(_10, null);
		if (computedStyle == null) {
			// SAFARI HACK
			if (_11 == 'width') {
				return "689px";
			} else if (_11 == 'height') {
				return "297px";
			}
		}
		return document.defaultView.getComputedStyle(_10, null).getPropertyValue(_11);
	} else {
		if(_10.currentStyle) {
			return _10.currentStyle[_11];
		} else {
			return null;
		}
	}
}

function ka_getComputedHeight(e) {
	return $j(e).height();
}

function ka_getComputedWidth(e) {
	return $j(e).width();
}

function ka_getDocumentScrollTop( ) {
	return $j(document).scrollTop();
}

function ka_getDocumentScrollLeft( ) {
	return $j(document).scrollLeft();
}

function ka_getDocumentScrollWidth( ) {
	if (document.documentElement && document.documentElement.scrollWidth) {
		s = document.documentElement.scrollWidth;
	} else if (document.body) {
		s = document.body.scrollWidth;
	} else {
		s = 0;
	}
	return s;
}

function ka_getDocumentScrollHeight( ) {
	if (document.documentElement && document.documentElement.scrollHeight) {
		s = document.documentElement.scrollHeight;
	} else if (document.body) {
		s = document.body.scrollHeight;
	} else {
		s = 0;
	}
	return s;
}

function ka_positionCenter(id) {
	//alert('The function used here is old, please alert Mauvis so he can change to the new function. You don\t have to Jira this message as the fix is quick.');
	obj = document.getElementById(id);
	d = ka_getWindowDimensions();
	
	l = (d.width / 2) - (ka_getComputedWidth(obj) / 2);
	l += ka_getDocumentScrollLeft();
	
	if(!document.all){ l -= 3;}
		
	t = (d.height / 2) - (ka_getComputedHeight(obj) / 2);
	t += ka_getDocumentScrollTop();
	ka_positionObj(id, t, l)

}

function ka_positionObj(id, top, left) {
	try {
		obj = document.getElementById(id);
		obj.style.top = top + "px";
		obj.style.left = left + "px";
	}
	catch(e) {
	}
}

function ka_thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    }
    else {
        return document[movieName];
    }
}

function ka_formatDate(month, day, year, hours, minutes) {
	
	var meridiem = "AM";
			
	if(hours > 12) {
		hours -= 12;
		meridiem = "PM";
	}

	if(month < 10) month = "0" + month;
	if(day < 10) day = "0" + day;
	if(hours < 10) hours = "0" + hours;
	if(minutes < 10) minutes = "0" + minutes;
	
	return  month + "/" + day + "/" + year + " " + hours + ":" + minutes + " " + meridiem;
	
	
}

function ka_empty(val) {
	if(val != undefined && val != "") {
		return false;
	}
	return true;
}

function ka_wordWrap(str, num) {
	
	return Ka.Util.wbr(str, num);
	/*var s = new String(str);
	var words = s.split(" ");
	
	s = "";
	for(var i = 0; i < words.length; i++) {
		var p = "";
		var w = words[i];
		while(w.length > num){
			p += w.slice(0, num) + ' ';
			w = w.slice(num);
		}
		s += p + w;
		if((i + 1) < words.length) s += ' ';
	}
	
	return s;
	*/
}

/*
**************************************************************************************************
http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
*/

function ka_addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	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] );
	}
}

function ka_removeEvent( obj, type, fn )
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}

String.prototype.equalsIgnoreCase=MatchIgnoreCase;

function MatchIgnoreCase(strTerm){
		var strToSearch = this.toLowerCase();
		strTerm = strTerm.toLowerCase();
		if(strToSearch==strTerm){
		return true;
	}else
	{
		return false;
	}
}

/*
**************************************************************************************************
*/

/*
* String trim
*/

	function getImageDimension(imageObj) {
		var image = new Image();
		image.src = imageObj.src;
		var h=image.height;
		var w=image.width;
		
		return w+'x'+h+'px';
    }
    
    function ka_getImageDimension(image, id) {
    	var dim = getImageDimension(image);
    	setImageDimensionText(dim, id);
    }
    
    function setImageDimensionText(dim, id) {
    	imageDim = document.getElementById(id);
    	imageDim.innerHTML = dim;
    }
    

function toggleFlashVideoOn(){
	jQuery('embed,object').each(function(){jQuery(this).css('visibility','visible');}); 
}

function toggleFlashVideoOff(){
	jQuery('embed,object').each(function(){jQuery(this).css('visibility','hidden');}); 
}

			
var kaTimeOutObj = {
	disabled: false, //ka_doNotTimeOut: false,
	action: null,
	time: null,
	idleTimeOut: null,
	
	setInactivityTimer: function(time, action){
		/*if (!this.disabled){
		
			//TinyMCE iframe detection
			function checkTinyMC(){
				if (document.getElementById('mce_editor_0')){			
					iframe = document.getElementById('mce_editor_0');
					function addEvents(iframe){
					    //for good browsers
					    if(iframe.contentDocument){
					        iframe.contentDocument.addEventListener("keypress", kaTimeOutObj.resetTimeOut, false);
					        //for ie
					    } else if (iframe.contentWindow){
					        iframe.contentWindow.document.attachEvent("onkeypress", kaTimeOutObj.resetTimeOut);
					    }
					}		
					var iframe = document.getElementById('mce_editor_0');
					addEvents(iframe);
					if (document.getElementById('mce_editor_1')){
						iframe = document.getElementById('mce_editor_1');
						addEvents(iframe);
					}
				}
			}
			window.setTimeout(checkTinyMC,5000);
		
			this.time = time;
			this.action = action;
			
			//start idle timeout timer
			this.idleTimeOut = window.setTimeout(action, time);

			//set mousemove detection
			document.onmousemove = kaTimeOutObj.resetTimeOut;
				
			//set on keyup detection
			document.onkeyup = kaTimeOutObj.resetTimeOut;
				
			ka_addEvent(window, 'scroll', kaTimeOutObj.resetTimeOut);
		}*/
	},

	resetTimeOut: function(){
		/*
		//clear timeout script
		if (typeof kaTimeOutObj.idleTimeOut == "number"){
			window.clearTimeout(kaTimeOutObj.idleTimeOut);
			delete kaTimeOutObj.idleTimeOut;	
			//restart timeout script 
			kaTimeOutObj.idleTimeOut = window.setTimeout(kaTimeOutObj.action, kaTimeOutObj.time);
		}
		*/
	},
	
	autoLogout: function(kickUrl){
		/*if (!kaTimeOutObj.disabled){
			document.location.href=kickUrl;
		}
		*/
	}
};
	
var win = null;
function openDep(url) {
	win = window.open(url, "_kickapps");
}
			
function closeDep() {
	if (win && win.open && !win.closed){win.close();}
}
			
function signOutUser(){
	switch(Ka.Info.PAGETYPE)
	{
		case 'MKP':
			document.location.href='/user/logoutUser.kickAction?kplogout=true';
			break;
		case 'MB':
			if (Ka.Info.PAGE.indexOf('new')==0)
			{
				document.location.href='/user/logoutUser.kickAction';
			} else {
				$j.get("/user/logoutUser.kickAction", function() {document.location.href=document.location.href;});
			}
			break;
		default:
			$j.get("/user/logoutUser.kickAction", function() {document.location.href=document.location.href;});
			break;
	}
}
			
function nonEditableFileField(file) {
	file.blur();
}

function ka_toggleDiv(id) {	
	// if it's not for the photo preview
	if(id!='ka_photoPreviewDiv')
	{
		kap_SSOLoginCheck();
	}
	
	//callback function focuses on login once faded in
	Ka.popup(id,function(){
		if (id == 'ka_loginPopup' || id == 'form#ka_loginPopup'){
			$('username').focus();
		}
	});
	
}
	
function kap_SSOLoginCheck()
{
	if ($('ssoEnabled')){
		// if they're using SSO
		if($('ssoEnabled').value=='true')
		{
			var loginChar    	=    "?";
			var loginURL 		= 	 $('ssoLoginUrl').value;
			if (loginURL.indexOf("?") != -1) {
				loginChar = "&";
			}
			var redirectURL = encodeURIComponent(window.location.href);
			// redirect
			document.location.href    =   $('ssoLoginUrl').value+''+loginChar + 'redirectUrl=' +redirectURL;
		}
	}
}

//Login popup functions
function ka_shadeOn(){
	jQuery.dimScreen(800, 0.4, function(){
		//jQuery('#ka_loginPopup').fadeIn("slow");
	});
}

function ka_shadeOff(){
	jQuery.dimScreenStop();
	jQuery('#ka_shadeDiv').fadeOut("slow");
}

 
function ka_Help(contact,email,host,elementId){
	$j("#"+elementId).html("<a href=" + "mail" + "to:" + email + "@" + host + ">"+Ka.Messages.HELP+"</a>");
}

//userplane
function ka_openChat(){
		//reset timeout
		kaTimeOutObj.disabled=true;
		kaTimeOutObj.resetTimeOut();
		window.open('/service/displayChatWindow.kickAction?as='+Ka.Info.AFFILIATESITEID, 'Terms', 'width=716,height=563,location=no,menubar=no,resizable=yes,scrollbars=yes,toolbar=no,status=no');
}