var $j = jQuery.noConflict();
$j(document).ready(function() {	
						   
	/* GLOBAL BUTTON OVER STATES  */


    $j('#sli_search_1').keypress(function (e) {  
		if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) { 
		    // prevent all other .net default button to fire 
			e.preventDefault();
			
			// check the value and redirect
			if($j(this ).val() == '')
			{
				return false;
			}
			window.location = $j('#hfSearchUrl').val() + encodeURIComponent($j(this ).val());
		} 
	});

$j('#btnSearch').click(function () {
    if ($j('#sli_search_1').val() == '') {
        return false;
    }
    window.location = $j('#hfSearchUrl').val() + encodeURIComponent($j('#sli_search_1').val());
});  


$j('#btnjoinnow').click(function(){
    var url = "http://" +$j('#hfShop').val() + "/shop/Membership-and-Sales/Online-memberships.aspx";
   
    window.location= url;
    return false;
});

$j('#btnUnlimitedReports').click(function(){
    var url = "http://" +$j('#hfShop').val() + "/shop/Membership-and-Sales/Online-memberships.aspx";
   
    window.location= url;
    return false;
});

$j('.join_button').click(function() {
    var url = "http://" + $j('#hfShop').val() + "/shop/Membership-and-Sales/Online-memberships.aspx";

    window.location = url;
    return false;
});

$j('#btnbenefits').click(function(){
    window.location = "/About-Us/Welcome-to-CHOICE.aspx";
return false;
});
	
$j("button.btnDefault.OneColSpan, .btnRhsLogin, button.btnDefault.TwoColSpan, button.btnDefault.TwoHalfColSpan, button.btnDefault.ThreeColSpan, button.btnDefault.FourColSpan, button.btnDefault.FiveColSpan, button.btnbenefits, button.btnMember, button.btnTertiary, button.btnAdd, .e-newsletters .scfForm > div > input").hover(
 function() {
 $j(this).addClass("hoverState");
 },
 function() {
 $j(this).removeClass("hoverState");
 }
 ) 
	
	$j(".btnComments, .btnClear, .btnClose").hover(
		function() {
			$j(this).addClass("hoverState_01");
		},
		function() {
			$j(this).removeClass("hoverState_01");
		}
 	)
	
	$j(".RSS_item").hover(
		function() {
			$j(this).addClass("hoverState_02");
		},
		function() {
			$j(this).removeClass("hoverState_02");
		}
 	)
	
	$j(".subCategoryItem, .pollClosedItem").hover(
		function() {
			$j(this).addClass("hoverState_03");
		},
		function() {
			$j(this).removeClass("hoverState_03");
		}	
 	)
	
	try
    {
        var h3item = $j("div#mainArticleIntro h3.border").eq(0);
        var inner = h3item.html();
        if($j("div#mainArticleIntro img").eq(0).hasClass("articleImg")){
           inner = inner + unescape("%3Cbr/%3E%3Cbr/%3E");
           h3item.html(inner);
           h3item.attr("style","display:inline;line-height:35px;");
        }
    }
    catch(e){}
				
	/* FIRST MAIN NAVIGATION DROP DOWN  */
	
	$j("#mainNav li:first a").mouseover(
		function() {
			$j("#mainNavDropDownWrapper").show();		
		}	
	)
	//hide the pull down menu, when user hits another L1 nav option	
	$j("#mainNav li:gt(0)").mouseover(
		function() {
			$j("#mainNavDropDownWrapper").hide();		
		}	
	)
	
	$j("#mainNavDropDownWrapper").hover(
		function() {
			$j("#mainNav li:first").addClass("hover");		
		},function() {
			$j("#mainNav li:first").removeClass("hover");		
		}	
	)
	
	$j("#navCapture,#navCapture2").mouseover(
		function() {
			$j("#mainNavDropDownWrapper").hide();		
		}	
	)	
	
	/* Print Friendly */
	$j('#pageToolsPrint').click(function(){
	window.print();
	return false;
	});
	
	$j('#AZPaginationWrapper a.inactive').click(function(){
	    return false;
	});
						   
	/* POLLS */

	$j("#poll_vote").click(function () { 
		$j(this).hide();
		$j("#submit_00").show();
	});
	
	
	$j("button.btnTertiary").click(function () { 
		var id = $j(this).attr("id").replace("poll_vote","submit")
		$j(this).hide();
		$j("#"+id).show();
	});
	
	/* SELECT CATEGORY DROP DOWN */	
	$j("#selectCategory").click(
		function () { 
			$j("#selectCategoryDropDown").toggle();
			$j(this).toggleClass("active");
	});
	
	$j("#selectCategory").mouseout(
		function () { 
			$j("#selectCategoryDropDown").hide();
			$j(this).removeClass("active");
	});

	
	$j("#selectCategoryDropDownList li a").click(
		function () { 
			str = $j(this).html();
			id = $j(this).attr("id");
			$j("#selectCategory").html(str);
			$j("#selectCategoryDropDown").hide();
			if ($j("#article_detail").attr('id') == 'article_detail')
	        {
	            $j("#loading").show();
	            $j("#article_detail").load("Homepage-Latest-Reviews.aspx?Category=" + id.toString().toLowerCase(), function(){
                    $j("#loading").hide();
	            });	    
	        }	
        	
	        if ($j("#videoLibraryWrapper").attr('id') == 'videoLibraryWrapper')
	        {
	            $j("#loading").show();
	            $j("#videoLibraryWrapper").load("/Video-Library-Category-Views.aspx?Category=" + id.toString().toLowerCase(), function(){
                    $j("#loading").hide();
	            });
	        }
	});
	
	$j("#selectCategoryDropDown").mouseover(
		function () { 			
			$j(this).show();
			$j("#selectCategory").addClass("active");
	});
	
	$j("#selectCategoryDropDown").mouseout(
		function () { 							
			$j("#selectCategory").removeClass("active");
	});
	
	
	/* SIGN IN FORM */	
	$j("#signUp_submit").click(function () {
	
	     $j.ajax
        ({
            type: 'POST',
            url: url_path,
            data: 'SubmitReplyAbuse=1'  + '&commenttext=' + $j('#userReportAbuse_' + id).val() + '&replyid='  + $j('#hfreply_id_' + id).val(),
            success: function(data)
            {
                $j('#reportAbuseClicked_' + id).hide();
		        $j('#userReportAbuse_' + id).val('');
		        $j('#reportAbuseClickedThankyouMessage_' + id).show();
		        RefreshComments('',1,true,'blogCommentsWrapper');
		        button.removeAttr('disabled');
            }
        });
		$j("#signUpFields label").addClass("error");
		$j("p#errorMsg").show();
	});
	
	
	/* MAIN ARTICLE SIGN IN DROP DOWN */		
	$j("#myAccount").click(function () { 
		$j("#signInDropDown").toggle(); 
	});
	
	
	/* BOOKMARK SHARE DROP DOWN */	
	$j("#bookmarkShareWrapper_00 .bookmarkShare").click(function () { 
		$j("#bookmarkShareWrapper_00 .bookmarkShareDropDownOuterWrapper").show();		
	});
	$j("#bookmarkShareWrapper_01 .bookmarkShare").click(function () { 
		$j("#bookmarkShareWrapper_01 .bookmarkShareDropDownOuterWrapper").show();		
	});
	
	
	/* SUB CATEGORY LANDING PAGE ITEMS */	
	$j("#expand").click(function () { 
		showAllSubCats(); 
	});
	
	$j("#collapse").click(function () { 
		closeAllSubCats(); 
	});
	
	//Individual Open Close - Output for each accordion item
	$j("#subCategoryWrapper div.subCategoryItem").click(function () { 
	    var id = $j(this).attr("id");
	    id = id.replace("subCategoryItem","subCategoryArticleWrapper");
	    var objClose = $j(this).find("span.closeBtn");
	    var objOpen = $j(this).find("span.openBtn");
        if($j("#" + id).css('display')=='block') {			
		    $j(this).removeClass('closeItem');
		    objClose.hide();
		    objOpen.show();
	    }else{
		    $j(this).addClass('closeItem');
		    objClose.show();
		    objOpen.hide();
	    }
	    $j("#" + id).slideToggle();
	});	
	
	//Individual Open Close - Output for each accordion item
	$j("div.pollClosedItem").click(function () { 
	    var id = $j(this).attr("id");
	    id = id.replace("pollClosedItem","pollClosedItemDetailWrapper");
		if($j("#"+id).css('display')=='block') {			
			$j(this).removeClass('closeItem');
		} else {
			$j(this).addClass('closeItem');
		}
		$j("#"+id).slideToggle();
	});
						   
	//start the feature panel timer
	if ($j("#mainFeatureItem_02").attr("id") == "mainFeatureItem_02")
	{
	    timer = setTimeout("setHPFeaturePanel('next',true)","4000");
	}	
	
	hpPanelLength = $j('#mainFeature > div._feature').size();
	lifePanelLength = $j('#lifestyleItemWrapper > div._feature').size();
	CommentPanelLength = $j('#CommentItemWrapper > div._feature').size();
	
	$j('div[id^="replyClickedThankyouMessage"]').css("display","none");
	$j('div[id^="reportAbuseClickedThankyouMessage"]').css("display","none");
	$j('div[id^="newReplyWrapper"]').css("display","none");
	
	$j('#blogCommentsItemWrapper textarea[id^="userReply"]').css("width","334px");
	$j('#blogCommentsItemWrapper textarea[id^="userReportAbuse"]').css("width","334px");
	
	
	
	
	// *** tooltips					   
	$j('a[title]').not('#mainNav li a[title]').qtip({
		position: {
	     	 corner: {
	         	target: 'topMiddle',
	       	 	tooltip: 'bottomMiddle'
	     	 },
	     	 adjust: {
	     	 	screen: true
	     	 }
  	 	},
  	 	style: { 
	      "padding-top": 0,
	      "padding-bottom": 0,
	      "padding-left": 10,
	      "padding-right": 10,
	      background: '#d9dad4',
	      color: '#3d3a33',
	      textAlign: 'center',
	      border: {
	         width: 1,
	         radius: 3,
	         color: '#d9dad4'
	      },
	      tip: {
	      	corner: 'bottomMiddle',
	      	color: '#d9dad4',
	      	size: {
	      		x:15,
	      		y:8	      	
	      	}      	
	      },
	      name: 'light' // Inherit the rest of the attributes from the preset dark style
	    }  	 			
	});
	
	
	//Font sizing	
	prevFontSize = "";
	$j('#textSize a').click(function(){
            var ourText = $j('body');
            var currFontSize = ourText.css('fontSize');
            var finalNum = parseFloat(currFontSize, 12);
            var stringEnding = currFontSize.slice(-2); 
         	
			if (this.id == 'large') {				
				if (prevFontSize == "75" || prevFontSize == "") {
					finalNum = '0.81em';
				} else if (prevFontSize >= "81") {
					finalNum = '0.88em'; 				
				} 		
			} else { //small
				if (prevFontSize == "88") {
					finalNum = '0.81em';
				} else {
         		 	finalNum = '0.75em'; 
				}         
			}         
            prevFontSize = finalNum.slice(2,4); //set to work with ems
            prevFontSize = prevFontSize;
            //ourText.animate({fontSize: finalNum + stringEnding},500);
            ourText.css('fontSize', finalNum);
        });	
	
	
	
	//Filter items expand/contract
	$j('#filterWrapper .moreOptions').click(function(){
		$j(this).hide();
		$j(this).next('.lessOptions').hide();
		$j(this).next().css('display','block');
		$j(this).parent().find('ul.filterItems').find('.filterOptionFull').show();
	});
	
	$j('#filterWrapper .lessOptions').click(function(){
		$j(this).hide();
		$j(this).prev('.moreOptions').hide();
		$j(this).prev().css('display','block');
		$j(this).parent().find('ul.filterItems').find('.filterOptionFull').hide();
	});
	
	$j('#openAllFilters').click( function() {
		$j('#filterWrapper .filterHiddenRows').show();
		$j(this).hide();
		$j('#closeAllFilters').css('display','block');
		
		$j('li.filterOptionFull').show();
		
		$j('#filterWrapper .moreOptions').hide();
		$j('#filterWrapper .lessOptions').show();
		$j('#filterWrapper .lessOptions').css('display','block');
	});
	
	$j('#closeAllFilters').click( function() {
		$j('#filterWrapper .filterHiddenRows').hide();
		$j(this).hide();
		$j('#openAllFilters').css('display','block');
		
		$j('li.filterOptionFull').hide();
		$j('#filterWrapper .moreOptions').show();
		$j('#filterWrapper .lessOptions').hide();
		$j('#filterWrapper .moreOptions').css('display','block');
	});	
	
	$j('#deselectAllFilters').click( function() {
		$j('#filterWrapper .filterItems li a').removeClass('selected');
	});
	
	$j('ul.filterItems a').click( function() {
	    
	    if($j(this).hasClass('disabled'))
	    {
		    return false;
	    }
	    
		//get the UL that is the parent of the a clicked	
		var parentID = $j(this).parent().parent().get(0).id;	
		//evaluate the class of the clicked element, and set to active if neccessary or remove
		if ($j(this).hasClass("selected") == false) {
			$j("#" + parentID + " a").removeClass('selected');
			$j(this).addClass("selected");
		} else {
			$j("#" + parentID + " a").removeClass('selected');
		}		
	});
	
	//Comparison table checkboxes
	$j('#comparisonTbl input:checkbox').click( function() {
		var n = $j("#comparisonTbl input:checked").length;
		if (n > 5) {
			$j(this).attr('checked',false);
			$j('#comparisonTbl label[for="' + $j(this).attr("id") +'"] span').removeClass("highlighter");	
			//show alert to explain only 5 items can be selected at once
			$j('#comparisonTbl .tblInstructions p').addClass('error');
			
		} else {
			$j('#comparisonTbl label[for="' + $j(this).attr("id") +'"] span').toggleClass("highlighter");	
			//clear alert
			$j('#comparisonTbl .tblInstructions p').removeClass('error');		
		}		
	});
	
	//Header Sign In
		 $j("a.sign-in").hover(function(event){
				 clearTimeout(window.delayHide);
					 $j(this).addClass("open");
					 $j(this).next("div.sign-wrap").show(); 	   
				 },function(event){ 
				   var $a = $j(this);
				  window.delayHide =  setTimeout(function(){ 
		             $a.removeClass("open");
					 $a.next("div.sign-wrap").hide();
		         	}, 500);
				 });
	 $j("div.sign-wrap").hover(function(event){
				clearTimeout(window.delayHide);
				 $j(this).prev().addClass("open");
				 $j(this).show();     
			},function(event){
				  var $sign = $j(this);
				  window.delayHide =  setTimeout(function(){ 
				 $sign.prev().removeClass("open");
				 $sign.hide(); 	    
				  }, 500);
			}); 
	 $j("div.sign-wrap input").hover(function(){
				clearTimeout(window.delayHide);
				$j(this).parents("div.sign-wrap").show();
				$j(this).parents("a.sign-in").addClass("open"); 	    		
			      
		});
	 
	  
	  //Member-only content
	  $j("#mainArticleContents ul.article-list li a.hover, .mainPagination ul.tooltip li a").hover(function(){
        //if (window.delayHide) {
			clearTimeout(window.delayHide);
			$j(this).parent().children("span.tips").show();
			$j(this).parent().siblings().children("span.tips").hide();
		 //}
		 },function(){
	      var  $tips = $j(this).parent().children("span.tips")
	      window.delayHide =  setTimeout(function(){ 
		     $tips.hide();
		    }, 3000);
      });
	  
	  //E-newsletters form input value
	   $j(".e-newsletters INPUT:text").each(function(){
			$val = $j(this).parent().prev("label").text();
			$j(this).val($j.trim($val));
		})
		
		$j(".e-newsletters INPUT:text").focus(function(){
				$val = $j(this).parent().prev("label").text();
				if($j(this).val() == $j.trim($val))
					$j(this).val("");
					         
				}).blur(function(){
					 if ($j(this).val() == '') {
					$j(this).val($j.trim($val));
				 }
		});
		$j(".e-newsletters h1").replaceWith("<p class='title'>E-newsletters</p>");
		$j("#register h2").replaceWith("<p class='title'>Already a <br> subscriber?</p>");
		
		//Tabs Hide Dropdown
		$j(".tabs_NavWrapper ul.tabs li:gt(0) a").click(function(){
				$j(".selectCategory #selectCategoryWrapper").hide();	
		 })
		$j(".tabs_NavWrapper ul.tabs li:eq(0) a").click(function(){
				$j(".selectCategory #selectCategoryWrapper").show();	
		 })

		
});	



