var _ajax_cache = {};
 

function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	 return pattern.test(emailAddress);
	};


$(document).ready(function() {
	$('#slideshowHolder').jqFancyTransitions({ width: 672, height: 250 });
	 
	$('.search-btn').click(function(event){
		var val = $('.search-input').val();
		if(val=='Search Medications')
		{
		   event.preventDefault();
		}
	});
	
	$("#showlist_main").jcarousel({
		auto: 8 // delay - seconds
//		,initCallback: mycarousel_initCallback
		,wrap: "circular"
			,animation : 1500
				,rtl: false
				
				,easing: "easeInOutQuad"
                                ,scroll:1 // items per scroll
	});
	
	$("#mycarousel").jcarousel({
		auto: 5 // delay - seconds
//		,initCallback: mycarousel_initCallback
		,wrap: "circular"
			,animation : 1500
			,rtl: false
			,buttonNextHTML: '<div class="new_gal_prev_btn"></div>',
	        buttonPrevHTML: '<div class="new_gal_next_btn"></div>'
			,easing: "easeInOutQuad"
				,scroll:4 // items per scroll
	});
	
	
	$('#see-more-open').click(function(event){
		event.preventDefault();
		$('#see-more-cats').toggle('slow');
	});
	
	
	
	$('#nextmovie').click(function(event){
		
		event.preventDefault();
		$("#showlist_main").data('jcarousel').next();
	});
	$('#prevmovie').click(function(event){
		
		event.preventDefault();
		$("#showlist_main").data('jcarousel').prev();
	});
	$('#pausemovie').click(function(event){
		
		event.preventDefault();
		var j = $("#showlist_main").data('jcarousel');
		if (j.autoStopped == true)
		{
			j.autoStopped = false;
			j.startAuto();
			$(this).removeClass('playmovie');
//			$(this).html('Pause me');
			
		}
		else
		{
			j.autoStopped = true;
			$(this).addClass('playmovie');
//			$(this).html('Play Again');
			
		}
	});
	
	$('#remove_node a').click(function(event){

        event.preventDefault();
        $(this).parent().remove();
        $('#remove_node').submit();


});
	$('.see_more').click(function(event){
		
		
		event.preventDefault();
		
		
	});
	
	
	var parent = $('.selected').parent().attr('class');
	 
	
	if(parent=='more')
	{
		$('.selected').parent().parent().parent().remove();
	}
	
	else
	{
	$('.selected').parent().remove();
	}
	
	
	
	
	$('#articles-tab-show').hide();
	$('#articles-tab').click(function(event){
		event.preventDefault();
		$('#articles-tab-show').show();
		$('#products-tab-show').hide();
		$('#articles-tab').parent().removeClass();
		$('#articles-tab').parent().addClass('selected-tab');
		$('#products-tab').parent().removeClass();
		$('#products-tab').parent().addClass('unselected-tab-left');
		
	});
	
	$('#products-tab').click(function(event){
		event.preventDefault();
		$('#products-tab-show').show();
		$('#articles-tab-show').hide();
		
		$('#products-tab').parent().removeClass();
		$('#products-tab').parent().addClass('selected-tab');
		$('#articles-tab').parent().removeClass();
		$('#articles-tab').parent().addClass('unselected-tab');
		
		
		
	});
$('#newslatter').click(function(e){
		
		e.preventDefault();
		
		var ajaxUrl = $(this).closest('form').attr('action');
		var name = $('#ful_name').val();
		var email = $('#ful_email').val();
		
		if(name !='' && name !='Your Name' && email !='' && email != 'Email Address')
		{
			$.post(ajaxUrl,{'name': name,'email':email},function(data){
				
				data = $.trim(data);
					$('#newsletter-form-warp').hide();
					
					$('#thanks').html('Thank You '+ data);
					$('#thanks').show();
					
				
				
			});
		}
		 
		});

/////////////////////  youtube  /////////////////////////////////////////////////////
$(".youtube").click(function() {
	$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'		: 680,
			'height'		: 495,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			   	 'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});

	return false;
});
 

//////////comments form
$('#submit-comment').click(function(event){

	var name = $('#comment-name').val();
	var email = $('#comment-email').val();
	var text = $('#comment-text').val();
	var good = true;
	if(name!='' && email!='' && text!='' )
	{
		if(name=='FULL NAME')
		{
			event.preventDefault();
			alert('Please enter a valid name');
			return;
		}
		
		if(email=='EMAIL ADRESS' || isValidEmailAddress(email)==false)
		{
			event.preventDefault();
			alert('Please enter a valid email');
			return;
		}
		
		if(text=='COMMENT')
		{
			event.preventDefault();
			alert('Please enter a comment');
			return;
		}
		
		
		
		
	}
	
	
	
});

$('.vote').click(function(event){

	event.preventDefault();
    
	var rel = $(this).attr('rel');
   var AjaxUrl = $(this).attr('href');
   $.post(AjaxUrl,{'vote': rel},function(data){
	  
		$('.up_result').html(Math.round(data.click_up) + '%');
		$('.down_result').html(Math.round(data.click_down) + '%');
		var href = 'javaScript:void(0)';
		$('.vote').attr('href',href);
		if(rel=='vote_up')
		{
			$('.vote_up').addClass('vote_up_click');
			$('.vote_down').addClass('not-click');
			$('.vote_down').addClass('vote_down_not');
			$('.vote_down_not').removeClass('vote_down');
		}
		else
		{
			$('.vote_down').addClass('vote_down_click');
			$('.vote_up').addClass('not-click');
			$('.vote_up').addClass('vote_up_not');
			$('.vote_up_not').removeClass('vote_up');
		}
	},'json');
});

$('.vote_pharmacy').click(function(event){
	
	event.preventDefault();
	
	var rel = $(this).attr('rel');
	var AjaxUrl = $(this).attr('href');
	$.post(AjaxUrl,{'vote': rel},function(data){
		
		$('.up_result').html(Math.round(data.click_up) + '%');
		$('.down_result').html(Math.round(data.click_down) + '%');
		var href = 'javaScript:void(0)';
		$('.vote_pharmacy').attr('href',href);
		if(rel=='vote_up')
		{
			$('.vote_up').addClass('vote_up_click');
			$('.vote_down').addClass('not-click');
			$('.vote_down').addClass('vote_down_not');
			$('.vote_down_not').removeClass('vote_down');
		}
		else
		{
			$('.vote_down').addClass('vote_down_click');
			$('.vote_up').addClass('not-click');
			$('.vote_up').addClass('vote_up_not');
			$('.vote_up_not').removeClass('vote_up');
		}
	},'json');
});


$('.vote_product').click(function(event){
	
	event.preventDefault();
	
	var rel = $(this).attr('rel');
	var AjaxUrl = $(this).attr('href');
	$.post(AjaxUrl,{'vote': rel},function(data){
		
		$('.up_result').html(Math.round(data.click_up) + '%');
		$('.down_result').html(Math.round(data.click_down) + '%');
		var href = 'javaScript:void(0)';
		$('.vote_product').attr('href',href);
		if(rel=='vote_up')
		{
			$('.vote_up').addClass('vote_up_click');
			$('.vote_down').addClass('not-click');
			$('.vote_down').addClass('vote_down_not');
			$('.vote_down_not').removeClass('vote_down');
		}
		else
		{
			$('.vote_down').addClass('vote_down_click');
			$('.vote_up').addClass('not-click');
			$('.vote_up').addClass('vote_up_not');
			$('.vote_up_not').removeClass('vote_up');
		}
	},'json');
});

 


$('a#contact-link').fancybox(
		{
        		'autoDimensions'	: false,
        		'width'         		: 500,
        		'height'        		: 346,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'showCloseButton' :false,
				'padding'       :0,
				 
				'onComplete' : function(){$('.close-w').click(function(){$.fancybox.close()})}
		}
	);

$('#quick-contact-form').live('submit',function(){
	
	var actionUrl = $(this).attr('action');
	$.fancybox.showActivity();
	

	$.ajax({
		type		: "POST",
		cache	: false,
		url		: actionUrl,
		data		: $(this).serializeArray(),
		  
		success: function(data) {
			
			if (data == 'ok')
			{
				$.fancybox.close();
				$.fancybox.showActivity();
				$("a#thankscontact").fancybox().trigger('click');
			}	
			else
			{
				$.fancybox(data);
			}
		}
	});
	return false;

});

$('a#thankscontact').fancybox(
		{
			'showCloseButton' :false,
        		'autoDimensions'	: false,
        		'width'         		: 550,
        		'height'        		: 166,
        		'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'padding'       :0,
				'onComplete' : function(){$('.close-w').click(function(){$.fancybox.close()})}
				 
		}
	);




/* add-read-co new comment review and rate*/
$('a#add-read-co').fancybox(
		{
        		'autoDimensions'  : false,
        		'width'           : 500,
        		'height'          : 480,
			'transitionIn'		  : 'none',
			'transitionOut'		  : 'none',
			'showCloseButton'     :false,
				'padding'         :0,
				'onComplete'      : function(){
					$('#rate-products').raty({
						cancel: true,
						half:  true,
						target:     '#products-score',
						targetKeep: true,
						targetType: 'number'
					});
					
					
					$('#ship-rate').raty({
						cancel: true,
						half:  true,
						target:     '#ship-score',
						targetKeep: true,
						targetType: 'number'
						
					});
					
					
					$('#support-rate').raty({
						cancel: true,
						half:  true,
						target:     '#support-score',
						targetKeep: true,
						targetType: 'number'
						
					});
					$('.close-w').click(function(){$.fancybox.close();});
				}
				
		 
		}
	);

$('#quick-review-form').live('submit',function(){
	
	var actionUrl = $(this).attr('action');

	var name     = $('#name').val();
	var email    = $('#email').val();
	var text     = $('#text').val();
	var location = $('#location').val();
	var sum      = $('#num-sum').val();
	var num1     = $('#num1').html();
	var num2     = $('#num2').html();
	var check = parseInt(num1)+parseInt(num2);
	var newsum =parseInt(sum);
	
	if(check != newsum)
	{
		alert('The sum you typed is incorrect');
		return false;
		
	}
	
	
	if(name=='' || email=='' || text=='' || text=='Your comment here...')
	{
		if(name=='')
		{
			alert('Please insert valid name');
			return false;
		}
		if(email=='')
		{
			alert('Please insert valid email');
			return false;
		}
		if(text=='' || text=='Your comment here...')
		{
			alert('Please insert a review');
			return false;
		}
		
	}
	$.fancybox.showActivity();

	$.ajax({
		type		: "POST",
		cache	: false,
		url		: actionUrl,
		data		: $(this).serializeArray(),
		  
		success: function(data) {
			
			if (data == 'ok')
			{
				$.fancybox.close();
				$.fancybox.showActivity();
				$("a#thanksreview").fancybox().trigger('click');
			}	
			else
			{
				$.fancybox(data);
			}
		}
	});
	return false;

});



$('a#thanksreview').fancybox(
		{
			'showCloseButton' :false,
        		'autoDimensions'	: false,
        		'width'         		: 550,
        		'height'        		: 166,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
				'padding'       :0,
				'onComplete' : function(){$('.close-w').click(function(){$.fancybox.close()})}
				
				 
		}
	);


/////////////////////vote poll

$('.vote_btn').click(function(e){
	
	e.preventDefault();
	
	var ajaxUrl = $(this).closest('form').attr('action');
	var ans1 = $('#ans1').val();
	var ans2 = $('#ans2').val();
	var ans3 = $('#ans3').val();
	var ans4 = $('#ans4').val();
	var pollid = $('#pollid').val();
	
	var ans = ans1
	if($('#ans2').attr('checked'))
	{
		ans = ans2;
	}
	if($('#ans3').attr('checked'))
	{
		ans = ans3;
	}
	if($('#ans4').attr('checked'))
	{
		ans = ans4;
	}
		$.post(ajaxUrl,{'ans': ans},function(data){
			
			data = $.trim(data);
			
			 $('.votepoll').hide();
			 $('#vote-result-show').html(data);
			
		});
	 
	 
	});

 
 


	
});

function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
	thisfield.value = "";
	}
	}
	function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
	thisfield.value = defaulttext;
	}
	}

	

