/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////
////		EMAIL FUNCTIONS
////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function HideLayer(d) {
 if(d.length < 1) { return; }
 document.getElementById(d).style.display = "none";
} // HideLayer

function ShowLayer(d) {
 if(d.length < 1) { return; }
 document.getElementById(d).style.display = "block";
} // ShowLayer

function ShrinkLayer(d) {
 if(d.length < 1) { return; }
 document.getElementById(d).style.width = "1";
} // ShrinkLayer

function toggleLayer(whichLayer) {
  var elem, vis;
  if(document.getElementById) // this is the way the standards work
    elem = document.getElementById(whichLayer);
  else if(document.all) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if(document.layers) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

function ToggleEmailPreview()
{ toggleLayer("EditEmail");
  toggleLayer("PreviewEmail");
}

function HideMenu()
{ HideLayer('nav');
  ShrinkLayer('leftTabNav');
  ShrinkLayer('leftNav');
}

function CopyEmailTextToPreview()
{ document.getElementById('EmailText1').innerHTML=FCKeditorAPI.GetInstance('EmailText').GetHTML();
}

function CopySubjectToPreview()
{ document.getElementById('Subject1').innerHTML=$('#Subject').val();
}

function CopyCCsToPreview()
{ var CC,i;
  var list = [];
  $('#CC :selected').each(function(i, selected){ list[i] = $(selected).text();});
  CC="";
  for(i=0;i<list.length;++i) {
   CC=CC+list[i]+"<br>&nbsp;&nbsp;&nbsp;";
  } // for
  document.getElementById('CC1').innerHTML=CC;
} 

function CopyTOsToPreview()
{ var TO,i;  
  var list = [];
  if($('#To').val()=="ALL") {
   document.getElementById('To1').innerHTML='Everyone';
   return;
  } // if
  if($('#To').val()=="GROUP") { 
   document.getElementById('To1').innerHTML=$('#Groupname :selected').text();
   return;
  } // if
  $('#To :selected').each(function(i, selected){ list[i] = $(selected).text();});
  TO="";
  for(i=0;i<list.length;++i) {
   TO=TO+list[i]+"<br>&nbsp;&nbsp;&nbsp;";
  } // for
  document.getElementById('To1').innerHTML=TO;
} 

function Preview()
{ CopyEmailTextToPreview();
  CopySubjectToPreview();
  CopyCCsToPreview();
  CopyTOsToPreview();
  ToggleEmailPreview();
}


    function fnValidator(oForm) {
     fnSelectAll(oForm.Members)
     return true;
    } // fnValidator

    function fnMenuSwap(fbox, tbox) {
     var arrFbox = new Array();
     var arrTbox = new Array();
     var arrLookup = new Array();
     var i;
     for(i=0; i<tbox.options.length; i++) {
      arrLookup[tbox.options[i].text] = tbox.options[i].value;
      arrTbox[i] = tbox.options[i].text;
     } // for
     var fLength = 0;
     var tLength = arrTbox.length
     for(i=0; i<fbox.options.length; i++) {
      arrLookup[fbox.options[i].text] = fbox.options[i].value;
      if(fbox.options[i].selected && fbox.options[i].value != "") {
       arrTbox[tLength] = fbox.options[i].text;
       tLength++;
      } else {
       arrFbox[fLength] = fbox.options[i].text;
       fLength++;
      }
     } // for
//     arrFbox.sort();
//     arrTbox.sort();
     fbox.length = 0;
     tbox.length = 0;
     var c;
     for(c=0; c<arrFbox.length; c++) {
      var no = new Option();
      no.value = arrLookup[arrFbox[c]];
      no.text = arrFbox[c];
      fbox[c] = no;
     } // for
     for(c=0; c<arrTbox.length; c++) {
      var no = new Option();
      no.value = arrLookup[arrTbox[c]];
      no.text = arrTbox[c];
      tbox[c] = no;
     } // for
    } //fnMenuSwap
 
    function fnSelectAll(box) {
     for(var i=0; i<box.length; i++) {
      box[i].selected = true;
     } // for
    } // fnSelectAll

    function fnDeleteGroup(oForm) {
     if (window.confirm('Are you sure you want to delete this group?')) {
      oForm.FormAction.value='DeleteGroup'; 
      return true;
     } else {
      return false;
     }
    } // fnDeleteGroup


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////
//// 	HEADER SLIDESHOW (requires Jquery)
////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function slideSwitch() {
    var $active = $('#headerSlideShowArea IMG.active');
//    if ( $active.length == 0 ) $active = $('#headerSlideShowArea IMG:last');
    var $next =  $active.next().length ? $active.next() : $('#headerSlideShowArea IMG:first');
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
     .addClass('active')
     .animate({opacity: 1.0}, 2500, function() {
       $active.removeClass('active last-active');
     });
}

   $(document).ready(function(){
    $(function() {
     setInterval( "slideSwitch()", 6200 );
    });
    $("#header li").hover(
     function() { $("ul", this).fadeIn(); },
     function() { $("ul", this).fadeOut("slow"); } 
    );
    });

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////
//// 	Xhale.Com FRONT PAGE VIDEOS (requires Jquery)
////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Xhale.com front page video 1