/* JAVASCRIPT FUNCTIONS  */

function clearForm() {
		$j('#comparisonTbl label span').removeClass("highlighter");
		$j('#comparisonTbl input:checkbox').attr("checked",false);
		$j('#comparisonTbl .tblInstructions p').removeClass('error');
	}

var theTimer;	
	
function fixBubbling(e,obj,y) {
	if (mouseReallyOut(e,obj,y)) {
		$j("#" + obj.id).hide();	
	}
}

//used to prevent the bubbling of events
function mouseReallyOut(e,obj,y) {     
	var result	=	false;     
	var recurse	=	y;     
	var parent	=	null;   
	           
	if (e.relatedTarget) {             
		result = (e.relatedTarget != obj);                          
		parent = e.relatedTarget.parentNode;                     
	} else {            
		result = (e.toElement != obj);                          
		parent = e.toElement.parentNode;       
	}   
	                     
	for( var x = 0; x < recurse; x++ ){                          
		if (parent != null){                 
			result = (result && parent  != obj);                 
			parent = parent.parentNode;         
		}        
	}                      
	return result; 
}
		
		
function closeAllSubCats() {
	$j(".accordion").hide();
	$j(".closeBtn").hide();	
	$j(".openBtn").show();		
	$j(".subCategoryItem").removeClass('closeItem');	
	$j(".subCategoryItem").addClass('openItem');
}

