
SDN.Ecohub.runReport = function(reportName,url){
	if (url != null){
		window.open(url);
	}
	else if (reportName != null){
	 $j.ajax({
			   dataType:'text',
			   type: "GET",
			   success: function(msg){
	           window.location.href = "/irj/ecohub/go/prtrw/prtmode/ajax/prtroot/com.sap.sdn.ecohub.core." + reportName;
			},
			   error:function(xhr, status, err){
		 		alert("Error loading document!!! ");
		   } 
	 });
	}
}

SDN.Ecohub.hideDisclaimer = function(){
	$j('#disclaimer').dialog('destroy')
}

SDN.Ecohub.showDisclaimer = function(){
			$j('#disclaimer').dialog({dialogClass:'hub-disclaimer',bgiframe: true , modal: true,width:650,height:500,resizable:false,draggable:false, overlay: { opacity: 0.5, background: "black" } });
			$j(".hub-disclaimer .ui-dialog-titlebar-close").remove();
			$j('#disclaimer').css('display','block');
		}

SDN.Ecohub.acceptDisclaimer = function(uuid){
		var el = document.getElementById('SDN.Ecohub.AcceptCheck');
		if(el!=null&&el.checked){
		 $j.ajax({
			   dataType:'text',
			   type: "GET",
			   url: "/irj/ecohub/go/prtrw/prtmode/ajax/prtroot/com.sap.sdn.ecohub.core.DisclaimerComponent",
			   data:'rid='+uuid,
			   success: SDN.Ecohub.accepetedDisclaimer,
			   error:function(xhr, status, err){
			 		SDN.Ecohub.rejectDisclaimer();
				   } 
		   
			 });
		}else{
			$j("#disclaimermessage").html('You must check the box to confirm acceptance');
		}
		
}

SDN.Ecohub.accepetedDisclaimer = function(data,status){};
SDN.Ecohub.rejectDisclaimer = function(uuid){window.close()};


/*SponsoredSolutions*/
SDN.Ecohub.showSponsoredSolutions = function(uuid){
		var el = document.getElementById('sponsored_solutions_ajax');
		if(el!=null){
			 $j.ajax({
				   dataType:'text',
				   type: "GET",
				   url: "/irj/ecohub/go/prtrw/prtmode/ajax/prtroot/com.sap.sdn.ecohub.search.infocontrols.ui.SponsoredSolutionSearchComponent",
				   data:'rid='+uuid,
				   success: SDN.Ecohub.showSolutions,
				   error:function(xhr, status, err){
				 		$j("#sponsored_solutions_ajax").html("Error loading document");
					   } 
				 });
		}
}

SDN.Ecohub.showSolutions = function(data,status){$j("#sponsored_solutions_ajax").html(data); $j("#sponsored_solutions_ajax0").hide(); $j("#sponsored_solutions_ajax").show();};

/*MyviewedSolutions*/
SDN.Ecohub.showMyviewedSolutions = function(){
		var el = document.getElementById('viewed_solutions');
		if(el!=null){
			 $j.ajax({
				   dataType:'text',
				   type: "GET",
				   url: "/irj/ecohub/go/prtrw/prtmode/ajaxMyViewedSolutions/prtroot/com.sap.sdn.ecohub.myviewedsolutions.MyViewedSolutions",
				   success: SDN.Ecohub.showViewedSolutions,
				   error:function(xhr, status, err){
				 		$j("#viewed_solutions").html("Error loading document");
					   } 
				 });
		}
}

SDN.Ecohub.showViewedSolutions = function(data,status){$j("#viewed_solutions").html(data); $j("#viewed_solutions").show();};

/*MySearchHistory*/
SDN.Ecohub.showMySearchHistory = function(){
		var el = document.getElementById('search_history');
		if(el!=null){
			 $j.ajax({
				   dataType:'text',
				   type: "GET",
				   url: "/irj/ecohub/go/prtrw/prtmode/ajaxMySearchedSolutions/prtroot/com.sap.sdn.ecohub.myviewedsolutions.MyViewedSolutions",
				   success: SDN.Ecohub.showSearchHistory,
				   error:function(xhr, status, err){
				 		$j("#search_history").html("Error loading document");
					   } 
				 });
		}
}

SDN.Ecohub.showSearchHistory = function(data,status){$j("#search_history").html(data); $j("#search_history").show();};

SDN.Ecohub.toggleExpander = function(div_id, className){
		$j("#"+div_id).toggle();
		if($j("."+className).text()=="See More"){
			$j("."+className).text("See Less");
		}else{
			$j("."+className).text("See More");
		}
}

/*******************************************************************/
/* function to center an element vertically on the viewport
   www.learningjquery.com/2007/12/questions-and-answers-from-the-list 
*/	 

