// JavaScript Document
//łśćłżź
var DebugQueryMode=true; //Show Alerts
//var IE=false;

/* ================================================================================== */
/* =============================== jquery.ready [START] ============================= */
/* ================================================================================== */
/* =============================== .jAjax [START] =================================== */
// Important, required function getScrollXY;
var Global_jAjaxPerm=true;
function jAjax(){
	try{
		if(Global_jAjaxPerm==false){ self.setTimeout("jAjax('"+'test'+"')", 300); }
		elements=$JQ('.jAjax');
		
		var glob=0;
		for(i=0;i<elements.length;i++){
			c_href='';
			single=$JQ(elements).eq(i).find('.jAjax_link');
			//alert(single.length);
			if(single.length==1){ c_href=$JQ(single).eq(0).attr('href'); }
			if(c_href!='' && c_href !='#'){
				$JQ(elements).eq(i).attr('class','.jAjaxDone');
				
				$JQ(elements).eq(i).bind("ajaxSend", function(){
					Global_jAjaxPerm=false;
					$JQ(this).unbind('ajaxSend');
					$JQ(this).hide();
					
				}).bind("ajaxComplete", function(){
					$JQ(this).unbind('ajaxError');
					$JQ(this).unbind('ajaxComplete');
					$JQ(this).show(800, function(){ Global_jAjaxPerm=true; });					
					
				}).bind("ajaxError", function(){
					$JQ(this).unbind('ajaxError');
					$JQ(this).unbind('ajaxComplete');
					$JQ(this).html('<div class="loading"><img src="graph/shared/empty.gif" alt="" width="18" height="18" /></div>');
					$JQ(this).show(800, function(){ Global_jAjaxPerm=true; });
				});
				Global_jAjaxPerm=false;
				$JQ(elements).eq(i).load(c_href);
				self.setTimeout("jAjax('"+'test'+"')", 300);
				return false;
			}//if
			
		}//for
	}catch(err){ if(DebugQueryMode==true){ alert(' jAjax: '+err); }}
}


function jAjaxSliderSet(){
	try{
		var elements = $JQ('a');
		for(i=0;i<=elements.length;i++){
			if($JQ(elements).eq(i).attr('rev')=='jslider'){
				$JQ(elements).eq(i).click(function () {
					var new_href=$JQ(this).attr('href');
					if(new_href=='' || new_href=='#'){ return false; }
					//var new_href='https://myhealthangel01.worldsecuresystems.com/mini/help/programs_faq/my_weight.html';
					//cmsSlideShow(new_href);
					jAjaxSlider(new_href);
					return false;
				});
				
				$JQ(elements).eq(i).bind("ajaxError", function(){
					//$JQ(this).unbind('ajaxError');
					//$JQ(this).unbind('ajaxComplete');
					
					$JQ('#layer_slider').html('<a class="layer_slider_close" href="#"><img src="graph/shared/empty.gif" alt="" /></a><div class="loading_error" style="display:none">Unable to load page</div>');
					$JQ(".layer_slider_close").click(function () { 
						$JQ('#layer_main').remove();
						return false;
					});
					$JQ('#layer_slider .loading_error').show(100);
					
					//$JQ('#layer_opacity').animate({opacity:0}, 4000,"swing",function() {  });  
					//$JQ('#layer_slider').animate({opacity:0.9}, 2000,"linear",function() {  $JQ('#layer_main').remove(); });  
					return true;
				}).bind("ajaxComplete", function(){
					//$JQ(this).unbind('ajaxError');
					//$JQ(this).unbind('ajaxComplete');
					$JQ('#layer_slider .layer_slider_close').css('opacity',0);	
					$JQ('#layer_slider .layer_slider_close').animate({opacity:1}, 800,"swing");
					return false;
				});
				
				
			}
		}	
		
		
			
	}catch(err){ if(DebugQueryMode==true){ alert(' jAjaxSliderSet: '+err); }}
}

function jAjaxSlider(c_href){
	try{
		var elements=$JQ('#layer_main');
		if(elements.length>0){ return false; }
		$JQ('body').prepend('<div class="layer_main" id="layer_main"></div>');
		$JQ('#layer_main').append('<div class="layer_opacity" id="layer_opacity"></div>');
		$JQ('#layer_main').append('<div class="layer_slider" id="layer_slider" align="center"><a class="layer_slider_close" href="#"><img src="graph/shared/empty.gif" alt="" /></a></div>');
		
		$JQ('#layer_slider').append('<div class="layer_slider_ajax"><div class="jAjax"><a class="jAjax_link" href="'+c_href+'"></a></div></div>');
		
		$JQ('#layer_slider .layer_slider_close').css('opacity',0);
		$JQ('#layer_main').css('height', $JQ('body').attr('scrollHeight'));
		$JQ('#layer_opacity').css('height', $JQ('body').attr('scrollHeight'));
		
		var scrolls=getScrollXY();
		var c_top=scrolls[1]+150;
		$JQ('#layer_slider').animate({top:c_top}, 60, "linear");
		
		$JQ(".layer_opacity").click(function () { 
		  	$JQ('#layer_main').remove();
		  	return false;
		});
		
		$JQ(".layer_slider_close").click(function () { 
		  	$JQ('#layer_main').remove();
		  	return false;
		});
		
		$JQ('#layer_opacity').css('opacity',0);
		$JQ('#layer_main').show();
		jAjaxSliderPosition();
		$JQ('#layer_opacity').animate({opacity:0.6}, 1000,"swing",function() { jAjax();  });
		
		
		//$JQ('#layer_main').show(1000, );
		
		
		
	}catch(err){ if(DebugQueryMode==true){ alert(' jAjaxSlider: '+err); }}
}