function showAllSubCats() {
	$j(".accordion").show();
	$j(".openBtn").hide();	
	$j(".closeBtn").show();		
	$j(".subCategoryItem").addClass('closeItem');
	$j(".subCategoryItem").removeClass('openItem');	
}

function showSelectedSubCat(x) {
	closeAllSubCats()
}     


currentIndexStart = 0;			

function setHPFeaturePanel(i,x) {				
					
	//hide all the panel elements
	$j('#mainFeature > div._feature').hide();
	//remove the active class from the carousel nav
	$j('a.numNavHPFeat').removeClass('active');				
				
	if (i == 'next') {
		currentIndexStart = currentIndexStart + 1;
		if (currentIndexStart >= hpPanelLength) {				
			currentIndexStart = 0;
		}							
	} else if (i == 'prev') {
		currentIndexStart = currentIndexStart - 1;
		if (currentIndexStart < 0) {				
			currentIndexStart = hpPanelLength - 1;
		}					
	} else {
		currentIndexStart = i;
	}

	//show the needed panel	& correct active state on the panel pagination
	$j('#mainFeature > div._feature:eq(' + currentIndexStart + ')').fadeIn('slow');
	$j('a.numNavHPFeat:eq(' + currentIndexStart + ')').addClass('active');

	//clear the timer and reintialise only if the user hasnt started to navigate themselves
	timer = clearTimeout(timer);	
	if (x == true) { 					
		timer = setTimeout("setHPFeaturePanel('next',true)","4000");								
	}					
}	

