/* function for opening popup window */

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);
}

function validateEmail(email)
{
// a very simple email validation checking. 
// you can add more complex email checking if it helps 
    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 removeLeadingAndTrailingChar (inputString, removeChar) 

{

	var returnString = inputString;

	if (removeChar.length)

	{

	  while(''+returnString.charAt(0)==removeChar)

		{

		  returnString=returnString.substring(1,returnString.length);

		}

		while(''+returnString.charAt(returnString.length-1)==removeChar)

	  {

	    returnString=returnString.substring(0,returnString.length-1);

	  }

	}

	return returnString;

}


function simplePreload()
{ 
  var args = simplePreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }

}


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

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

var box_flg = false;
$(document).ready(function() {
						   
	$("div#signin_menu").hide();
	
	$(".signin").click(function(e) {
		e.preventDefault();
		var offset = $(this).offset();
		var eleheight=	$(this).height();
		$('div#signin_menu').removeAttr("style");
		$('div#signin_menu').css( { "right": 265 + "px", "top":(offset.top+eleheight+5) + "px" } );
		if(box_flg == true)
		{ 	
		 $("div#signin_menu").html('').slideDown(10);
		 box_flg = false;
		 return false;
					
		}
		else{
			 $.ajax({url:'/ajax_mini_login.php',
					success: function(data){
					$('div#signin_menu').html(data).slideDown('fast');
					box_flg = true;
				   }
			 });
		 }
	});
	
	$(".signin2").click(function(e) {
		e.preventDefault();
		var offset = $(this).offset();
		var eleheight=	$(this).height();
		$('div#signin_menu').removeAttr("style");
		$('div#signin_menu').css( { "left": 10 + "px", "top":(offset.top+eleheight+5) + "px" } );
		if(box_flg == true)
		{ 	
		 $("div#signin_menu").html('').slideDown(10);
		 box_flg = false;
		 return false;
					
		}
		else{
			 $.ajax({url:'/ajax_mini_login.php',
					success: function(data){
					var diff=$('div#signin_menu').offset().top+$('html').offset().top;
					$('div#signin_menu').html(data).slideDown('fast');
					box_flg = true;
					if(diff>500)
					{
						$('html, body').animate({ 
						  scrollTop: $('div#signin_menu').offset().top-200
						}, 3000);
					}

				   }
			 });
		 }
	});
	$("div#signin_menu").mouseup(function() {
		return false
	});
	$(document).mouseup(function(e) {			
		if($(e.target).parent("a.signin").length==0) {
			$(".signin").removeClass("menu-open");
			$("div#signin_menu").hide();
			if(box_flg == true)
			{ 	
			 $("div#signin_menu").html('').slideDown(10);
			 box_flg = false;
			 return false;
			}
		}
		if($(e.target).parent("a.signin2").length==0) {
			$(".signin2").removeClass("menu-open");
			$("div#signin_menu").hide();
			if(box_flg == true)
			{ 	
			 $("div#signin_menu").html('').slideDown(10);
			 box_flg = false;
			 return false;
						
			}
		}
	});	
	
	//Hide all toggle container
	$("ul[class='left_toggle_container']").hide();
	
 	var isanimationcomplete = true;
	//Show container on mouseover of parent and set parent_toggle_flag to ture
	 $("li[class='left_toggle_parent']").mouseenter(function(){ 
			var selected_index=$(this).index();											  
			if(isanimationcomplete == true)
			{	$("li[class='left_toggle_parent']").stop(true,true);
				$("ul[class='left_toggle_container']").stop(true,true);
				$("ul[class='left_toggle_container']").each(function(index){
					if($(this).is(":visible"))
					{
							if(index!=selected_index)
							{
								$(this).slideUp("slow");
							}
					}
				});
				isanimationcomplete = false;
				$(this).find('.left_toggle_container').slideDown("slow",function(){
					isanimationcomplete = true;															 
				});
			}
	 });	
});

function ShowForgotPasswordBoxMini(id)
{
	
if(id)	
forgot = document.getElementById(id);
else
forgot = document.getElementById('forgotpass');

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


//////////////////////
function testimonial_showhide(id)
{
for(i=1;i<=document.getElementById('total_testimonial').value ;i++)
{
if(document.getElementById('link_'+i))
	{
		if(i == id)		
		{
			document.getElementById('full_'+i).style.display = '';
			document.getElementById('link_'+i).style.display = 'none';
			document.getElementById('short_'+i).style.display = 'none';			
		}	
		else		
		{
			document.getElementById('full_'+i).style.display = 'none';
			document.getElementById('link_'+i).style.display = '';
			document.getElementById('short_'+i).style.display = '';			
		}	
		
	}
}
}
// header all condition menu
/////////////////////////////////////////////////////////////////
// 	the following code block is for All condition right side menu
function load_menu_by_ajax()
{
		$.ajax({	
			beforeSend: function(){
				$("#ajax_menu").html("Loading....");
			},
			url: "ajax_header_menu.php",
			success: function(data) {
				$("#ajax_menu").html(data);
			}
	});
}
function menu_slide_up()
{
	TimerRunning = false;
	$("#push_page_div").slideUp("fast");	
	$("#ajax_menu").slideUp("fast");
	$('#dropmenuatag').removeClass('dropmenuactive');

}
var TimerRunning = false;

$(document).ready(function(){
	
	var timer ;
 	$("#ajax_menu").mouseleave(function(){
		 TimerRunning=true;
		timer=	setTimeout ( "menu_slide_up()", 50);
	}); 
	$("#cat_menu").mouseleave(function(){
		TimerRunning=true;
	 	timer = setTimeout ( "menu_slide_up()", 50);
		$("#ajax_menu").stop(true,true);
	}); 
	$("#ajax_menu").mouseenter(function(){
		clearTimeout(timer);
		TimerRunning=false;
	});
	$("#cat_menu").mouseenter(function(){ 
		
		//var myleft =  $("#TopMenu").offset().left;
		//$("#ajax_menu").css("left",myleft);	
		//$("#ajax_menu").offset({'left':myleft});
		if(TimerRunning == true)
		{
			clearTimeout(timer);
			TimerRunning=false;
		}
		else
		{
			$('#dropmenuatag').addClass('dropmenuactive');
			$("#ajax_menu").slideDown("slow");
			$("#push_page_div").slideDown("fast");	
		}
	});

	//tabs code start
	//Default Action
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li a:first").addClass("tabact").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.tabs li a").click(function() {
		$("ul.tabs li a").removeClass("tabact"); //Remove any "tabact" class
		$(this).addClass("tabact"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});
	
	//tabs code end
	if(document.getElementById('home_flag'))
	setTimeout("load_menu_by_ajax()",1000);
	
});
// 	End of code block 
//////////////////////

function ShowHideTreatments()
{
	if($('#cat_treatments').css('display')=='none')
	{
		$('#cat_treatments').css('display','');
	}
	else
	{
		$('#cat_treatments').css('display','none');
	}
}