$(function() {
	
$f("a.player1", "/_SWF/flowplayer-3.1.5.swf", {
 plugins: { controls: { stop:true } },
 onBeforeClick: function() {
		$f().unload();
		$('#video2').hide();
		$('#video1text').hide();
		var wrap = $(this.getParent());
		wrap.find("img").fadeOut();
		$('#video1').css('background-color', '#0088aa');
		$('#video1').animate({width:405, height:300},500);
		wrap.animate({width:405, height:300}, 500, function() {
			$f(this).load();
		});	
		return false; 
	}, 
 
 onUnload: function() {
           $('#video1').css('background-color', '#efefef');
	   $('#video1').animate({width:368,height:150},500);
	   $(this.getParent()).animate({width:200, height:150}, 500, function()  {
   	    $(this).find("img").fadeIn();	
	    $('#video1text').show();
	    $('#video2').show();
	   });				
	}, 
	
 onFinish: function() {
	   this.unload();	
	   },
 onStop: function() {
	   this.unload();	
	   }
	
});
}); 

// Xhale.com front page video 2

$(function() {
	
$f("a.player2", "/_SWF/flowplayer-3.1.5.swf", {
 plugins: { controls: { stop:true } },
 onBeforeClick: function() {
		$f().unload();
		$('#video1').hide();
//		$('#video2text').hide();
		$('#video2text').html('');
		var wrap = $(this.getParent());
		wrap.find("img").fadeOut();
		$('#video2').css('background-color', '#0088aa');
		$('#video2').animate({width:405, height:300},500);
		wrap.animate({width:405, height:300}, 500, function() {
			$f(this).load();
		});	
		return false; 
	}, 
 
 onUnload: function() {
           $('#video2').css('background-color', '#efefef');
	   $('#video2').animate({width:368,height:150},500);
	   $(this.getParent()).animate({width:200, height:150}, 500, function()  {
   	    $(this).find("img").fadeIn();		
	   $('#video1').show();
//	   $('#video2text').show();
           $('#video2text').html('<center><font style="color:#0000CC; font-size:22px;"><b>SMART</b><font size=1><sup>&trade;</sup></font></font><br>Self Monitoring<br>and Reporting<br>Therapeutics');
	   });				
	}, 
	
 onFinish: function() {
	   this.unload();	
	   },
 onStop: function() {
	   this.unload();	
	   }
	
});
}); 

// HyGreen front page video


$(function() {
	
$f("a.player3", "/_SWF/flowplayer-3.1.5.swf", {
 plugins: { controls: { stop:true } },
 onBeforeClick: function() {
		$f().unload();
		$('#video3text').css('display','none');
		var wrap = $(this.getParent());
		wrap.find("img").fadeOut();
		$('#video3').css('background-color', '#949698');
		$('#video3').animate({width:405, height:300},500);
		wrap.animate({width:405, height:300}, 500, function() {
			$f(this).load();
		});	
		return false; 
	}, 
 
 onUnload: function() {
           $('#video3').css('background-color', '#efefef');
	   $('#video3').animate({width:368,height:150},500);
	   $(this.getParent()).animate({width:200, height:150}, 500, function()  {
   	    $(this).find("img").fadeIn();	
	    $('#video3text').css('display','block');		
	   });				
	}, 
	
 onFinish: function() {
	   this.unload();	
	   },
 onStop: function() {
	   this.unload();	
	   }
	
});
}); 