//array to store the life stage's labels'					
currentLifeIndexStart = 0;	

function setHPStagesPanel(i) {				
			
	//hide all the panel elements
	$j('#lifestyleItemWrapper > div._feature').hide();
	//remove the active class from the carousel nav
	$j('a.numNavLifeStage').removeClass('active');				
				
	if (i == 'next') {
		currentLifeIndexStart = currentLifeIndexStart + 1;					
		if (currentLifeIndexStart >= lifePanelLength) {				
			currentLifeIndexStart = 0;
		}							
	} else if (i == 'prev') {
		currentLifeIndexStart = currentLifeIndexStart - 1;
		if (currentLifeIndexStart < 0) {				
			currentLifeIndexStart = lifePanelLength - 1;
		}					
	} else {
		currentLifeIndexStart = i;
	}
	
	//display the correct title
	$j('#lifestyleHeader h3').hide();
    $j('#lifestyleHeader h3').html($j('#hidden' + currentLifeIndexStart).val()).fadeIn('slow');
			
	//show the needed panel	& correct active state on the panel pagination
	$j('#lifestyleItemWrapper > div._feature:eq(' + currentLifeIndexStart + ')').fadeIn('slow');
	$j('a.numNavLifeStage:eq(' + currentLifeIndexStart + ')').addClass('active');

}

		

