$(document).ready(
		function () {
			try {
				
				initializeBanner();
				initializePreloading();
				initializeLogin();  //custom login javascripts....
				initializeSearch(); //custom search javascripts....
				initializeAdminSearch(); //initialize admin search functions
				
				setKeypressSearch();
				setCheckresource();//for school zone resource type if all items are checked
				initializeSchoolZoneDate();//schoolzone date
				
				initializeAdvancedSearch();//initialize advanced search features
				
//				var noHead = $('#isNohead').val();
//				alert(noHead);
//				if (noHead == 1) {
//					$('body#body').css("background-image", "none");
//					$('#body').css('background-repeat','no-repeat');
//				}
				initdropDivMoon();
				togglePremOpen();
				toggleDefaultOpen();
				/* comment out for default checks */
				
				
//				setPremOpenCheck();
				/* comment out for default checks */
				misc();
				
				
				/*watermark and disabling right click for images*/
				
				var subscribe = $('#isSubscribed').val();
				
				$(document).bind('cbox_complete', function(){
					//margin top= -height of the watermark image
					if(null == subscribe || subscribe == "false"){
						$('#cboxLoadedContent').append('<img id="cboxPhoto2" src="'+ctx+'/faces/images/ggflwatermark.png" style="position:relative; float:right; margin-top:-60px;margin-right:8px;"/>');
					}
					
					$('#cboxPhoto').bind("contextmenu",function(e){
			              return false;
					}); 
					$('#cboxPhoto2').bind("contextmenu",function(e){
			              return false;
			       }); 
					
				    });
				/*watermark and disabling right click for images*/
			
				
			} catch (e) {
				//alert(e);
			}
		}
);



function initializeBanner(){
	//local
	
//	if($('#headerDir').html()!="new_header.jpg" && $('#headerDir').html()!="../../organisation_logo/new_header.jpg"&& $('#headerDir').html()!="../../school_logo/new_header.jpg"){
//		$('#header').css('background-image','url("'+$('#headerDir').html()+'")');
//		$('#rightHeadSpan').css('background-image','url("'+$('#rightheaderDir').html()+'")');
//		$('#leftHeadSpan').css('background-image','url("'+$('#leftheaderDir').html()+'")');
//	}
		
		
		
//		alert($('#rightheaderDir').html());
//	}else{
//		$('#header').css('background-image','url("../images/new_header.jpg")');
//		$('#rightHeadSpan').css('background-image','url("../images/new_bgtopright.jpg")');
//		$('#leftHeadSpan').css('background-image','url("../images/new_bgtopleft.jpg")');
//	}
	
	//dev
//	if($('#headerDir').html()!="new_header.jpg" && $('#headerDir').html()!="../../../organisation_logo/new_header.jpg"&& $('#headerDir').html()!="../../../school_logo/new_header.jpg"){
//		$('#header').css('background-image','url("'+$('#headerDir').html()+'")');
//		$('#rightHeadSpan').css('background-image','url("'+$('#rightheaderDir').html()+'")');
//		$('#leftHeadSpan').css('background-image','url("'+$('#leftheaderDir').html()+'")');
//	}else{
//	$('#header').css('background-image','url("../images/new_header.jpg")');
//	$('#rightHeadSpan').css('background-image','url("../images/new_bgtopright.jpg")');
//	$('#leftHeadSpan').css('background-image','url("../images/new_bgtopleft.jpg")');
//	}
	

};


function misc(){
	var layout = theme;
	
	if(isIE7){
		$('#TOF_download_link').css('margin-right','-8px');
 	}
	
	if(layout.indexOf('green') != -1){
		$('#homeIcon').attr('src',ctx+'/faces/images/icon_home.png');
	}
	else if (layout.indexOf('gray') != -1){
		$('#homeIcon').attr('src',ctx+'/faces/images/icon_home_blu.png');
	}
	
	
	$('#submitBtn').click(function(){
		$('#submitBtn').css('display','none');
		$('#questionLbl').html(" ");
		$('#submitTxt').css('display','none');
		$('#doneQuestion').html("<strong>Thank you for submitting a question.</strong>");
		
	});
	
	$('#fromYear').attr("autocomplete","off");
	$('#fromDay').attr("autocomplete","off");
	$('#toYear').attr("autocomplete","off");
	$('#toDay').attr("autocomplete","off");
	
	
	if(pName="Safari"){
		$('.contentPub').attr("style","min-height: 200px;");
	}
	
}

function clickCheckbox(elem){
	$(elem).find("input#personal_checkbox").attr("checked","checked");
};


function togglePremOpen(){
	if($.session("showResource_session")!=null && $.session("showResource_session")!="none"){
		$('#search_contentId').css('display','block');
		$.session("showResource_session","block");
		
		
	}else{
		$('#search_contentId').css('display','none');
		$.session("showResource_session","none");
		
	}
	
	if($.session("showPrem_session")!=null && $.session("showPrem_session")!="none"){
		$('#1').parent('li').parent('ul').css('display','block');
		$.session("showPrem_session","block");
		$('#1').parent('li').parent('ul').prev('a').find('span').removeClass('hasArrow');
		$('#1').parent('li').parent('ul').prev('a').find('span').addClass('drop');
	}else{
		$('#1').parent('li').parent('ul').css('display','none');
		$.session("showPrem_session","none");
		
		$('#premiumId').next('a').find('span').each(function(){
			$(this).removeClass('drop');
			$(this).addClass('hasArrow');
		});
	}
	
	if($.session("showOpen_session")!=null && $.session("showOpen_session")!="none"){
		$('#5').parent('li').parent('ul').css('display','block');
		$.session("showOpen_session","block");
		$('#5').parent('li').parent('ul').prev('a').find('span').removeClass('hasArrow');
		$('#5').parent('li').parent('ul').prev('a').find('span').addClass('drop');
	}else{
		$('#5').parent('li').parent('ul').css('display','none');
		$.session("showOpen_session","none");
		
		$('#openId').next('a').find('span').each(function(){
			$(this).removeClass('drop');
			$(this).addClass('hasArrow');
		});
	}	

};

function toggleDefaultOpen(){
	var toggleStatus = $.session('formatDefault');
	
	var formatDiv = $('div#format_open');
	var formatAEL = $(formatDiv).find('a.closeElFirst:first');
	var formatASpan = $(formatDiv).find('a.closeElFirst span:first');
	var formatUl = $(formatDiv).find('ul.first:first');
	
	$(formatAEL).bind('click',
		function(){		
			var toggleStatus = $.session('formatDefault');

			if ('closed' == toggleStatus) {
				$(formatASpan).removeClass('first hasArrow');
				$(formatASpan).addClass('first drop');

				$(formatUl).css('display','block');
				$.session('formatDefault', 'open');
			}
			else {
				$(formatASpan).removeClass('first drop');
				$(formatASpan).addClass('first hasArrow');

				$(formatUl).css('display','none');
				$.session('formatDefault', 'closed');
			}
		}
	);
	
	if (toggleStatus == null || 'open' == toggleStatus){	
		$(formatASpan).removeClass('first hasArrow');
		$(formatASpan).addClass('first drop');

		$(formatUl).css('display','block');
		$.session('formatDefault', 'open');
	}
	else {
		$(formatASpan).removeClass('first drop');
		$(formatASpan).addClass('first hasArrow');

		$(formatUl).css('display','none');
		$.session('formatDefault', 'closed');
	}
};

function setPremOpenCheck(){
//	$.session("premium_session" , "false");
//	$.session("open_session" , "false");
	try{
//		alert("PREMIUM OPEN CHECK");
				if($.session("pLibrary_session")!=null && $.session("pLibrary_session")=="true"){
					$("#1").attr("checked","checked");
					$.session("pLibrary_session" , "true");
//					alert("1 check");
					
				}
				else if($.session("pLibrary_session")!=null && $.session("pLibrary_session")=="false"){
					$("#1").removeAttr("checked");
					$.session("pLibrary_session" , "false");
//					alert("1 !check");
					
				}
				if($.session("pColl_session")!=null && $.session("pColl_session")=="true"){
					$('#2').attr("checked","checked");
//					alert("2 check");
					
				}
				else if($.session("pColl_session")!=null && $.session("pColl_session")=="false"){
					$("#2").removeAttr("checked");
//					alert("2 !check");
					
				}
				if($.session("pCourse_session")!=null && $.session("pCourse_session")=="true"){
					$("#3").attr("checked","checked");
//					alert("3 check");
					
				}	
				else if($.session("pCourse_session")!=null && $.session("pCourse_session")=="false"){
					$("#3").removeAttr("checked");
//					alert("3 !check");
				}
					
				
				if($.session("pPay_session")!=null && $.session("pPay_session")=="true"){
					$("#4").attr("checked","checked");
//					alert("4 check");
				}
					
				else if($.session("pPay_session")!=null && $.session("pPay_session")=="false"){
					$("#4").removeAttr("checked");
//					alert("4 !check");
				}
					
					
				if($.session("oLibrary_session")!=null && $.session("oLibrary_session")=="true"){
					$("#5").attr("checked","checked");
//					alert("5 check");
					
				}
				else if($.session("oLibrary_session")!=null && $.session("oLibrary_session")=="false"){
					$("#5").removeAttr("checked");
					
//					alert("5 !check");
					
				}
				
				if($.session("oColl_session")!=null && $.session("oColl_session")=="true"){
					$("#6").attr("checked","checked");
					
//					alert("6 check");
				}
					
				else if($.session("oColl_session")!=null && $.session("oColl_session")=="false"){
					$("#6").removeAttr("checked");
					
//					alert("6 !check");
				}
					
				
				if($.session("oCourse_session")!=null && $.session("oCourse_session")=="true"){
					$("#7").attr("checked","checked");
					
//					alert("7 check");
				}
					
				else if($.session("oCourse_session")!=null && $.session("oCourse_session")=="false"){
					$("#7").removeAttr("checked");
					
//					alert("7 !check");
				}
					
				
				if($.session("premium_session")!=null && $.session("premium_session")=="true"){
					$("#premiumId").attr("checked","checked");
					$("#1").attr("checked","checked");
					$('#2').attr("checked","checked");
					$("#3").attr("checked","checked");
					$("#4").attr("checked","checked");
					
					
//					alert("premium check");
				}
//				else if($.session("premium_session")!=null && $.session("premium_session")=="false"){
//					$("#premiumId").removeAttr("checked");
//					$("#1").removeAttr("checked");
//					$("#2").removeAttr("checked");
//					$("#3").removeAttr("checked");
//					$("#4").removeAttr("checked");
//					
//					alert("premium !check");
//				}
					
				
				if($.session("open_session")!=null && $.session("open_session")=="true"){
					$("#openId").attr("checked","checked");
					$("#5").attr("chekced","chekced");
					$("#6").attr("checked","checked");
					$("#7").attr("checked","checked");
					
//					alert("open check");
				}
//				else if($.session("open_session")!=null && $.session("open_session")=="false"){
//					$("#openId").removeAttr("checked");
//					
//					$("#5").removeAttr("checked");
//					$("#6").removeAttr("checked");
//					$("#7").removeAttr("checked");
//					alert("open !check");
//				}	
				
				setColoredTabs();
				
				
	}
	catch(e){
		
	}

	
};