function jAjaxSliderPosition(){
	try{
		var elements=$JQ('#layer_main');
		if(elements.length!=1){ return false; }
		
		c_bodywidth=parseInt($JQ('body').attr('offsetWidth'));
		if(c_bodywidth<1000){ c_bodywidth=1000; }
		
		$JQ('#layer_main').css('width',c_bodywidth);
		$JQ('#layer_opacity').css('width',c_bodywidth);
		
		if(parseInt($JQ('.layer_slider_ajax').attr('offsetHeight'))>=430){ 
			$JQ('.layer_slider_ajax').css('padding-right','18px');
		}
		
		var c_left=parseInt((c_bodywidth/2)- ($JQ('#layer_slider').attr('offsetWidth')/2 ));
		//var scrolls=getScrollXY();
		//var c_top=scrolls[1]+150;
		
		//$JQ('#layer_slider').css('left',c_left);
		//$JQ('#layer_slider').css('top',c_top);
		$JQ('#layer_slider').animate({left:c_left}, 60, "linear");
		//$JQ('#layer_slider').animate({top:c_top}, 60, "linear");
		self.setTimeout("jAjaxSliderPosition('"+'test'+"')", 400);
		
	}catch(err){ if(DebugQueryMode==true){ alert('jAjaxSliderPosition: '+err); }}
}
/* =============================== .jAjax [END] ===================================== */
/* =============================== .nForm [START] =================================== */
function jnFormRadioClick(This){
	try{
		ID=$JQ(This).attr('id');
		var unique_name='';
		for(i=0;i<glob_nFormRadio.length;i++){
			if(glob_nFormRadio[i].idgraph==ID){
				//$JQ('#'+glob_nFormRadio[i].idgraph).attr('class','nform_check2');
				//$JQ('#'+glob_nFormRadio[i].idradio).attr('checked','checked');
				unique_name=glob_nFormRadio[i].name;
				break;				
			}
		}
		if(unique_name==''){ return false; }
		for(i=0;i<glob_nFormRadio.length;i++){
			if(glob_nFormRadio[i].name==unique_name){
				$JQ('#'+glob_nFormRadio[i].idgraph).attr('class','nform_check1');
				if(glob_nFormRadio[i].idgraph==ID){
					$JQ('#'+glob_nFormRadio[i].idgraph).attr('class','nform_check2');
					$JQ('#'+glob_nFormRadio[i].idradio).attr('checked','checked');
					$JQ('#'+glob_nFormRadio[i].idradio).change(); /*Added*/
				}
			}
		}//for
	}catch(err){ if(DebugQueryMode==true){ alert('jnFormRadioClick: '+err); }}
}

var glob_nFormRadio=new Array();

function jnFormRadioSet(IDarray){
	try{
		if(!IDarray || IDarray.length==0){ return false; }
		var unique_name='';
		for(i=0;i<IDarray.length;i++){
			c_id=IDarray[i];
			if(c_id.slice(0,12)=='nform_radio_'){
				c_idradio=c_id.slice(12,c_id.length);
				//alert(glob_nFormRadio.length)
				if(unique_name==''){ 
					unique_name=c_id;
					if(glob_nFormRadio.length){
						for(k=0;k<glob_nFormRadio.length;k++){
							if(glob_nFormRadio[k].name==unique_name){ return false; }
						}
					}
				}
				var air={}
				air.name=unique_name;
				air.idgraph=c_id;
				air.idradio=c_idradio;
				c_count=glob_nFormRadio.length
				
				if($JQ('#'+air.idradio).attr('checked')==true){
					$JQ('#'+air.idgraph).attr('class','nform_check2'); //set at start
				}
				
				if(!c_count){ c_count=0; }
				glob_nFormRadio[c_count]=air;
				
				$JQ('#'+c_id).click(function () { 
				  	jnFormRadioClick(this);
				});
						
			}
		}//for
	}catch(err){ if(DebugQueryMode==true){ alert('jnFormRadioSet: '+err); }}
}
/* =============================== .nForm [END] ===================================== */
/*
function jAjaxClearboxCleaner(){
	try{
		var elements=$JQ('.jAjaxDone').find('a');
		for(i=0;i<elements.length;i++){
			c_rev=$JQ(elements).eq(i).attr('rev');
			if(c_rev.toLowerCase()=='clearbox'){
				$JQ(elements).eq(i).click(function () { return false; });
			}
		}
		
		setBlur();
		
	}catch(err){ if(DebugQueryMode==true){ alert('jAjaxClearboxCleaner: '+err); }}
}*/
/* ================================================================================== */
/* =============================== jquery.ready [END] =============================== */
/* ================================================================================== */