function setPrimaryContentTabs(i) {
	//reset the tabs and hide all content
	$j('.tabs a').removeClass('active');	
	$j('._mainTabContent').hide();	
				
	//set the active elements
	$j('.tabs a:eq('+i+')').addClass('active');
	$j('._mainTabContent:eq('+i+')').show();				
}

function setArticleTabs(i) {
//	//reset the tabs and hide all content
//	$j('.tabs a').removeClass('active');	
//	$j('._mainTabContent').hide();	
//				
//	//set the active elements
//	$j('.tabs a:eq('+i+')').addClass('active');
//	$j('._mainTabContent:eq('+i+')').show();				
}

function setPollTabs(i) {
	//reset the tabs and hide all content
	$j('.tabs a').removeClass('active');	
	$j('._mainTabContent').hide();	
				
	//set the active elements
	$j('.tabs a:eq('+i+')').addClass('active');
	$j('._mainTabContent:eq('+i+')').show();				
}

function setBlogTabs(i) {
	//reset the tabs and hide all content
	$j('.blog_tabs a').removeClass('active');	
	$j('.blog_grid').hide();	
				
	//set the active elements
	$j('.blog_tabs a:eq('+i+')').addClass('active');
	$j('.blog_grid:eq('+i+')').show();
	
	scroller('mainIntroBlog', 1);
	
}