function initdropDivMoon(){
	if (true) {
		return;
	}
	
	try {
		if(null == $.session("showDiv") || $.session("showDiv")=="--"){
			if($('#status').val()=='false'){
				$('#dropDivMoon').css('display','none');
				$('#iconUpImg').attr('src',ctx+'/faces/images/icon_down.gif');
				$('#co-texthedIdMoon').css("border","none");
			}
			else{
				$('#co-texthedIdMoon').css("border","1px solid #CCC");
				$('#co-texthedIdMoon').css("margin","5px");
				$('#co-texthedIdMoon').css("padding","10px");
				$('#dropDivMoon').css('display','block');
				$('#iconUpImg').attr('src',ctx+'/faces/images/icon_up.png');
			}
		}else{
			if($.session("showDiv")!="true"){
				$('#dropDivMoon').css('display','none');
				$('#iconUpImg').attr('src',ctx+'/faces/images/icon_down.gif');
				$('#co-texthedIdMoon').css("border","none");
			}
			else{
				$('#co-texthedIdMoon').css("border","1px solid #CCC");
				$('#co-texthedIdMoon').css("margin","5px");
				$('#co-texthedIdMoon').css("padding","10px");
				$('#dropDivMoon').css('display','block');
				$('#iconUpImg').attr('src',ctx+'/faces/images/icon_up.png');
			}
		}

	}
	catch (e) {}
};



function initializeSchoolZoneDate() {
	$('#as_det_year').keyup(function(){enableMonth();});
	$('#as_det_month').change(function(){enableDay();});
}

function initializeAdvancedSearch() {
	$('#suggestionKeyword').click(function(){ setInputElements();});
	
	$('#doSearchBtn1 a:first,#doSearchBtn2  a:first').click(function(){
		showWithin();
	});
	if($.session("hideWithinSession1")!= null && $.session("hideWithinSession1") == "show" || $.session("hideWithinSession2")!= null && $.session("hideWithinSession2") == "show") {
			$("#hideWithin").css("display","block");
	}
	if($.session("hideWithinSession1")!= null && $.session("hideWithinSession1") == "hide" || $.session("hideWithinSession2")!= null && $.session("hideWithinSession2") == "hide"){
		$("#hideWithin").css("display","none");
	}
	if($.session("hideWithinSession1")== null || $.session("hideWithinSession2")== null)
		$("#hideWithin").css("display","none");
		
	$('#subscribeBtn').click(function(){
		
		if($('#firstName').val()==null || $('#firstName').val()==""|| $('#lastName').val()==null || $('#lastName').val()==""|| $('#email').val()==null || $('#email').val()==""|| $('#organisationName').val()==null || $('#organisationName').val()==""){
			return true;
		}	
		else{
			$.session("hide","none");
			$('#toHideDiv').css('display','none');
			return false;
		}
	});
	if($.session("hide")=="none"){
		$('#toHideDiv').css("display","none");
		$.session("hide","block");
	}else if($.session("hide")=="block"){
		$('#toHideDiv').css("display","block");
	}
		
};

/** preloading mechanisms for browsing efficiency */
function initializePreloading() {
	$.preloadCssImages();
}
/** begin admin search functions... */
function toggleAge() {
	
	var atab = toEmptyString('atab');
	if (atab != '') {
		$('#age_all').fadeOut(200);
		$('#age_filtered').fadeIn('slow');
		$.session('atab:','--');
		
		$('#age_button_col').toggle();
		$('#age_button_uncol').toggle();
	}
	else {
		$('#age_filtered').fadeOut(200);
		$('#age_all').fadeIn('slow');	
		$.session('atab:','expanded');
		
		$('#age_button_uncol').toggle();
		$('#age_button_col').toggle();
	}

	$('input[name="search_ages1"]:checked').each(function() {
		$(this).removeAttr('checked');
	});

	$('input[name="search_ages2"]:checked').each(function() {
		$(this).removeAttr('checked');
	});

	$('input[name="search_ages3"]:checked').each(function() {
		$(this).removeAttr('checked');
	});

	$('input[name="search_ages4"]:checked').each(function() {
		$(this).removeAttr('checked');
	});

	$('.grade_search').parents().find('a.closeEl').removeAttr('style');

	
	clearForm('#age_filtered');
	setColoredTabs();
	clearForm('#age_all');
	setColoredTabs();
};

/** begin admin search functions... */
function initializeAdminSearch() {
	$(".selectAsset").click(function(){ initializeAssetDetails();return false;});	
};
function initializeAssetDetails() {
	$('#isSelected').html("true");
	parent.$.fn.colorbox.close();
	$(".logout").click();
};

/** begin school zone functions... */
function setCheckresource() {
	

	
	var tabbedhue = getTabColor();
	var str = 0;
	$('input[name="search_types2"]:checked').each(function() {
		str ++;
	}
	);
	var totalItems = $('input[name="search_types2"]').size();
	if(totalItems == (str+1)){
		$('input[name="search_types2"]').attr('checked','checked');
	}
};
function enableMonth() {
	var year = $('#as_det_year').val();

	if (year > 0) {//to check if integer is entered
		$('#as_det_month').removeAttr('disabled');
	}

};
function enableDay() {
	$('#as_det_day').removeAttr('disabled');
};

/** begin custom login functions... */
function initializeLogin() {
	//password field listener in login page
	$(".passField").data("capsTriggered", false);
	$(".passField").data("capsShaking", false);

	$(".passField").keypress(function (e) { passwordKeyPress(e); });
	$(".userField").keypress(function (e) { passwordKeyPress(e); });
	
	if($.session("passRecheck_session")==null){
		reCheck();
	}
	
	
};

function passwordKeyPress(e){

	//show caps alert if capslock is on
	if ($(".passField").data("capsTriggered") == false) {
		if( (65 <= e.which) && (e.which <= 90) && !e.shiftKey){
			$("#capslock").fadeIn("slow");
			$(".passField").data("capsTriggered", true);
		}
	}else{
		//shake caps alert if caps alert is on and still typing
		if( (65 <= e.which) && (e.which <= 90) && !e.shiftKey){
			if($(".passField").data("capsShaking") == false){
				$("#capslock").effect("bounce", { times:3 }, 300,
						function(){
					$(".passField").data("capsShaking", false);
				}
				);
				$(".passField").data("capsShaking", true);
			}
		}else if( ((65 > e.which) || (e.which > 90)) && !e.shiftKey){
			$("#capslock").effect("explode", { times:3 }, 300);
			$(".passField").data("capsTriggered", false);
		}
	}
};
/** end custom login functions... */

/** begin custom search functions... */
function initializeSearch() {
	putMoon();	
	showHideMoon();
	initMoon();
	setBegin();
	setCheckedTree();
	setInputElements();
	setSearchtoggle();
	setSearchSubtoggle();
	setColoredTabs();
};



function setBegin() {
	var topUnorderedList  	= $('ul.top,ul.top2');
	var tree 				= topUnorderedList.find('li.tree');

	var firstLevel  		= tree.find('span.first' );
	var secondLevel 		= tree.find('span.second');
	var thirdLevel  		= tree.find('span.third' );
	
	var firstLevelInput  	= tree.find('input.first' );
	var secondLevelInput 	= tree.find('input.second');
	var thirdLevelInput  	= tree.find('input.third' );
	
	var loop = null, loopLen = 0, _this = null;
	
	loop = $(topUnorderedList);
	loopLen = loop.length;
	for (var i=0;i<loopLen;i++) {
		_this = loop[i];
		$(_this).find('li:first').attr('class','search_multipleselect_bordertop'); 
	}

	loop = $(firstLevel);
	loopLen = loop.length;
	for (var i=0;i<loopLen;i++) {
		_this = loop[i];
				
		if ($(_this).next('ul').length > 0) {
			$(_this).wrap('<a class="closeElFirst" href="javascript:void(0);"></a>');
//			$(_this).prepend('<img src="'+ctx+'/faces/images/icon_subuncollapse.gif" class="subcollapsable_1"/>');
			$(_this).addClass('hasArrow');
		}/*else if($(_this).attr('class')=='first subjSpan' && $(_this).next('ul').length <= 0){
			$(_this).addClass('nodrop');
		}*/else{
			$(_this).addClass('nodrop');
		}
	}

	loop = $(secondLevel);
	loopLen = loop.length;
	for (var i=0;i<loopLen;i++) {
		_this = loop[i];
		if ($(_this).next('ul').length > 0) {
			$(_this).wrap('<a class="closeElSecond" href="javascript:void(0);"></a>');
//			$(_this).prepend('<img src="'+ctx+'/faces/images/icon_subuncollapse.gif" class="subcollapsable_1"/>');
			$(_this).addClass('hasArrow');
		}/*else if($(_this).attr('class')=='second subjSpan' && $(_this).next('ul').length <= 0){
			$(_this).addClass('nodrop');
		}*/else{
			$(_this).addClass('nodrop');
		}
		
	}

	loop = $(thirdLevel);
	loopLen = loop.length;
	for (var i=0;i<loopLen;i++) {
		_this = loop[i];
		if ($(_this).next('ul').length > 0) {
			$(_this).wrap('<a class="closeElThird" href="javascript:void(0);"></a>');
//			$(_this).prepend('<img src="'+ctx+'/faces/images/icon_subuncollapse.gif" class="subcollapsable_1"/>');
			$(_this).addClass('hasArrow');
		}/*else if($(_this).attr('class')=='third subjSpan' && $(_this).next('ul').length <= 0){
			$(_this).addClass('nodrop');
		}*/else{
			$(_this).addClass('nodrop');
		}
	}
	var topLevelToggles = $('a.closeEl'), subLevelToggles = $('a.closeElFirst,a.closeElSecond,a.closeElThird');
	$(topLevelToggles).click(function() {toggleContent(this);});
	$(subLevelToggles).click(function() {toggleSubContent(this);});
};


function initMoon(){
	   if($.session("pLibrary_session") == "true" || $('#showAllMoon').html()=="true"){
			$('#bluP').css('display','inline');
		}
		else{
			$('#bluP').css('display','none');
		}	
		if($.session("pColl_session") == "true" || $('#showAllMoon').html()=="true"){
			$('#grnP').css('display','inline');
		}
		else{
				$('#grnP').css('display','none');
		}	
		if($.session("pCourse_session") == "true" || $('#showAllMoon').html()=="true"){
			$('#yelP').css('display','inline');
		}
		else{
				$('#yelP').css('display','none');
		}
		
		if ($.session("pPay_session") == "true" || $('#showAllMoon').html()=="true") {
		$('#redP').css('display', 'inline');
		} else {
			$('#redP').css('display', 'none');
		}

		if ($.session("oLibrary_session") == "true" || $('#showAllMoon').html()=="true") {
			$('#bluF').css('display', 'inline');
		} else {
			$('#bluF').css('display', 'none');
		}
		if($.session("oColl_session") == "true" || $('#showAllMoon').html()=="true"){
			$('#grnF').css('display','inline');
		}
		else{
				$('#grnF').css('display','none');
		}	
		if($.session("oCourse_session") == "true" || $('#showAllMoon').html()=="true"){
			$('#yelF').css('display','inline');
		}
		else{
			$('#yelF').css('display','none');
		}		
		
		if($.session("pLibrary_session")!="true" 
			&& $.session("pColl_session")!="true" 
				&& $.session("pCourse_session")!="true" 
				&& $.session("pPay_session")!="true" 
				&& $.session("pPay_session")!="true" 
				&& $.session("oLibrary_session")!="true" 
				&& $.session("oColl_session")!="true" 
				&& $.session("oCourse_session")!="true"){
			$('#bluP').css('display','inline');
			$('#grnP').css('display','inline');	
			$('#yelP').css('display','inline');
			$('#redP').css('display','inline');
			$('#bluF').css('display','inline');
			$('#grnF').css('display','inline');	
			$('#yelF').css('display','inline');	
			$.session("clearMoon_session","true");
		}
		
};


