$(document).ready(function() {
						   
// Tooltip jquery

	$('a[rel=tooltip]').mouseover(function(e) {
		var tip = $(this).attr('title');	
		$(this).attr('title','');
		$(this).append('<div id="tooltip"><div class="tipHeader"></div><div class="tipBody">' + tip + '</div><div class="tipFooter"></div></div>');		
		$('#tooltip').fadeIn('500');
		$('#tooltip').fadeTo('10',0.9);
		
	}).mousemove(function(e) {
		$('#tooltip').css('top', e.pageY + 10 );
		$('#tooltip').css('left', e.pageX + 20 );
		
	}).mouseout(function() {
		$(this).attr('title',$('.tipBody').html());
		$(this).children('div#tooltip').remove();
	});

	$('#nav').hover(
		function () {
			//show its submenu
			$('ul', this).slideDown(100);

		}, 
		function () {
			//hide its submenu
			$('ul', this).slideUp(100);			
		}
	);
	
	hs.lang = {
		creditsText : '',
		creditsTitle : ''
	},
	
	hs.graphicsDir = '/images/hs/';
	hs.align = "center";
	hs.dimmingOpacity = 0.50;
	hs.fadeInOut = true;
	hs.outlineType = 'rounded-white';
	hs.wrapperClassName = 'draggable-header';
});


function validateEmail(email)
{
    if(email.length <= 0)
	{
	  return true;
	}
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}