function setVideoTabs(i) {
    $j('.video_tabs a').removeClass('active');	
	$j('.video_grid').hide();	
				
	//set the active elements
	$j('.video_tabs a:eq('+i+')').addClass('active');
	$j('.video_grid:eq('+i+')').show();
}

function setChoiceVoiceContentTabs(i) {
	//reset the tabs and hide all content
	$j('#choiceVoiceTabsNav li').removeClass('active');	
	$j('#choiceVoiceTabsNav li').removeClass('noDivider');
	$j('#choiceVoiceTabsNav a').removeClass('active');	
	$j('._choiceVoiceContent').hide();	
	
	
	if (i == 0) { // youtube
		$j('#choiceVoiceTabsNav li:eq(0)').addClass('active');	
		$j('._choiceVoiceContent:eq('+i+')').show()
		$j('#choiceVoiceTabsNav li a:eq(0)').addClass('active');
		$j('#choiceVoiceTabsNav li:eq(2)').addClass('noDivider');
	
	} else if  (i == 1) { //twitter
		$j('._choiceVoiceContent:eq(1)').show()
		$j('#choiceVoiceTabsNav li a:eq(1)').addClass('active');
		$j('#choiceVoiceTabsNav li:eq(1)').addClass('active');
		$j('#choiceVoiceTabsNav li:eq(0)').addClass('noDivider');
		$j('#choiceVoiceTabsNav li:eq(2)').addClass('noDivider');
		
	} else if (i == 2) { //facebook
		$j('._choiceVoiceContent:eq(2)').show()	
		$j('#choiceVoiceTabsNav li a:eq(2)').addClass('active');
		$j('#choiceVoiceTabsNav li:eq(2)').addClass('active');
		$j('#choiceVoiceTabsNav li:eq(1)').addClass('noDivider');
	}
					
}


	/* Stars */
	var maxStars		=	5;
	var currentRatings	=	0;  // number of votes received
	var currentTotals	=	0;  // total ratings from all votes received 
	var currentStars	=	0;  // number of star to show for current article
	
	/* load full start to the specified number */
	function loadStars(starno){
		showStars(starno);
	}

	/* set full start to the specified number */
	function setStars(starno){
		currentRatings=++currentRatings;
	 	currentTotals=currentTotals+starno;
		currentStars=Math.floor(currentTotals/currentRatings);
		loadStars(currentStars);
	}

	function clearStars(){
		//set back the loaded stars momentarily
		timer=setTimeout("loadStars(currentStars)",500);
	}

	function showStars(starno){
		//clear any timer been set previously
		clearTimeout(timer);

		for(var fullStar=1;fullStar<=starno;fullStar++){
			$j("#star_"+fullStar).removeClass();
			$j("#star_"+fullStar).addClass("starFull");
		}

		for(var emptyStar=starno+1;emptyStar<=maxStars;emptyStar++){
			$j("#star_"+emptyStar).removeClass();
			$j("#star_"+emptyStar).addClass("starEmpty");
		}
	}	
	
	function popupWindow(url) {
		window.open(url,'_blank','height=700,width=500,status=no,toolbar=no,menubar=no,addressbar=no,scrollbars=no,location=no,resizable=no,directories=no');
	}
	
	function popupComparisonTable(url) {
		window.open(url+'?p=1','_blank','height=885,width=980,status=no,toolbar=no,menubar=no,scrollbars=yes,addressbar=no,location=no,resizable=yes,directories=no');
	}
	
	function popupWindowClose() {
		window.close();
	}
	
	function submitStars(i,spanId){
	    var xmlhttp;
        try{
            xmlhttp=new XMLHttpRequest();
        }catch(e){
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function(){
            if (xmlhttp.readyState==4){
                if (xmlhttp.status==200){
                    $j("div.qtip").hide();
                    $j("#"+spanId).html("");
                    for(var j=0;j<i;j++){
                        $j("#"+spanId).html($j("#"+spanId).html()+"<img src=\"/img/icon_rating_full.gif\" />");
                    }
                    for(var j=i;j<5;j++){
                        $j("#"+spanId).html($j("#"+spanId).html()+"<img src=\"/img/icon_rating_empty.gif\" />");
                    }
                    $j("#"+spanId).html($j("#"+spanId).html()+": Your rating");
                }
            }
        }
        xmlhttp.open("get","?rate="+i,true);
        xmlhttp.send(null);
	}

	function showPolls(pollDefault,pollResult){
   		$j("#"+pollDefault).hide();
        $j("#"+pollResult).show();                    
	}
	
    function showLandingPoll(){
   		$j("#pollDefault").hide();
        $j("#pollResults").show();                    
	}
	function submitPolls(scid,id){
        for(var i=0;i<$j("#pollForm_0"+id+" input[type='radio']").length;i++){
            var item;
            try
            {
                item = $j($j("#pollForm_0"+id+" input[type='radio']").get(i));
            }
            catch(err){
                item = $j($j("#pollForm_00 input[type='radio']").get(i));
            }
            
            if(item.attr("checked")){
                var opt = item.val();
                break;
            }
        }
        
  
        
        $j.ajax({
            "type": "post",
            "url": "/polls-list/poll-action.aspx",
            "data": "pid="+scid+"&oid="+opt,
            "success": function(msg){
                if(msg.indexOf("<form")>0)msg=msg.substring(0,msg.indexOf("<form")-1);
                var rateArr = msg.split("|");
                if(id=='0'){
                    var pollResult = "#pollResults";
                    var pollDefault = "#pollDefault";
                }else{
                    var pollResult = "#poll_item_results_0" + id;
                    var pollDefault = "#poll_item_0" + id;
                }

                try{for(var i=0;i<$j(pollResult + " td.pollImg").size();i++){
                    $j(pollResult + " td.pollImg").eq(i).attr("width",rateArr[i+1]+"%");
                    $j(pollResult + " td.pollance").eq(i).attr("width",(100-rateArr[i+1])+"%");
                }}catch(e){}
    
                for(i=0;i<$j(pollResult + " span").size();i++){
                    $j(pollResult + " span").eq(i).html(rateArr[i+1]+"%");
                }
	      		$j(pollDefault).hide();
	            $j(pollResult).show();                    
            }
        });
        return false;
	}

	window.onload = function(){
	var height = $j("#mainFeatureItem_01").height();	
	height = height > $j("#mainFeatureItem_02").height() ? height:$j("#mainFeatureItem_02").height();	
	height = height > $j("#mainFeatureItem_03").height() ? height:$j("#mainFeatureItem_03").height();	
	height = height > $j("#mainFeatureItem_04").height() ? height:$j("#mainFeatureItem_04").height();
	
    $j("#mainFeature").css("height",height + 20);
    $j("#mainFeature").css("min-height",height + 20);
    
    }
    
//    var blogHeight = 0;
//    $(".blog_grid").each(function(index)
//    {
//        blogHeight = blogHeight > $(".blog_grid:eq("+ index +")").height() ? blogHeight : $(".blog_grid:eq("+ index +")").height();        
//    })
//    
//    $(".blog_grid").css("height",blogHeight);
//    
//    }