function clearMoon(){
	if("true"==$.session("clearMoon_session")){
		$('#bluP').css('display','none');
		$('#grnP').css('display','none');	
		$('#yelP').css('display','none');
		$('#redP').css('display','none');
		$('#bluF').css('display','none');
		$('#grnF').css('display','none');	
		$('#yelF').css('display','none');	
		$.session("clearMoon_session","false");
	}
};

function isAllUnchecked(){
	
//	alert(!$("#1").attr("checked")
//			   && !$("#2").attr("checked") 
//			   && !$("#3").attr("checked")
//			   && !$("#4").attr("checked") &&!$("#premiumId").attr("checked"));
//	alert(!$("#5").attr("checked") 
//			   && !$("#6").attr("checked")
//			   && !$("#7").attr("checked")
//			   && !$("#openId").attr("checked"));
	
	
//	alert("5"+$("#5").attr("checked"));
//	alert("6"+$("#5").attr("checked"));
//	alert("7"+$("#5").attr("checked"));
//	alert("open"+$("#openId").attr("checked"));
	
	if(!$("#1").attr("checked")
	   && !$("#2").attr("checked") 
	   && !$("#3").attr("checked")
	   && !$("#4").attr("checked")
	   && !$("#5").attr("checked")
	   && !$("#6").attr("checked")
	   && !$("#7").attr("checked")
//	||(!$("#1").attr("checked")
//	   && !$("#2").attr("checked") 
//	   && !$("#3").attr("checked")
//	   && !$("#4").attr("checked")
//	   && !$("#premiumId").attr("checked")
//	  )
//	||(!$("#5").attr("checked") 
//	   && !$("#6").attr("checked")
//	   && !$("#7").attr("checked")
//	   && !$("#openId").attr("checked")
//	  )  
	){
		
		$('#bluP').css('display','inline');
		$('#grnP').css('display','inline');	
		$('#yelP').css('display','inline');
		$('#redP').css('display','inline');
		$('#bluF').css('display','inline');
		$('#grnF').css('display','inline');	
		$('#yelF').css('display','inline');	
		
		$.session("pLibrary_session","true");
		$.session("pColl_session","true");
		$.session("pCourse_session","true");
		$.session("pPay_session","true");
		$.session("oLibrary_session","true");
		$.session("oColl_session","true");
		$.session("oCourse_session","true");
		
		$.session("clearMoon_session","true");
		
		
	}
	
	
	return false;
};

function showHideMoon(){
						$('#1').click(function(){
							
							   if(!$("#1").attr("checked")){
								   $('#bluP').css('display','none');
								   isAllUnchecked();
								}
								else{
									clearMoon();
									$('#bluP').css('display','inline');
									$.session("pLibrary_session","true");
								}
							});

						$('#2').click(function() {
							
							if(!$("#2").attr("checked")){
								$('#grnP').css('display','none');
								$.session("pColl_session","false");
								isAllUnchecked();
							}
							else{
								clearMoon();
								$('#grnP').css('display','inline');	
								$.session("pColl_session","true");
							}
							});

						$('#3').click(function() {
							
						if(!$("#3").attr("checked")){
							$('#yelP').css('display','none');
							$.session("pCourse_session","false");
							isAllUnchecked();
						}
						else{
							clearMoon();
							$('#yelP').css('display','inline');
							$.session("pCourse_session","true");
						}
						});

						$('#4').click(function() {
							
						if(!$("#4").attr("checked")){
							$('#redP').css('display','none');
							$.session("pPay_session","false");
							isAllUnchecked();
						}
						else{
							clearMoon();
							$('#redP').css('display','inline');
							$.session("pPay_session","true");
								
						}
						});

						$('#5').click(function() {
							
						if(!$("#5").attr("checked")){
							
							$('#bluF').css('display','none');
							$.session("oLibrary_session","false");
							isAllUnchecked();
						}
						else{
							clearMoon();
							$('#bluF').css('display','inline');
							$.session("oLibrary_session","true");
//							$("#5").attr("checked","checked");
						}
						
						
						
						});

						$('#6').click(function() {
							
						if(!$("#6").attr("checked")){
							
							$('#grnF').css('display','none');
							$.session("oColl_session","false");
							isAllUnchecked();
						}
						else{
							clearMoon();
							$('#grnF').css('display','inline');	
							$.session("oColl_session","true");
//							$("#6").attr("checked","checked");
						}
						});

						$('#7').click(function() {
							
						if(!$("#7").attr("checked")){
							$('#yelF').css('display','none');
							$.session("oCourse_session","false");
							isAllUnchecked();
						}
						else{
							clearMoon();
							$('#yelF').css('display','inline');	
							$.session("oCourse_session","true");
//							$("#7").attr("checked","checked");
						}
						});
						

							$('#premiumId').click(function() {
//								$.session("premium_session").val($('#premiumId').attr("checked"));
									if(!$("#premiumId").attr("checked")){
										$('#bluP').css('display','none');
										$('#grnP').css('display','none');
										$('#yelP').css('display','none');
										$('#redP').css('display','none');
										$("#1").removeAttr("checked");
										$("#2").removeAttr("checked");
										$("#3").removeAttr("checked");
										$("#4").removeAttr("checked");
										$.session("premium_session", "false");
										$.session("pLibrary_session","false");
										$.session("pColl_session","false");
										$.session("pCourse_session","false");
										$.session("pPay_session","false");
										
										isAllUnchecked();
									}else{
										clearMoon();
										$('#bluP').css('display','inline');
										$('#grnP').css('display','inline');
										$('#yelP').css('display','inline');
										$('#redP').css('display','inline');
										$.session("premium_session","true");
										$.session("pLibrary_session","true");
										$.session("pColl_session","true");
										$.session("pCourse_session","true");
										$.session("pPay_session","true");
									}								
								
								
						    });		
//							
							$('#openId').click(function() {
//								$.session("open_session").val($('#openId').attr("checked"));
									if(!$("#openId").attr("checked")){
										$('#bluF').css('display','none');
										$('#grnF').css('display','none');
										$('#yelF').css('display','none');
										$("#openId").removeAttr("checked");
										$("#5").removeAttr("checked");
										$("#6").removeAttr("checked");
										$("#7").removeAttr("checked");
										$.session("open_session","false");
										$.session("oLibrary_session","false");
										$.session("oColl_session","false");
										$.session("oCourse_session","false");
										
										isAllUnchecked();
									}else{
										clearMoon();
										$('#bluF').css('display','inline');
										$('#grnF').css('display','inline');
										$('#yelF').css('display','inline');
										$.session("open_session","true");
										$.session("oLibrary_session","true");
										$.session("oColl_session","true");
										$.session("oCourse_session","true");
										
									}
						    });	
							
							
							
						$('#search_contentId').prev().find('a').click(function() {
								
								if($('#search_contentId').css('display')=="none")
									$.session("showResource_session","block");
								else
									$.session("showResource_session","none");
						});	
						
							
						$('#premiumId').next('span').click(function() {
							
							if($('#1').parent('li').parent('ul').css('display')=="none")
								$.session("showPrem_session","block");
							else
								$.session("showPrem_session","none");
						});	
						$('#openId').next('span').click(function() {
							if($('#5').parent('li').parent('ul').css('display')=="none")
								$.session("showOpen_session","block");
							else
								$.session("showOpen_session","none");
						});
						
							
							
							
};

function resetSubReg(){
	$.session("passSub_sesssion","false");
	$.session("passReg_sesssion","false");
	$.session("isNewSearch","false");
	$.session("showResource_session","none");
	$.session("showPrem_session","none");
	$.session("showOpen_session","none");
	$.session("pLibrary_session" , "false");
	$.session("pColl_session" , "false");
	$.session("pCourse_session" , "false");
	$.session("pPay_session" , "false");
	$.session("oLibrary_session" , "false");
	$.session("oColl_session" , "false");
	$.session("oCourse_session" , "false");
	$.session("premium_session" , "false");
	$.session("open_session" , "false");
	$.session("check_session","false");
};