// dimensions of image
var largeImageWidth = 800;
var largeImageHeight = 600;

$j.fn.center = function(options) {
    var pos = {
    sTop : function() {
      return window.pageYOffset
      || document.documentElement && document.documentElement.scrollTop
      || document.body.scrollTop;
    },
    wHeight : function() {
      return window.innerHeight
      || document.documentElement && document.documentElement.clientHeight
      || document.body.clientHeight;
    }
    };
	
    return this.each(function(index) {
      if (index == 0) {
        var $this = $j(this);
		// image is positioned wrongly if height of viewport is smaller than height of image.
		// therefore we set default top to top of viewport 
		if (pos.wHeight() <= 600) { elTop = pos.sTop() + 10 }
		else { var elTop = pos.sTop() + (pos.wHeight() / 2) - (largeImageHeight / 2); }
        $this.css({
          position: 'absolute',
          marginTop: '0',
          top: elTop
        });
      }
    });
}


$j(document).ready(function()
{	
	// focus on the first text input field on the page
	$j("input[type='text']:first", document.forms[0]).focus();
		
	/************************************************************************************/
	
	// Simple Lightbox in JQuery
	/**
	 *
	 * Click on image opens lightbox.
	 * Click on opened image or press on a key (e.g. ESC) closes lightbox again.
	 * 
	 * needs JQuery Library, e.g. jquery-1.2.6.js
	 * 
	 * needs Images:
	 * close_lightbox.gif
	 *
	 * needs CSS:
	 * 		
	 * 		#overlayBackground { position: absolute; background-color: #000; top: 0; left: 0; z-index: 3; }
	 * 		#largeImage { position: absolute; width: 600px; top: 100px; z-index: 4; }
	 *		.lightbox { ... }
	 *
	 */	
	
	$j('.lightbox').click(function() {
	// create DIV for background 
	var background = $j('<div><div/>');
	// set opacity of background, e.g 0.5 = 50% 
	$j(background).attr('id', 'overlayBackground').css(
	 {
	  'width' : $j(document).width(),
	  'height' : $j(document).height(),
	  'opacity' : '0'
	 });
	 // show background
	 $j('body').append(background);
	 // oder 	 $j(background).appendTo('body');
	 $j(background).attr('id', 'overlayBackground').animate( {'opacity' : '.7' }, 500);
	  
	 // create container
	 var imageContainer = $j('<div></div>');
	 // create the close Button
	 var closeImage = $j('<div></div>').attr('class', 'closeImg');
	 // create the left Button
	 var goLeftImage = $j('<div></div>').attr('class', 'goLeftImg');
	 // create the right Button
	 var goRightImage = null;
	 var browser = navigator.appName;
		if (browser != null && browser == "Netscape"){
           goRightImage = $j('<div></div>').attr('class', 'goRightImgMoz');
		}
		else{
		   goRightImage = $j('<div></div>').attr('class', 'goRightImgIE');		
		}
	 // create the lightbox image 
	 var largeImage = $j('<img/>').attr('class', 'largeImg');
	 // source of lightbox image 
	 var largeImageSrc = $j(this).attr('href');
 
	 //create array with the sources of images
	 var hrefs = null;
	 if (largeImageSrc != null)
		 hrefs = largeImageSrc.split(";");
	 
	 // width of body   
	 var width = $j('body').width();
	 
	 // distance of image to left
	 var distLeft = (width/2) - (largeImageWidth/2);
	 
	 $j(imageContainer).attr('class', 'imgContainer');
	 // center vertically
	 $j(imageContainer).center();
	 // center horizontally
	 $j(imageContainer).css(
	  {
	   'left' : distLeft
	  });
	 
	 $j(largeImage).appendTo(imageContainer);
	 $j(closeImage).insertBefore(largeImage);
	 
	 // do this if there is more then one image
	 if (hrefs != null && (hrefs.length - 1) > 1){
		 var itemsNum = hrefs.length - 1;
		 var counter = 0;
		 
    	var textField = $j('<div>Image ' + (counter + 1) + ' out of ' + itemsNum + '</div>').attr('class', 'textBox');
        //set the first image 
		$j(largeImage).attr('src', hrefs[counter]);
		$j(goLeftImage).attr('title', 'Previous Image');
		$j(goRightImage).attr('title', 'Next Image');
	    $j(goLeftImage).insertAfter(largeImage);
	    $j(textField).insertAfter(largeImage);
	    $j(goRightImage).insertAfter(largeImage);
	    
	    // go to the next image
		$j(goRightImage).bind('click', function()
		{
		 counter++;
			if (counter == itemsNum)
				counter = 0;
			var text = "Image " + (counter + 1) + " out of " + itemsNum;
		    $j(textField).html(text); 			
			$j(largeImage).attr('src', hrefs[counter]);
    	});
	    // go to the previous image
		$j(goLeftImage).bind('click', function()
		{
			counter--;
			if (counter < 0)
				counter = itemsNum - 1;
			var text = "Image " + (counter + 1) + " out of " + itemsNum;
		    $j(textField).html(text); 
			$j(largeImage).attr('src', hrefs[counter]);
    	});
	 }
	 else{
	 $j(largeImage).attr('src', largeImageSrc);
	 }
	 
	//if window resized
  $j(window).resize(function(){
		$j(background).attr('id', 'overlayBackground').css(
					 {
					  'width' : $j(document).width(),
					  'height' : $j(document).height(),
					  'opacity' : '0'
					 });
			 // oder 	 $j(background).appendTo('body');
			 $j(background).attr('id', 'overlayBackground').animate( {'opacity' : '.7' }, 500);
			 // width of body   
			 width = $j('body').width();
			  // distance of image to left
			 distLeft = (width/2) - (largeImageWidth/2);
			 // center horizontally
			 $j(imageContainer).css(
			  {
			   'left' : distLeft
			  });
			}); 
	 // show lightbox image 					
	 $j('body').append(imageContainer);
	 $j(imageContainer).fadeIn(800, function()
	  {
	   // lightbox closes when clicking on ESC (keycode for ESC is 27)  
	   $j(document).keypress(function (e) {	
		 	if (e == null) { // ie
				keycode = event.keyCode;
			} else { // mozilla
				keycode = e.which;
			}
			if(keycode == 27){ // close
				$j(imageContainer).fadeOut(400);
				$j('#overlayBackground').fadeOut(400, function()
				{
					$j(this).remove();
				});
			}
		});
	   // lightbox closes when clicking on opened image  
	   $j(largeImage).bind('click', function()
		{
		 $j(imageContainer).fadeOut(400);
		 $j('#overlayBackground').fadeOut(400, function()
		  {
		   $j(this).remove();
		  });
		});
	    // lightbox closes when clicking on opened image
		$j(closeImage).bind('click', function()
		{
		 $j(imageContainer).fadeOut(400);
		 $j('#overlayBackground').fadeOut(400, function()
		  {
		   $j(this).remove();
		  });
		});
	   
	  }); 
	  return false; // we need this, otherwise the "href" is activated, not the lightbox
	});
	
	/************************************************************************************/	
	// PopDown-Slider in JQuery
	/**
	 *
	 * Click opens PopDown.
	 * 
	 * needs JQuery Library, e.g. jquery-1.2.6.js
	 *
	 * needs Images:
	 * arrow.gif, close.gif 
	 *
	 */
	 
	// First Visit? Then DropDown fades in (instead of sliding down)
	var first = true;
	
	var el_slider = $j('<div></div>').attr('class', 'slider');
		var el_slider_head = $j('<div></div>').attr('id', 'slider_head');
			 el_slider_head.attr('class', 'clearfix');
			var el_slider_head_divTitle = $j('<div>Solutions I visited before</div>').attr('id', 'solutionstitle');
			var el_slider_head_divClose = $j('<div></div').attr('id', 'close');
		var el_slider_content = $j('<div></div>').attr('id', 'slider_content');
	
	var solutions = $j('#solutionscarousel');
	 
	
	$j(el_slider_head_divTitle)
	.insertBefore(el_slider_head_divClose)
	.parent()
	.appendTo(el_slider_head)
	.parent()
	.appendTo(el_slider)
	.parent()
	.appendTo('#myviewedsolutions')
	.end();
	
	
	$j(solutions)
	.appendTo(el_slider_content)
	.parent()
	.insertAfter(el_slider_head);
	
	$j(solutions).css('display', 'inline');
	
	$j('.viewedsolutionslist').click(function(){	
		
		if (first == true) {
			$j(".slider").css('left', 'auto').animate({opacity: 1.0}, 500);
		}
		if (first == false){	 
			$j(".slider").slideToggle(400);
		}
		first = false;
		$j('.viewedsolutionslist').toggleClass("active");
	});
	
	$j('#close').click(function(){
		$j(".slider").slideToggle(400);
		$j('.viewedsolutionslist').toggleClass("active");
	});
	
	$j('.pricingclick').click(function(){
		$j('#solprofile > .tabwrapper ul').tabs('select',0);
	});
	
	$j('.certclick').click(function(){
		$j('#solprofile > .tabwrapper > ul').tabs('select',2);
	});
	
	$j('.tabwrapper > ul').tabs();
});