function ShowForgotPasswordBox()
{
forgot = document.getElementById('forgotpass');

if(forgot.style.display == 'none')
	forgot.style.display = 'block';
else
	forgot.style.display = 'none';
		
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function redirect_ip_popup()
{
	if(getCookie('IS_REDIRECT'))
	{
		if(getCookie('REDIRECT_URL') != "")
		{	
			location.href=getCookie('REDIRECT_URL');
		}
		return;
		
	}
}

function html_get_ip_country_popup(url,qstring,div)
{
	if (url.length==0)
	{
		return;
	}
	if(getCookie('IS_REDIRECT'))
	{
		if(getCookie('REDIRECT_URL') != "")
		{	
			location.href=getCookie('REDIRECT_URL');
		}
		return;
		
	}
	$.ajax({
		url: url,
		data:'',
		success: function(data) {
			if(data != 'false' && data != ''){
				hs.lang = {
					creditsText : '',
					creditsTitle : ''
				},
				hs.graphicsDir = 'images/hs/';
				hs.outlineType = 'rounded-white';
				hs.align = 'center';
				hs.wrapperClassName = 'draggable-header';
				hs.htmlExpand( document.getElementById('anchor'),{maincontentText:data,width:300});
			}
		}
	});

}


function RunActiveContent()
{
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="770" height="210" id="preview" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="slider/slider.swf" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="bgcolor" value="#FFFFFF" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<embed src="slider/slider.swf" quality="high" bgcolor="#FFFFFF" width="770" height="210" name="preview" align="middle" wmode="transparent" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

function htmlData(url,qstring,div)
{
	if (url.length==0)
	{
		document.getElementById(div).innerHTML="";
		return;
	}
	
	$.ajax({
		url: url,
		data:'',
		success: function(data) {
		document.getElementById(div).innerHTML=data;
		}
	});
	
}

function preloadImages()

{

  if(document.images)

  {

    if(!document.imageArray) document.imageArray = new Array();

    var i,j = document.imageArray.length, args = preloadImages.arguments;

    

    for(i=0; i<args.length; i++)

    {

      if (args[i].indexOf("#")!=0)

      {

        document.imageArray[j] = new Image;

        document.imageArray[j++].src = args[i];

      }

    }

  }

}
// header all condition menu
/////////////////////////////////////////////////////////////////
// 	the following code block is for All condition right side menu
var timerHandler;
var timerStatus = false;
var alcondmenu = function()
	{
		$('#the_menu').slideUp('slow');
		timerStatus = false;

	}
$(document).ready(function(){

 	
	$("#the_menu").mouseleave(function(){
		
		timerHandler =	setTimeout ('alcondmenu()', 500);
		timerStatus = true;
	});
	
	$("#cat_menu").mouseleave(function(){

		timerHandler =	setTimeout ('alcondmenu()', 500);
		timerStatus = true;
	});
 
	$("#the_menu").mouseenter(function(){
		
		if(timerStatus == true)
		{
			clearTimeout(timerHandler);
			timerStatus = false;
		}
	});

	$("#cat_menu").mouseenter(function(){
		
		if(timerStatus == true)
		{
			clearTimeout(timerHandler);
			timerStatus = false;
		}
		else
		{
			 var pTop = $(this).offset().top-60;
			 var pLeft = $(this).offset().left-215;
			 var pWidth = $(this).width();
			 
			 $("#the_menu").css('z-index','9999');	
			 $("#the_menu").slideDown('slow');
		}
		//$(this).hight		
		 /* $("#the_menu").css({
			  top: pTop,
			  left: pLeft
		  }).slideDown('slow');*/

	});
	///////////code for call me back ////////////////
	
	var submitioninporgress = 0;
	var qrystring = "";
	$("#submitionofcallmeback").click(function(event){
		event.stopPropagation()
		if(submitioninporgress == 0)
		{
			qrystring = "expected_date_to_call="+$("#expected_date_to_call").val()+"&start_time_to_call="+$("#start_time_to_call").val()+"&end_time_to_call="+$("#end_time_to_call").val()+"&existing_patient="+$("input[name=existing_patient]").val()+"&fname="+$.base64.encode($("#txt_fname").val())+"&lname="+$.base64.encode($("#txt_lname").val())+"&callmebackemail="+$.base64.encode($("#callmebackemail").val())+"&phone="+$.base64.encode($("#txt_phone").val())+"&existing_patient="+$("input[name=existing_patient]:checked").val();
			$.ajax({
				beforeSend: function(){
					$("#sp_submit_reqest").html("<img align='absmiddle' src='images/csrajaxloader.gif'/>");
					submitioninporgress = 1;
				},
				url: "submitcallmeback.php",
				data:qrystring,
				type:'POST',
				success: function(data) {
					resultarr=	data.split('|X|');
					
					$("#sp_submit_reqest").html("");
					submitioninporgress = 0;
					if(resultarr[0] == "success")
					{ // when success
						$(".main_border").slideUp("slow",function(){
								$(this).html(resultarr[1]);
								$(this).slideDown('fast');
						});//end of slideup
					}
					else if(resultarr[0] == "Fail")
					{//when Fail with error msg.
						$("#callmemsg").html(resultarr[1]).attr('class','showmsg');
					}
				}
			});// end of ajax
		}
	});// end of submit click.
	$(window).scroll(function () {
		var	pTop = $(window).scrollTop();
		$("#sticyRight").stop(true, true).animate({'top': pTop+135},600);
		$("#divcallmeContainer").stop(true, true).animate({'top': pTop+135},600);
	});
	$("#leftbarcallmepopup").click(function(event){
		event.stopPropagation();
		$("#sticyRight").trigger('click');
		
	});
	$("#sticyRight").click(function(event){
		event.stopPropagation();
		$("#divcallmeContainer").stop(true, true);
		if($("#divcallmeContainer").is(":visible"))
		{
			$("#divcallmeContainer").hide("slide", { direction: "right" }, 200);
		}
		else
		{
			$("#divcallmeContainer").show("slide", { direction: "right" }, 200);
			
		}	

	});//end of click
	setTimeout("presetcallmeback()",1000);
///////////End of Call me back/////////////////			
	
});
// 	End of code block 

function openpopup(url,popup_name,height,width,other_properties)
{
	var left		= parseInt((screen.width-350)/2);
	var top			= parseInt((screen.height-300)/2)	
	var win_options = 'height='+ height +',width='+ width +',resizable=yes,' 
	+ 'scrollbars=yes,left=' + left + ',top=' + top;

	window.open(url,popup_name,win_options);
}
//////////////////////
// 	End of code block 
function presetcallmeback()
{
	var firstnamecaption = "Votre prénom";
	var lastnamecaption = "Votre nom";
	var emailcaption ="Adresse email";
	var phonecaption = "Numéro de téléphone";

	if($("#txt_fname").val()=="")$("#txt_fname").val(firstnamecaption);
	if($("#txt_lname").val()=="")$("#txt_lname").val(lastnamecaption);
	if($("#callmebackemail").val()=="")$("#callmebackemail").val(emailcaption);
	if($("#txt_phone").val()=="")$("#txt_phone").val(phonecaption);
	
	$("#start_time_to_call").change(function(){
		$("#end_time_to_call").find("option[value="+$(this).val()+"]").attr('selected','selected');
	});
	$("#txt_fname").focus(function(){
		if($(this).val()==firstnamecaption)
		{
			$(this).val('');
		}
	});	
	$("#txt_fname").blur(function(){
		if($(this).val()=="")
		{
			$(this).val(firstnamecaption);
		}
	});
	$("#txt_lname").focus(function(){
		if($(this).val()==lastnamecaption)
		{
			$(this).val('');
		}
	});	
	$("#txt_lname").blur(function(){
		if($(this).val()=="")
		{
			$(this).val(lastnamecaption);
		}
	});
	
	$("#txt_phone").focus(function(){
		if($(this).val()==phonecaption)
		{
			$(this).val('');
		}
	});	
	$("#txt_phone").blur(function(){
		if($(this).val()=="")
		{
			$(this).val(phonecaption);
		}
	});
	$("#callmebackemail").focus(function(){
		if($(this).val()==emailcaption)
		{
			$(this).val('');
		}
	});	
	$("#callmebackemail").blur(function(){
		if($(this).val()=="")
		{
			$(this).val(emailcaption);
		}
	});
	$("input[name='existing_patient']").change(function(){
		setEmailVisibleHide();
	});
}// END of function presetcallmeback
function setEmailVisibleHide()
{
	if($("input[name='existing_patient']:checked").val() == 'Y')
	{
		if($('#callmebackemailrow').is(':visible'))
		{	
			//do nothing
		}
		else
		{
			$('#callmebackemailrow').show();
		}
	}
	else
	{
		if($('#callmebackemailrow').is(':visible'))
		{	
			$('#callmebackemailrow').hide();
		}
		
		
	}	
}
//////////////////////