function putMoon(){
	var pemium_open			= $('#premium_open');
	var ulTop 				= pemium_open.find('ul.top,ul.top2');
	var tree2				= ulTop.find('li.tree');
	var secondOpenPremInput = tree2.find('input.second');
	var firstLevelInput  	= tree2.find('input.first' );
	var loop = null, loopLen = 0, _this = null;	
	var layout = theme;
	
	loop =$(secondOpenPremInput);
	loopLen = loop.length;
	
	for (var i=0;i<loopLen;i++) {
		_this = loop[i];
		switch($(_this).val()){
		   case  "1" : 	
			   			$(_this).attr('id','1');
			   			if(isIE7 && layout.indexOf('gray') == -1) {
			   				//$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cblue.png" style= "float:right; margin-right:-15px;"/>');
			   			
//			   			else if(isIE7 && layout.indexOf('gray') == -1){
//			   				$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cblue.png" style= "float:right; margin-right:-15px;"/>');
//			   				alert("else if");
//			   			}	
			   			}
			   			else if(isIE7 || (!isIE7 && layout.indexOf('gray') != -1) ) {
			   				//$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cblue.png" style= "float:right;"/>');
			   			}
			   			else {
			   				//$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cblue.png" style= "float:right; margin-right:-22px;"/>');
			   			}
			   			
			   			/* for default check subscribed */
			   		  
//			   			if($('#isSub').html()=="true" && $.session("passSub_sesssion")!="true"){
//			   				$('#1').attr('checked','checked');
//			   				$.session("pLibrary_session","true");
//			   				$.session("passSub_sesssion","true");
//							
////							$.session("showResource_session","block");
////							$.session("showPrem_session","block");
//			   				
//			   				$.session("showResource_session","none");
//							$.session("showPrem_session","none");
//							
//			   			}
			   			
			   			/* for default check subscribed */
			   			
			   			
			   			if($.session("passSub_sesssion")!="true"){
		   				$.session("passSub_sesssion","true");
						
						$.session("showResource_session","block");
						$.session("showPrem_session","block");
						$.session("showOpen_session","block");
						
		   			    }
			   			
			   			
			   			
			   			
			   			
						break;
						
			case "2": 	$(_this).attr('id','2');
//						if(isIE7)
//							$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cgrn.png" style= "float:right; margin-right:-15px;"/>');
//						else if(layout.indexOf('gray') != -1)
//			   				$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cgrn.png" style= "float:right;"/>');
//			   			else
//			   				$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cgrn.png" style= "float:right; margin-right:-22px;"/>');
						if(isIE7 && layout.indexOf('gray') == -1) {
			   				//$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cgrn.png" style= "float:right; margin-right:-15px;"/>');
						}
						else if(isIE7 || (!isIE7 && layout.indexOf('gray') != -1) ) {
			   				//$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cgrn.png" style= "float:right;"/>');
						}
			   			else {
			   				//$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cgrn.png" style= "float:right; margin-right:-22px;"/>');
			   			}
						
			  			break;
			  			
			case "3": 	$(_this).attr('id','3');
//						if(isIE7)
//							$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cyellow.png" style= "float:right; margin-right:-15px;"/>');
//						else if(layout.indexOf('gray') != -1)
//			   				$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cyellow.png" style= "float:right;"/>');
//			   			else
//			   				$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cyellow.png" style= "float:right; margin-right:-22px;"/>');
						if(isIE7 && layout.indexOf('gray') == -1) {
			   				//$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cyellow.png" style= "float:right; margin-right:-15px;"/>');
						}
						else if(isIE7 || (!isIE7 && layout.indexOf('gray') != -1) ) {
			   				//$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cyellow.png" style= "float:right;"/>');
						}
			   			else {
			   				//$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cyellow.png" style= "float:right; margin-right:-22px;"/>');
			   			}
						
			  			break;
			  			
			case "4": 	$(_this).attr('id','4');
//						if(isIE7)
//							$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cred.png" style= "float:right; margin-right:-15px;"/>');
//						else if(layout.indexOf('gray') != -1)
//			   				$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cred.png" style= "float:right;"/>');
//			   			else
//			   				$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cred.png" style= "float:right; margin-right:-22px;"/>');
						if(isIE7 && layout.indexOf('gray') == -1) {
			   				//$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cred.png" style= "float:right; margin-right:-15px;"/>');
						}
						else if(isIE7 || (!isIE7 && layout.indexOf('gray') != -1) ) {
			   				//$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cred.png" style= "float:right;"/>');
						}
			   			else {
			   				//$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cred.png" style= "float:right; margin-right:-22px;"/>');
			   			}
						
						break; 
			case "5":  	$(_this).attr('id','5');
//						if(isIE7)
//							$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cblue_f.png" style= "float:right; margin-right:-15px;"/>');
//						else if(layout.indexOf('gray') != -1)
//			   				$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cblue_f.png" style= "float:right;"/>');
//			   			else
//			   				$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cblue_f.png" style= "float:right; margin-right:-22px;"/>');
						
						if(isIE7 && layout.indexOf('gray') == -1) {
			   				//$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cblue_f.png" style= "float:right; margin-right:-15px;"/>');
						}
						else if(isIE7 || (!isIE7 && layout.indexOf('gray') != -1) ) {
			   				//$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cblue_f.png" style= "float:right;"/>');
						}
			   			else {
			   				//$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cblue_f.png" style= "float:right; margin-right:-22px;"/>');
			   			}
						/*for default check registered */	
//						if($('#isSub').html()!="true" && $.session("passReg_sesssion")!="true"){
//							$('#5').attr('checked','checked');
//							
//							
//							$.session("oLibrary_session","true");
//							$.session("passReg_sesssion","true");
//							$.session("showResource_session","block");
//							$.session("showOpen_session","block");
//							
//							$.session("showResource_session","none");
//							$.session("showOpen_session","none");
//						}
						/*for default check registered */
						
						
						if($.session("passSub_sesssion")!="true"){
			   				$.session("passSub_sesssion","true");
							
							$.session("showResource_session","block");
							$.session("showPrem_session","block");
							$.session("showOpen_session","block");
							
			   			}
						
						
						break;
						
			case "6": 	$(_this).attr('id','6');
//						if(isIE7)
//							$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cgrn_f.png" style= "float:right;margin-right:-15px; "/>');
//						else if(layout.indexOf('gray') != -1)
//			   				$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cgrn_f.png" style= "float:right;"/>');
//			   			else
//			   				$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cgrn_f.png" style= "float:right; margin-right:-22px;"/>');
						if(isIE7 && layout.indexOf('gray') == -1) {
			   				//$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cgrn_f.png" style= "float:right; margin-right:-15px;"/>');
						} 
						else if(isIE7 || (!isIE7 && layout.indexOf('gray') != -1) ) {
			   				//$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cgrn_f.png" style= "float:right;"/>');
						}
			   			else {
			   				//$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cgrn_f.png" style= "float:right; margin-right:-22px;"/>');
			   			}
						
						break;
						
			case "7": 	$(_this).attr('id','7');
//						if(isIE7)
//							$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cyellow_f.png" style= "float:right;margin-right:-15px;"/>');
//						else if(layout.indexOf('gray') != -1)
//			   				$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cyellow_f.png" style= "float:right;"/>');
//			   			else
//			   				$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cyellow_f.png" style= "float:right; margin-right:-22px;"/>');
						if(isIE7 && layout.indexOf('gray') == -1) {
			   				//$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cyellow_f.png" style= "float:right; margin-right:-15px;"/>');
						}
						else if(isIE7 || (!isIE7 && layout.indexOf('gray') != -1) ) {
			   				//$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cyellow_f.png" style= "float:right;"/>');
						}
			   			else {
			   				//$(_this).next('span').prepend('<img src="'+ctx+'/faces/images/cyellow_f.png" style= "float:right; margin-right:-22px;"/>');
			   			}
						
						break;  
		}		

	}	
	
	
	
	
	loop =$(firstLevelInput);
	loopLen = loop.length;
	
	for (var i=0;i<loopLen;i++) {
		_this = loop[i];
		switch($(_this).val()){
		 
		   case  "premium" : 	
			   			$(_this).attr('id','premiumId');
			   			
						break;
			case "open":
						$(_this).attr('id','openId');
						
			  			break;
		}		
	
	}	
	
	
};


function newSearch() {
	clearForm('#searchForm');
	setColoredTabs();
	var topLevelToggles = $('a.closeEl'), subLevelToggles = $('a.closeElFirst,a.closeElSecond,a.closeElThird');

	var loop = null, loopLen = 0, _this = null;
	
	loop = topLevelToggles;
	loopLen = loop.length;
	for (var i=0; i<loopLen; i++) {
		_this = loop[i];
		var targetContent = $(_this).parent().next('div');
		targetContent.css('display','none');
		$(_this).find('img.collapsable').each(function() {$(this).attr('src',ctx+'/faces/images/icon_uncol_blutrans.png');});
		
	}
	
	loop = subLevelToggles;
	loopLen = loop.length;
	for (var i=0; i<loopLen; i++) {
		_this = loop[i];
		var targetContent = $(_this).next('ul');
//		var targetContent =
		
		if(targetContent.attr('class')!='first show' && targetContent.attr('class')!='first open'){
			targetContent.css('display','none');
//			$(_this).find('img').each(function(){$(this).attr('src',ctx+'/faces/images/icon_subuncollapse.gif');});
			$(_this).find('span').each(function(){$(this).removeClass('drop');});
			$(_this).find('span').each(function(){$(this).addClass('hasArrow');});
			
//			$(e).find('span').removeClass('hasArrow');
//			$(e).find('span').addClass('drop');
			
		}
		
		
	}
	
	$('#extrafield3,#extrafield4,#extrafield5').css('display','none');
	if ($('#allDiv').css('display')!='none') {
		$.session('remove_addrow', '--');
		$('#search_aar').css('display','block');
		$('#addrowdiv').css('display','block');
		$("#advSearch").click();
	}
	
	$('#resourceCol').attr('src',ctx+'/faces/images/icon_col_blutrans.png');
	$('#search_contentId.resrcDiv').css('display','block');
	$('#search_multipleselect').css('display','block');
	//commented for fuzzy off by default
	//$('#fuzzyCheck').attr('checked','checked');
	return false;
};
function getTabColor(){
	var layout = theme;
	
	var tabbedhueFirstLevel  = '#82ae32';
	var tabbedhueSecondLevel = '#82ae32';
	var tabbedhueThirdLevel  = '#82ae32';
	
	if (layout.indexOf('green') != -1) {
		tabbedhueFirstLevel  = '#BE7A03';
		tabbedhueSecondLevel = '#BE7A03';
		tabbedhueThirdLevel  = '#BE7A03';
	}
	else if (layout.indexOf('gray') != -1){
		tabbedhueFirstLevel  = '#82ae32';
		tabbedhueSecondLevel = '#82ae32';
		tabbedhueThirdLevel  = '#82ae32';
	}
	else {
		tabbedhueFirstLevel  = '#82ae32';
		tabbedhueSecondLevel = '#6b9029';
		tabbedhueThirdLevel  = '#82ae32';
	}
	
	var tabbedhues = [];
	tabbedhues['tabbedhueFirstLevel']  = tabbedhueFirstLevel;
	tabbedhues['tabbedhueSecondLevel'] = tabbedhueSecondLevel;
	tabbedhues['tabbedhueThirdLevel']  = tabbedhueThirdLevel;
	
	return tabbedhues;
}

function setColoredTabs() {
	var tabbedhues = getTabColor();
	var tabbedhueFirstLevel  = tabbedhues['tabbedhueFirstLevel'];
	var tabbedhueSecondLevel = tabbedhues['tabbedhueSecondLevel'];
	var tabbedhueThirdLevel  = tabbedhues['tabbedhueThirdLevel'];
	var untabbedhue = 'black';
	var loop = null, loopLen = 0, _this = null;
	
	loop = $('ul.top, ul.top2');
	loopLen = loop.length;
	var zoneSubjCheck = 0;
	for (var i=0; i<loopLen; i++) {
		_this = loop[i];

		if ($(_this).find(':checked').length > 0) {
			$(_this).parent().parent().parent().parent().parent().find('a.closeEl').attr('style', 'color: '+tabbedhueFirstLevel+';');
		}
		else {
			$(_this).parent().parent().parent().parent().parent().find('a.closeEl').removeAttr('style');
		}
		
		if (($('#subject_search ul.top').find(':checked').length) > 0) {
			$('#subject_search').find('a.closeEl').attr('style', 'color: '+tabbedhueFirstLevel+';');
		}
		else{
			$('#subject_search').find('a.closeEl').removeAttr('style');
		}
		
		//set checked subject tabs(ugly)
		if (($('#stab1 ul.top').find(':checked').length - 1) > 0) {
			$('#s_stab1').find('span').attr('style', 'color: '+tabbedhueFirstLevel+';');
		}
		else{
			$('#s_stab1').find('span').removeAttr('style');
		}
		if (($('#stab2 ul.top').find(':checked').length - 1) > 0) {
			$('#s_stab2').find('span').attr('style', 'color: '+tabbedhueFirstLevel+';');
		}
		else{
			$('#s_stab2').find('span').removeAttr('style');
		}
		//end of set subject checked tabs(ugly)
		
		
		//for grade search
		if ( ($('.grade_search ul.top').find(':checked').length) > 0 ) {
			$('.grade_search').parent().parent().parent().parent().parent().find('a.closeEl').attr('style', 'color: '+tabbedhueFirstLevel+';');

			if (($('#age_filtered ul.top').find(':checked').length) > 0) {
				$('#age_filtered').css('display','block');	
				$('#age_all').css('display','none');	
			}
			else if (($('#age_all ul.top').find(':checked').length) > 0){
				$('#age_filtered').css('display','none');	
				$('#age_all').css('display','block');
			}

		}
		else{
			$('.grade_search').parent().parent().parent().parent().parent().find('a.closeEl').removeAttr('style');
		}

		$(_this).find('li.search_multipleselect_bordertop, li.tree').each(
			function() {
				if ($(this).find(':checked').length > 0) {
					$(this).find('span.first').attr('style', 'color: '+tabbedhueFirstLevel+';');
				}
				else {
					if (zoneSubjCheck != 1) {
						$(this).find('span.first').removeAttr('style');
					}
				}
			}
		);

		$(_this).find('li.lisecond').each(
			function() {
				if ($(this).find(':checked').length > 0) {
					$(this).find('span.second').attr('style', 'color: '+tabbedhueSecondLevel+';');
				}
				else {
					if (zoneSubjCheck != 1) {
						$(this).find('span.second').removeAttr('style');
					}
				}
			}
		);

		$(_this).find('li.lithird').each(
			function() {
				if ($(this).find(':checked').length > 0) {
					$(this).find('span.third').attr('style', 'color: '+tabbedhueThirdLevel+';');
				}
				else {
					if (zoneSubjCheck != 1) {
						$(this).find('span.third').removeAttr('style');
					}
				}
			}
		);
	}

	loop = $('#publisher_search ul.top, #publisher_search ul.top2');
	loopLen = loop.length;
	for (var i=0; i<loopLen; i++) {
		_this = loop[i];

		if (toEmptyString('ptab') == '') { /** default publisher tab opened */
			$.session('ptab:','ptab1');
		}
		if (toEmptyString('pid') == '') { /** default publisher tab opened */
			$.session('pid:','p0');
		}

		var ptab = $.session('ptab:')
		var pid  = $.session('pid:');

		var publishermaintab = $('#publisher_search');


		$('#'+ptab).parent().parent().find('li').each(
			function() {
				$(this).attr('id','notselected');
			}
		);
		
		$('#'+ptab).parent().removeAttr('id');

		if (publishermaintab.find(':checked').length > 0) {
			$('#'+ptab).find('span').attr('style', 'color: '+tabbedhueFirstLevel+';');
			publishermaintab.find('a.closeEl').attr('style', 'color: '+tabbedhueFirstLevel+';');
		}
		else {
			$('#'+ptab).find('span').removeAttr('style');
			publishermaintab.find('a.closeEl').removeAttr('style');
		}

		$('.pubtab').each(
			function() {
				$(this).attr('style','display: none;');
			}
		);

		$('#'+pid).attr('style','diplay: block;');			
	}

	loop = $('#type_search ul');
	loopLen = loop.length;
	for (var i=0; i<loopLen; i++) {
		_this = $(loop[i]);
		var _parent = _this.parents('#type_search');
		if (_parent.find(':checked').length > 0) {
			_parent.find('a.closeEl').attr('style', 'color: '+tabbedhueFirstLevel+';');
		}
		else {
			_parent.find('a.closeEl').removeAttr('style');
		}
	}

	loop = $('.type_search2 ul');
	loopLen = loop.length;
	for (var i=0; i<loopLen; i++) {
		_this = $(loop[i]);
		var _parent = _this.parents('.type_search2');
		if (_parent.find(':checked').length > 0) {
			_parent.find('a.closeEl').attr('style', 'color: '+tabbedhueFirstLevel+';');
		}
		else {
			_parent.find('a.closeEl').removeAttr('style');
		}
	}

	loop = $('#date_search');
	loopLen = loop.length;
	for (var i=0; i<loopLen; i++) {
		_this = loop[i];
		var tabbed = false;
		var fromYear = $('#fromYear').val();
		var fromDay  = $('#fromDay').val();
		var fromMonth = $('#dateFromSelect').val();
		var toYear   = $('#toYear').val();
		var toDay	 = $('#toDay').val();
		var toMonth = $('#dateToSelect').val();
	
		if (fromYear != 'Year' && fromYear != "") {tabbed = true;}
		if (fromMonth != "") {tabbed = true;}
		if (fromDay != 'Day' && fromDay != "") {tabbed = true;}
		if (toYear != 'Year' && toYear != "") {tabbed = true;}
		if (toMonth != ""){tabbed = true;}
		if (toDay != 'Day' && toDay != "") {tabbed = true;}
	
		if (tabbed) {
			$(_this).find('a.closeEl').attr('style', 'color: '+tabbedhueFirstLevel+';');
		}
		else {
			$(_this).find('a.closeEl').removeAttr('style');
		}
	}

	$('ul.top, ul.top2').bind('click',
		function() {
			if ($(this).find(':checked').length > 0) {
				$(this).parent().parent().parent().parent().parent().find('a.closeEl').attr('style', 'color: '+tabbedhueFirstLevel+';');
			}
			else {
				$(this).parent().parent().parent().parent().parent().find('a.closeEl').removeAttr('style');
			}
			
			
			if (($('#subject_search ul.top').find(':checked').length) > 0) {
				$('#subject_search').find('a.closeEl').attr('style', 'color: '+tabbedhueFirstLevel+';');
				
				var id  = $.session('searchSubjId:');
				$('#s_'+id).find('span').attr('style', 'color: '+tabbedhueFirstLevel+';');
			}else{
				$('#subject_search').find('a.closeEl').removeAttr('style');
				
				var id  = $.session('searchSubjId:');
				$('#s_'+id).find('span').removeAttr('style');
			}
			
			var id  = $.session('searchSubjId:');
			if (($('#'+id+' ul.top').find(':checked').length) > 0) {
				$('#s_'+id).find('span').attr('style', 'color: '+tabbedhueFirstLevel+';');
			}else{
				$('#s_'+id).find('span').removeAttr('style');
			}
			
			
			//for grade search
			if ( ($('.grade_search ul.top').find(':checked').length) > 0 ) {
				$('.grade_search').parent().parent().parent().parent().parent().find('a.closeEl').attr('style', 'color: '+tabbedhueFirstLevel+';');
			}else{
				$('.grade_search').parent().parent().parent().parent().parent().find('a.closeEl').removeAttr('style');
			}
	
			if (toEmptyString('tab') == '') { /** default publisher tab opened */
				$.session('tab:','tab1');
			}
			if (toEmptyString('id') == '') { /** default publisher tab opened */
				$.session('id:','t1');
			}
	
			var loop11 = null, loopLen11 = 0, _this11 = null;
			
			loop11 = $(this).find('li.search_multipleselect_bordertop, li.tree');
			loopLen11 = loop11.length;
			for (var i=0; i<loopLen11; i++) {
				_this11 = loop11[i];
				if ($(_this11).find(':checked').length > 0) {
					$(_this11).find('span.first').attr('style', 'color: '+tabbedhueFirstLevel+';');
				}
				else {
					$(_this11).find('span.first').removeAttr('style');
				}
			}
	
			loop11 = $(this).find('li.lisecond');
			loopLen11 = loop11.length;
			for (var i=0; i<loopLen11; i++) {
				_this11 = loop11[i];
				if ($(_this11).find(':checked').length > 0) {
					$(_this11).find('span.second').attr('style', 'color: '+tabbedhueSecondLevel+';');
				}
				else {
					$(_this11).find('span.second').removeAttr('style');
				}
			}
	
			loop11 = $(this).find('li.lithird');
			loopLen11 = loop11.length;
			for (var i=0; i<loopLen11; i++) {
				_this11 = loop11[i];
				if ($(_this11).find(':checked').length > 0) {
					$(_this11).find('span.third').attr('style', 'color: '+tabbedhueThirdLevel+';');
				}
				else {
					$(_this11).find('span.third').removeAttr('style');
				}
			}
		}
	);

	$('#publisher_search ul.top, #publisher_search ul.top2').bind('click', 
		function() {
			if (toEmptyString('ptab') == '') { /** default publisher tab opened */
				$.session('ptab:','ptab1');
			}
			if (toEmptyString('pid') == '') { /** default publisher tab opened */
				$.session('pid:','p0');
			}
	
			var ptab = $.session('ptab:')
			var pid  = $.session('pid:');
	
			var publishermaintab = $('#publisher_search');
			if (publishermaintab.find(':checked').length > 0) {
				$('#'+ptab).find('span').attr('style', 'color: '+tabbedhueFirstLevel+';');
				publishermaintab.find('a.closeEl').attr('style', 'color: '+tabbedhueFirstLevel+';');
			}
			else {
				$('#'+ptab).find('span').removeAttr('style');
				publishermaintab.find('a.closeEl').removeAttr('style');
			}
		}
	);

	$('#type_search ul').bind('click',
		function() {
			var _parent = $(this).parents('#type_search');
			if (_parent.find(':checked').length > 0) {
				_parent.find('a.closeEl').attr('style', 'color: '+tabbedhueFirstLevel+';');
			}
			else {
				_parent.find('a.closeEl').removeAttr('style');
			}
		}
	);
	
	$('.type_search2 ul').bind('click',
		function() {
			var _parent = $(this).parents('.type_search2');
			if (_parent.find(':checked').length > 0) {
				_parent.find('a.closeEl').attr('style', 'color: '+tabbedhueFirstLevel+';');
			}
			else {
				_parent.find('a.closeEl').removeAttr('style');
			}
		}
	);

	$('#date_search').find(':input').bind('change keyup',
		function() {
			var tabbed = false;
	
			var fromYear = $('#fromYear').val();
			var fromDay  = $('#fromDay').val();
			var fromMonth = $('#dateFromSelect').val();
			var toYear   = $('#toYear').val();
			var toDay	 = $('#toDay').val();
			var toMonth = $('#dateToSelect').val();
	
			if (fromYear != 'Year' && fromYear != "") {tabbed = true;}
			if (fromMonth != "") {tabbed = true;}
			if (fromDay != 'Day' && fromDay != "") {tabbed = true;}
			if (toYear != 'Year' && toYear != "") {tabbed = true;}
			if (toMonth != ""){tabbed = true;}
			if (toDay != 'Day' && toDay != "") {tabbed = true;}
	
			if (tabbed) {
				$('#date_search a.closeEl').attr('style', 'color: '+tabbedhueFirstLevel+';');
			}
			else {
				$('#date_search a.closeEl').removeAttr('style');
			}
		}
	);

	$('#price_search').find(':input').bind('change keyup',
		function() {
			var tabbed = false;
	
			var priceFrom = $('.priceFromSearch').val();
			var priceTo   = $('.priceToSearch').val();
	
			if (priceFrom != "" || priceTo != "") {tabbed = true;}
	
			if (tabbed) {
				$('#price_search a.closeEl').attr('style', 'color: '+tabbedhueFirstLevel+';');
			}
			else {
				$('#price_search a.closeEl').removeAttr('style');
			}
		}
	);
}
function setCheckedTree() {
	$('ul.top,ul.top2').find(':checkbox').click(
		function() {
			var $par = $(this).parent();
			var clazz = $(this).attr('class');
			
			if ($(this).attr('checked')){$par.find(':checkbox').attr('checked','checked');}
			else {$par.find(':checkbox').removeAttr('checked');}
	
			if (clazz == 'first') {}
			else if (clazz == 'second') {
				var sec_parent = $(this).parents('ul.first');
				var sibs = $(sec_parent).find('input.second').length;
				var chkd = $(sec_parent).find('input.second').filter(':checked').length;
	
				var first_parent = $(sec_parent).parent('li').find('input.first');
				if (sibs == chkd) { $(first_parent).attr('checked','checked'); }
				else { $(first_parent).removeAttr('checked'); }
			}
			else if (clazz == 'third') {
				var sec_parent = $(this).parents('ul.second');
				var sibs = $(sec_parent).find('input.third').length;
				var chkd = $(sec_parent).find('input.third').filter(':checked').length;
	
				var first_parent = $(sec_parent).parent('li').find('input.second');
				if (sibs == chkd) { $(first_parent).attr('checked','checked'); }
				else { $(first_parent).removeAttr('checked'); }
	
				var sec_parent = $(sec_parent).parents('ul.first');
				var sibs = $(sec_parent).find('input.second').length;
				var chkd = $(sec_parent).find('input.second').filter(':checked').length;
	
				var first_parent = $(sec_parent).parent('li').find('input.first');
				if (sibs == chkd) { $(first_parent).attr('checked','checked'); }
				else { $(first_parent).removeAttr('checked'); }
			}
		}
	);
};
function toggleContent(e) {

	var targetContent = $(e).parent().next('div');
	var targetId = $(targetContent).attr('id');
	if (targetId == null || targetId == '') {
		targetId = $(targetContent).parents('.main_tab').attr('id');
	}

	var togglify = '';

	if (targetContent.css('display') == 'none') {
		$(targetContent).animate({
			opacity: 1,
			height: 'toggle'
		}, 350, "swing");
		$(e).find('img.collapsable').each(function() {$(this).attr('src',ctx+'/faces/images/icon_col_blutrans.png');});
		
		
		togglify = persistSearchtoggle();
	}
	else if (targetContent.css('display') != 'none') {
		$(targetContent).animate({
			opacity: 0.6,
			height: 'toggle'
		}, 350, "swing");
		$(e).find('img.collapsable').each(function() {$(this).attr('src',ctx+'/faces/images/icon_uncol_blutrans.png');});
		togglify = $.session("toggled:");
		if (togglify == targetId+';') {
			togglify = '--';
		}
		else {
			togglify = togglify.replace(targetId+';','');
		}
	}
	$.session("toggled:",togglify);
	return false;
};
function toggleSubContent(e) {

	var targetContent = $(e).next('ul');
	var targetId = $(targetContent).attr('id');
	var togglify = ''; 

	if (targetContent.css('display') == 'none') {
		$(targetContent).animate({
			opacity: 1,
			height: 'toggle'
		}, 320, "swing");
		
		$(e).find('span').each(function(){
//			alert($(e).find('span').attr('class'));
			$(e).find('span').removeClass('hasArrow');
			$(e).find('span').addClass('drop');
		});
		
		
		
		togglify = persistSearchSubtoggle();
	}
	else if (targetContent.css('display') != 'none') {
		$(targetContent).animate({
			opacity: 0.6,
			height: 'toggle'
		}, 320, "swing");
		
		$(e).find('span').each(function(){
			$(this).removeClass('drop');
			$(this).addClass('hasArrow');
		});
		
		//togglify = $.session("toggledSub:");
		togglify = persistSearchSubtoggle();
		
		if (togglify == targetId+';') {
			togglify = '--';
		}
		else {
			togglify = togglify.replace(targetId+';','');
		}
	} 

	$.session("toggledSub:",togglify);

	return false;
};
function clearForm(ele) {
	$(ele).find(':input').each(
		function() {
			var inputId = $(this).attr('id');
			
			switch(this.type) {
				case 'password':
				case 'select-multiple':
				case 'text':
				case 'textarea':
					if("#"+inputId!="orgType" || "#"+inputId!="userType")
					$(this).val('');
					break;
				case 'select-one':
					if(inputId=="dateFromSelect" || inputId=="dateToSelect"){
						$("#dateFromSelect")[0].selectedIndex = 0;
						$("#dateToSelect")[0].selectedIndex = 0;
					}
					
					break;
					
				case 'checkbox':
				case 'radio':
					this.checked = false;
		        case 'hidden':
		        	break;
			}
			
			if (inputId == 'fuzzyCheck') { /** use id instead of type to make it code-safe ^___^ */
				var value=.60;
				$('#fuzzy').val(value);
				makeSlider();
			}
		}
	);
	
	if (ele == '#searchForm') {
		$.session('toggled:','--');
		$.session('toggledSub:','--');
		$.session('keyword:' ,'--');
		$.session('thirdField_session','--');
		$.session('fourthField_session','--');
		$.session('fifthField_session','--');
		$.session('select1_session','--');
		$.session('select2_session','--');
		$.session('select3_session','--');
		$.session('select4_session','--');
		$.session('select5_session','--');
		
		$.session("keyword_session","--");
		$.session("keywordwithin_session","--");
		$.session("keyword1_session","--");
		$.session("keyword2_session","--");
		$.session("keyword3_session","--");
		$.session("keyword4_session","--");
		$.session("keyword5_session","--");
		$.session("initFuzzy_session","--");
		
		$.session("passSub_sesssion","--");
		
		$.session('fromYear:',ifEmptyString('fromYear'));
		$.session('fromDay:' ,ifEmptyString('fromDay'));
		$.session('toYear:'  ,ifEmptyString('toYear'));
		$.session('toDay:'   ,ifEmptyString('toDay'));
		$.session('dateToSelect:',ifEmptyString('dateToSelect'));
		$.session('dateFromSelect:',ifEmptyString('dateFromSelect'));

		defaultValue($('#fromYear'),'Year');
		defaultValue($('#fromDay'),'Day');
		defaultValue($('#toYear'),'Year');
		defaultValue($('#toDay'),'Day');
//		defaultValue($('#dateFromSelect'),'Month');
//		defaultValue($('#dateToSelect'),'Month');
		
//		$("#dateFromSelect").val($("#dateFromSelect option:first").val());
//		$("#dateToSelect").val($("#dateToSelect option:first").val());
		
//		if(pName="Firefox" || pName="Chrome"){
//			defaultValue($('#dateToSelect'),'Month');
//			defaultValue($('#dateFromSelect'),'Month');
//			$('#dateFromSelect').val('Month');
//			$('#dateToSelect').val('Month');
//		}
	}
	else if (ele == '#date_search') {		
		$.session('keyword:' ,ifEmptyString('keyword'));
		$.session('fromYear:',ifEmptyString('fromYear'));
		$.session('fromDay:' ,ifEmptyString('fromDay'));
		$.session('toYear:'  ,ifEmptyString('toYear'));
		$.session('toDay:'   ,ifEmptyString('toDay'));
		$.session('dateToSelect:',ifEmptyString('dateToSelect'));
		$.session('dateFromSelect:',ifEmptyString('dateFromSelect'));
		
		defaultValue($('#fromYear'),'Year');
		defaultValue($('#fromDay'),'Day');
		defaultValue($('#toYear'),'Year');
		defaultValue($('#toDay'),'Day');
//		defaultValue($('#dateFromSelect'),'Month');
//		defaultValue($('#dateToSelect'),'Month');
		
		
//		$("#dateFromSelect").val($("#dateFromSelect option:first").val());
//		$("#dateToSelect").val($("#dateToSelect option:first").val());
//		if(pName="Firefox" || pName="Chrome"){
//			defaultValue($('#dateToSelect'),'Month');
//			defaultValue($('#dateFromSelect'),'Month');
//			$('#dateFromSelect').val('Month');
//			$('#dateToSelect').val('Month');
//		}
	}
	
	$("#hideWithin").css("display","none");
	$.session("hideWithinSession2","hide");
	$.session("hideWithinSession1","hide");
	
	
//	if($.session("check_session")!=null && $.session("check_session")=="false"){
//		$('#fuzzyCheck').attr('checked','checked');
//	}
	
	
	$.session("pLibrary_session" , "false");
	$.session("pColl_session" , "false");
	$.session("pCourse_session" , "false");
	$.session("pPay_session" , "false");
	$.session("oLibrary_session" , "false");
	$.session("oColl_session" , "false");
	$.session("oCourse_session" , "false");
	$.session("premium_session" , "false");
	$.session("open_session" , "false");
	
	
//	$("#1").removeAttr("checked");
//	$("#2").removeAttr("checked");
//	$("#3").removeAttr("checked");
//	$("#4").removeAttr("checked");
//	$("#5").removeAttr("checked");
//	$("#6").removeAttr("checked");
//	$("#7").removeAttr("checked");
//	$("#premiumId").removeAttr("checked");
//	$("#openId").removeAttr("checked");
	
	$('#selecteditem1').val('AND');
	$('#selecteditem2').val('AND');
	$('#selecteditem3').val('AND');
	$('#selecteditem4').val('AND');
	$('#selecteditem5').val('AND');
	$("#keyword").val(' ');
	$("#keyword0").val(' ');
	$("#keyword1").val(' ');
	$("#keyword2").val(' ');
	$("#keyword3").val(' ');
	$("#keyword4").val(' ');
	$("#keyword5").val(' ');
	$('#select').val('None');
	$.session("isNewSearch","true");
	
	$.session("showResource_session","none");
	$.session("showPrem_session","none");
	$.session("showOpen_session","none");
	
	
	
	/* uncomment for default resource type default checks */
//	$.session("showResource_session","none");
//	$.session("showPrem_session","none");
//	$.session("showOpen_session","none");
//	
//	
//	$('#openId').next('a').find('span').each(function(){
//		$(this).removeClass('drop');
//		$(this).addClass('hasArrow');
//	});
//	
//	$('#premiumId').next('a').find('span').each(function(){
//		$(this).removeClass('drop');
//		$(this).addClass('hasArrow');
//	});	
//	
//	if($('#isSub').html()=="true"){
//		$('#1').attr('checked','checked');
//		$.session("pLibrary_session","true");
//		$.session("showResource_session","none");
//		$.session("showPrem_session","none");
//	
//	}else if($('#isSub').html()!="true"){
//	$('#5').attr('checked','checked');
//	
//	$.session("oLibrary_session","true");
//	$.session("showResource_session","none");
//	$.session("showOpen_session","none");
//	}	
	
	/* uncomment for default resource type default checks */
	
	
	//commented for fuzzy off by default
//	reCheck();
	
	
};

function reCheck(){
	//commented for fuzzy off by default
//	if($("#orgType").html()=="5" && $("#userType").html()=="0"){
//		$("#fuzzyCheck").attr("checked","checked");
//		$.session("check_session","true");
//	}
//	else if ($("#orgType").html()!="5" && $("#userType").html()!="0"){
//		$("#fuzzyCheck").removeAttr("checked");
//		$.session("check_session","false");
//	}

};

function showWithin(){
		if($("#keyword").val()==null || $("#keyword").val()==""){
			$.session("hideWithinSession1", "hide"); 
			$.session("hideWithinSession2", "hide");
			$("#hideWithin").css("display","none");	
			
		}else if($("#keyword").val()!=null || $("#keyword").val()!=""){
			$.session("hideWithinSession1", "show"); 
			$.session("hideWithinSession2", "show");
			$("#hideWithin").css("display","block");
			
		}		

};
function selectAllCheckboxes(ele){
	
	var loop = $(ele).find(':input');
	var loopLen = loop.length;
	for (var i=0; i < loopLen; i++) {
		var _this = loop[i];
		switch(_this.type) {
			case 'checkbox':_this.checked = true;
		}
	}
	
	if (ele == '#age_filtered' || ele == '#age_all') {
		//Aug 3,2010 - bug fix in ages(grade) - Darrel Diaz
		$.session('search_ages1:'      ,multiInputSave('search_ages1'));
		$.session('search_ages2:'      ,multiInputSave('search_ages2'));
		$.session('search_ages3:'      ,multiInputSave('search_ages3'));
		$.session('search_ages4:'      ,multiInputSave('search_ages4'));
		//END - bug fix in ages(grade) - Darrel Diaz
	}
	
	if(ele == '#age_filtered' || ele == '#age_all'){
		$("#selectAllAge").val("true");
	}
//	if(ele == '#publisher_search'){
//		$("#selectAll").val("true");
//	}
};
function persistSearchtoggle() {
	var loop = null,loopLen = 0, _this = null;
	var toggle_cnt = 0;
	var hidden = '';

	toggle_cnt = 0;
	loop = $('form#searchForm .main_tab');
	loopLen = loop.length;
	for (var i=0; i<loopLen; i++) {
		_this = loop[i];
		toggle_cnt++;
		var id = 'tp:'+toggle_cnt;
		$(_this).attr('id',id);
		if ($(_this).find('.search_content:first').css('display') != 'none') {
			hidden += id +';';
		}
	}
	return hidden;
};
function persistSearchSubtoggle() {
	var loop = null,loopLen = 0, _this = null;
	var toggle_cnt = 0;
	var hidden = '';
	
	toggle_cnt = 0;
	loop = $('form#searchForm div.subject_search').find('ul.first');
	loopLen = loop.length;
	for (var i=0; i<loopLen; i++) {
		_this = loop[i];
		toggle_cnt++;
		if ($(_this).css('display') != 'none') {
			var id = 'sb1:'+toggle_cnt;
			$(_this).attr('id',id);
			hidden += id +';';
		}
	}

	toggle_cnt = 0;
	loop = $('form#searchForm div.subject_search').find('ul.second');
	loopLen = loop.length;
	for (var i=0; i<loopLen; i++) {
		_this = loop[i];
		toggle_cnt++;
		if ($(_this).css('display') != 'none') {
			var id = 'sb2:'+toggle_cnt;
			$(_this).attr('id',id);
			hidden += id +';';
		}
	}

	toggle_cnt = 0;
	loop = $('form#searchForm div.type_search').find('ul.first');
	loopLen = loop.length;
	for (var i=0; i<loopLen; i++) {
		_this = loop[i];
		toggle_cnt++;
		if ($(_this).css('display') != 'none') {
			var id = 'ty1:'+toggle_cnt;
			$(_this).attr('id',id);
			hidden += id +';';
		}
	}

	toggle_cnt = 0;
	loop = $('form#searchForm div.type_search').find('ul.second');
	loopLen = loop.length;
	for (var i=0; i<loopLen; i++) {
		_this = loop[i];
		toggle_cnt++;
		if ($(_this).css('display') != 'none') {
			var id = 'ty2:'+toggle_cnt;
			$(_this).attr('id',id);
			hidden += id +';';
		}
	}

	toggle_cnt = 0;
	loop = $('form#searchForm div.publisher_search').find('ul.first');
	loopLen = loop.length;
	for (var i=0; i<loopLen; i++) {
		_this = loop[i];
		toggle_cnt++;
		if ($(_this).css('display') != 'none') {
			var id = 'ps1:'+toggle_cnt;
			$(_this).attr('id',id);
			hidden += id +';';
		}
	}

	toggle_cnt = 0;
	loop = $('form#searchForm div.publisher_search').find('ul.second')
	loopLen = loop.length;
	for (var i=0; i<loopLen; i++) {
		_this = loop[i];
		toggle_cnt++;
		if ($(_this).css('display') != 'none') {
			var id = 'ps2:'+toggle_cnt;
			$(_this).attr('id',id);
			hidden += id +';';
		}
	}
	return hidden;
};
function setSearchtoggle() {

	var toggl = toEmptyString('toggled');
	var toggled = toggl.split(';');
	var tog_cnt = 0, _this = null;
	
	var togglr = $('form#searchForm .main_tab');
	var togglrLen = togglr.length;
	for (tog in toggled) {
		if (toggled[tog].lastIndexOf('tp:') == 0) {
			tog_cnt = toggled[tog].replace('tp:', '');
			if (tog_cnt != '' && tog_cnt > 0 && togglrLen > 0) {
				_this = togglr[tog_cnt-1];
				$(_this).attr('id','tp:'+tog_cnt);
				$(_this).css('display','block');
				$(_this).find('.search_content:first').css('display','block');
				$(_this).find('h4').find('a img').each(function(){$(this).attr('src',ctx+'/faces/images/icon_col_blutrans.png');});
			}
		}
	}
};
function setSearchSubtoggle() {

	var toggl = toEmptyString('toggledSub');
	var toggled = toggl.split(';');
	var tog_cnt = 0;
	var togglr = null,togglrLen = 0,_this = null;
	
	togglr = $('form#searchForm div#subject_search').find('ul.first');
	togglrLen = togglr.length;
	for (tog in toggled) {
		if (toggled[tog].lastIndexOf('sb1:') == 0) {
			tog_cnt = toggled[tog].replace('sb1:', '');
			if (tog_cnt != '' && tog_cnt > 0 && togglrLen > 0) {
				_this = togglr[tog_cnt-1];
				$(_this).css('display','block');
//				$(_this).prev('a').find('img').each(function(){$(this).attr('src',ctx+'/faces/images/icon_subcollapse.gif');});
				$(_this).prev('a').find('span').each(function(){
					$(this).removeClass('hasArrow');
					$(this).addClass('drop');
				});
			}
		}
		else if (toggled[tog].lastIndexOf('sb2:') == 0) {
			tog_cnt = 0;
			$('form#searchForm div#subject_search')
			.find('ul.second').each( function() {
				tog_cnt++;
				if (toggled[tog] == 'sb2:'+tog_cnt) {
					$(this).css('display','block');
//					$(this).prev('a').find('img').each(function(){$(this).attr('src',ctx+'/faces/images/icon_subcollapse.gif');});
					$(this).prev('a').find('span').each(function(){
						$(this).removeClass('hasArrow');
						$(this).addClass('drop');
					});
				}
			}
			);
		}
		else if (toggled[tog].lastIndexOf('ty1:') == 0) {
			tog_cnt = 0;
			$('form#searchForm div#type_search')
			.find('ul.first').each( function() {
				tog_cnt++;
				if (toggled[tog] == 'ty1:'+tog_cnt) {
					$(this).css('display','block');
//					$(this).prev('a').find('img').each(function(){$(this).attr('src',ctx+'/faces/images/icon_subcollapse.gif');});
					$(this).prev('a').find('span').each(function(){
						$(this).removeClass('hasArrow');
						$(this).addClass('drop');
					});
				}
			}
			);
		}
		else if (toggled[tog].lastIndexOf('ty2:') == 0) {
			tog_cnt = 0;
			$('form#searchForm div#type_search')
			.find('ul.second').each( function() {
				tog_cnt++;
				if (toggled[tog] == 'ty2:'+tog_cnt) {
					$(this).css('display','block');
//					$(this).prev('a').find('img').each(function(){$(this).attr('src',ctx+'/faces/images/icon_subcollapse.gif');});
					$(this).prev('a').find('span').each(function(){
						$(this).removeClass('hasArrow');
						$(this).addClass('drop');
					});
				}
			}
			);
		}
		else if (toggled[tog].lastIndexOf('ps1:') == 0) {
			tog_cnt = 0;
			$('form#searchForm div#publisher_search')
			.find('ul.first').each( function() {
				tog_cnt++;
				if (toggled[tog] == 'ps1:'+tog_cnt) {
					$(this).css('display','block');
//					$(this).prev('a').find('img').each(function(){$(this).attr('src',ctx+'/faces/images/icon_subcollapse.gif');});
					$(this).prev('a').find('span').each(function(){
						$(this).removeClass('hasArrow');
						$(this).addClass('drop');
					});
				}
			}
			);
		}
		else if (toggled[tog].lastIndexOf('ps2:') == 0) {
			tog_cnt = 0;
			$('form#searchForm div#publisher_search')
			.find('ul.second').each( function() {
				tog_cnt++;
				if (toggled[tog] == 'ps2:'+tog_cnt) {
					$(this).css('display','block');
//					$(this).prev('a').find('img').each(function(){$(this).attr('src',ctx+'/faces/images/icon_subcollapse.gif');});
					$(this).prev('a').find('span').each(function(){
						$(this).removeClass('hasArrow');
						$(this).addClass('drop');
					});
				}
			}
			);
		}
	}
};
function setInputElements() {

	$('form#searchForm input:text').keyup(
		function() {
			$.session('keyword:'  ,ifEmptyString('keyword'));
			$.session('keyword0:' ,ifEmptyString('keyword0'));
			$.session('keyword1:' ,ifEmptyString('keyword1'));
			$.session('keyword2:' ,ifEmptyString('keyword2'));
			$.session('keyword3:' ,ifEmptyString('keyword3'));
			$.session('keyword4:' ,ifEmptyString('keyword4'));
			$.session('keyword5:' ,ifEmptyString('keyword5'));
			$.session('fromYear:',ifEmptyString('fromYear'));
			$.session('fromDay:' ,ifEmptyString('fromDay'));
			$.session('dateFromSelect:',ifEmptyString('dateFromSelect'));
			$.session('toYear:'  ,ifEmptyString('toYear'));
			$.session('toDay:'   ,ifEmptyString('toDay'));
			$.session('dateToSelect:',ifEmptyString('dateToSelect'));
		}
	);

	//$.session('keyword:'  ,ifEmptyString('keyword'));
	//$.session('keyword0:' ,ifEmptyString('keyword0'));
	//$.session('keyword1:' ,ifEmptyString('keyword1'));
	//$.session('keyword2:' ,ifEmptyString('keyword2'));
	//$.session('keyword3:' ,ifEmptyString('keyword3'));
	//$.session('keyword4:' ,ifEmptyString('keyword4'));
	//$.session('keyword5:' ,ifEmptyString('keyword5'));
	
	$('form#searchForm select').change(
		function() {
			$.session('dateFromSelect:',ifEmptyString('dateFromSelect'));
			$.session('dateToSelect:',ifEmptyString('dateToSelect'));
		}
	);

	$('form[id != searchForm],form#searchForm a.buttonsGrnds,form#searchForm input.button').click(
		function() {
			$.session('search_ages1:'      ,multiInputSave('search_ages1'));
			$.session('search_ages2:'      ,multiInputSave('search_ages2'));
			$.session('search_ages3:'      ,multiInputSave('search_ages3'));
			$.session('search_ages4:'      ,multiInputSave('search_ages4'));
			$.session('search_subjects4:'  ,multiInputSave('search_subjects4'));
			$.session('search_subjects5:'  ,multiInputSave('search_subjects5'));
			$.session('search_subjects6:'  ,multiInputSave('search_subjects6'));
			$.session('search_subjects7:'  ,multiInputSave('search_subjects7'));
			$.session('search_types:'     ,multiInputSave('search_types'));
			$.session('search_types_premium:'  ,multiInputSave('search_types_premium'));
			$.session('search_types_open:'     ,multiInputSave('search_types_open'));
			$.session('search_deliveries:',multiInputSave('search_deliveries'));
			$.session('search_publishers:',multiInputSave('search_publishers'));
			$.session('search_publishers_by_resource_type:',multiInputSave('search_publishers_by_resource_type'));
			$.session('search_publishers_by_name:',multiInputSave('search_publishers_by_name'));
		}
	);
	
	$('form#searchForm input:checkbox').click(
		function() {
			$.session('search_ages1:'      ,multiInputSave('search_ages1'));
			$.session('search_ages2:'      ,multiInputSave('search_ages2'));
			$.session('search_ages3:'      ,multiInputSave('search_ages3'));
			$.session('search_ages4:'      ,multiInputSave('search_ages4'));
			$.session('search_subjects4:'  ,multiInputSave('search_subjects4'));
			$.session('search_subjects5:'  ,multiInputSave('search_subjects5'));
			$.session('search_subjects6:'  ,multiInputSave('search_subjects6'));
			$.session('search_subjects7:'  ,multiInputSave('search_subjects7'));
			$.session('search_types:'      ,multiInputSave('search_types'));
			$.session('search_types_premium:'   ,multiInputSave('search_types_premium'));
			$.session('search_types_open:'      ,multiInputSave('search_types_open'));
			$.session('search_deliveries:' ,multiInputSave('search_deliveries'));
			$.session('search_publishers:' ,multiInputSave('search_publishers'));
			$.session('search_publishers_by_resource_type:',multiInputSave('search_publishers_by_resource_type'));
			$.session('search_publishers_by_name:',multiInputSave('search_publishers_by_name'));
		}
	);
	
	$('#keyword').val( toEmptyString('keyword'));
	$('#keyword0').val( toEmptyString('keyword0'));
	$('#keyword1').val( toEmptyString('keyword1'));
	$('#keyword2').val( toEmptyString('keyword2'));
	$('#keyword3').val( toEmptyString('keyword3'));
	$('#keyword4').val( toEmptyString('keyword4'));
	$('#keyword5').val( toEmptyString('keyword5'));
	$('#fromYear').val(toEmptyString('fromYear'));
	$('#fromDay').val( toEmptyString('fromDay'));
	$('#dateFromSelect').val(toEmptyString('dateFromSelect'));
	$('#toYear').val( toEmptyString('toYear'));
	$('#toDay').val( toEmptyString('toDay'));
	$('#dateToSelect').val(toEmptyString('dateToSelect'));

	multiInputSet('search_ages1');
	multiInputSet('search_ages2');
	multiInputSet('search_ages3');
	multiInputSet('search_ages4');
	multiInputSet('search_subjects4');
	multiInputSet('search_subjects5');
	multiInputSet('search_subjects6');
	multiInputSet('search_subjects7');
	multiInputSet('search_types');
	multiInputSet('search_types_premium');
	multiInputSet('search_types_open');
	multiInputSet('search_deliveries');
	multiInputSet('search_publishers');
	multiInputSet('search_publishers_by_resource_type');
	multiInputSet('search_publishers_by_name');

	defaultValue($('#fromYear'),'Year');
	defaultValue($('#fromDay'),'Day');
	defaultValue($('#toYear'),'Year');
	defaultValue($('#toDay'),'Day');
};
function toEmptyString(id) {
	var str = $.session(id+':');
	if (str == null || str == '--') { str = ''; }
	return str;
};
function ifEmptyString(id) {
	var str = $('#'+id).val();
	if (str == '') { str = '--'; }
	return str;
};
function multiInputSave(id) {
	var str = '';
	var loop = $('input[name="'+id+'"]:checked');
	var loopLen = loop.length;
	for (var i=0; i < loopLen; i++) {
		var _this = loop[i];
		str += $(_this).val() + ';';
	}

	if (str == '') { str = '--'; }
	return str;
};
function multiInputSet(id) {
	var str = toEmptyString(id);
	$("[name='"+id+"']").removeAttr('checked');
	if (str != null && str != '') {
		var values = str.split(';');
		var valuesLen = values.length;

		for (var i=0; i<valuesLen; i++) {
			$("input[name='"+id+"'][value='"+values[i]+"']").attr('checked','checked');
		}
	}

};

function clearPublisherCheckboxes(name,id,tab) {
	//save tab id for tab retension
	$.session('ptab:',$(tab).attr('id'));
	if ($.session('pid:') == id) {
		return;
	} 
	$.session('pid:',id);

	//set not selected for current tab(css design)
	$(tab).parent().parent().find('li').each(function() {
		$(this).attr('id','notselected');
		$(this).find('a span').each(function() {
			$(this).removeAttr('style');
			$('#publisher_search').find('a.closeEl').removeAttr('style');
		}
		);
	}
	);

	
	//remove not selected on clicked tab
	$(tab).parent().removeAttr('id');
	
	
	//hide all tabs
	$('.pubtab').each(
		function() {
			$(this).attr('style','display: none;');
		}
	);

	
	//show clicked tab
	$('#'+id).fadeIn('slow');
	$('#'+id).parent().show('slow');

	
	//remove checked items and coloring on tab that is not selected
	$('input[name="'+name+'"]:checked').each(
		function() {
			$(this).removeAttr('checked');
		}
	);
	$('#'+id).find('span.first,span.second').each(
		function() {
			$(this).removeAttr('style');
		}
	);
};



function defaultValue(e,text){

	var cnt = 0;
	return $(e).each(function(){
		/** must be text-based formfields */
		if (this.type != 'text'     && 
				this.type != 'password' && 
				this.type != 'textarea') {
			return;
		}
		var fld_current = this;
		//Set value initially if none are specified

		/** remove values on focus */
		$(this).focus(function() {
			if (this.value == text || 
			    this.value == ''   || 
			    this.value == '0')
				this.value = '';
		    }
		);

		/** place values back on blur */
		$(this).blur(function() {
			if (this.value == text || 
				this.value == ''   || 
				this.value=='0')
				this.value = text;
		});

		//Capture parent form submission
		//Remove field values that are still default
		$(this).parents("form").each(function() {
			//Bind parent form submit
			$(this).submit(function() {
				if(fld_current.value==text) {
					fld_current.value='';
				}
			});
		});

		if (this.value == ''|| 
				this.value == '0') {
			this.value = text;
		} else { return; }

	});
};

function showSelection(id0,id1) {
	try {
		if($('#'+id1).css('display') != 'none'){
			$('#'+id1).fadeOut(5);
			$(id0).find('span').each(function() {$(this).html('Click to Expand');});
			$(id0).find('img').each(function() {$(this).attr('src',ctx+'/faces/images/icon_uncol_blutrans.png');});
		}
		if($('#'+id1).css('display') == 'none'){
			$('.checklist').find('table td label').attr('style','text-align: left;');
			
			$('#'+id1).fadeIn("slow");
			$(id0).find('span').each(function() {$(this).html('Click to Collapse');});
			$(id0).find('img').each(function() {$(this).attr('src',ctx+'/faces/images/icon_col_blutrans.png');});
		}
	}
	catch (e) {}
	return false;
};

function showHideDiv(id0){
	try {
		if($('#dropDiv').css('display')!='none'){
			$('#dropDiv').hide("slow");
			$(id0).find('img').each(function() {$(this).attr('src',ctx+'/faces/images/icon_down.gif');});
			$('#co-texthedId').css("border","none");
		}
		if($('#dropDiv').css('display')=='none'){
			$('#co-texthedId').css("border","1px solid #CCC");
			$('#co-texthedId').css("margin","5px");
			$('#co-texthedId').css("padding","10px");
			$('#dropDiv').show("slow");
			$(id0).find('img').each(function() {$(this).attr('src',ctx+'/faces/images/icon_up.png');});
		}
	}
	catch (e) {}
	return false;	
}

function showHideMoonDiv(id0){
	try {
		if($('#dropDivMoon').css('display')!='none'){
			$('#dropDivMoon').hide("slow");
			$('#iconUpImg').attr('src',ctx+'/faces/images/icon_down.gif');
			$('#co-texthedIdMoon').css("border","none");
			$.session("showDiv", "false");
		}
		if($('#dropDivMoon').css('display')=='none'){
			$('#co-texthedIdMoon').css("border","1px solid #CCC");
			$('#co-texthedIdMoon').css("margin","5px");
			$('#co-texthedIdMoon').css("padding","10px");
			$('#dropDivMoon').show("slow");
			$('#iconUpImg').attr('src',ctx+'/faces/images/icon_up.png');
			$.session("showDiv", "true");
		}
		
	}
	catch (e) {}
	return false;	
}

function setKeypressSearch(){
	
	$("form").keypress(
		function (e) {
		
			
			if(e.which == 13){
				e.preventDefault();
				var clickMeLink  = $(this).find('.defaultClickedWhenEntered a:first');
				var clickMeInput = $(this).find('.defaultClickedWhenEntered input:first'); 
				
				clickMeLink.click();
				clickMeInput.click();
				
				if($("#keyword").val!=null && $("#keyword").val!="#{param.keyword}" || $("#keyword").val!=""){
					$.session("keyword_session", $("#keyword").val());
				}
//				if($.session("keyword_session")!=null){
//					$("#keyword").val($.session("keyword_session"));
//				}
			}
		}
	);

	
	
	
};
function clickGo(){
	/*please do not change :) thank you*/
	var keyword = $("#keyword").val();
	if(keyword == ""){
		$.session("keyword_session","--");
	}else{
		$.session("keyword_session",$("#keyword").val());
		$.session("keyword0_session", $("#keyword0").val());
		$.session("keyword1_session", $("#keyword1").val());
		$.session("keyword2_session", $("#keyword2").val());
		$.session("keyword3_session", $("#keyword3").val());
		$.session("keyword4_session", $("#keyword4").val());
		$.session("keyword5_session", $("#keyword5").val());
	}
	/*please do not change :) thank you*/
	
};
function logIt(a,id) {
	$.post(ctx+'/faces/common/ajaxjun.jsf',
		{ action: a, assetId: id },
		function(data) {}
	);
};
function noTimeout() {
	alert('notimeout');
};
function popup(href, windowname) {
	window.open(href, windowname, 'width=1024, height=768, scrollbars=yes, resizable=yes');
};
/** end custom search functions... */

