$(document).ready(function()
{
	
		$(".register input, .register select,.register textarea").formHints();

/*	$(document.getElementsByTagName("script")).each(function(s){
		if(s.src.match(/cropper\.js/)){
			var _a=s.src.replace(/cropper\.js(.*)?/,"");
			var _b=document.createElement("link");
			_b.rel="stylesheet";
			_b.type="text/css";
			_b.href=_a+"cropper.css";
			_b.media="screen";
			document.getElementsByTagName("head")[0].appendChild(_b);
		}
	});
*/
	$(".ceebox").ceebox(); //ceebox plugin	
			
	$("input[type='text'],input[type='password'],textarea,select").addClass("idleField");  
	$("input[type='text'],input[type='password'],textarea").focus(function() 
	{  
		  $(this).removeClass("idleField").addClass("focusField");  
	});  
	
	 $("input[type='text'],input[type='password'],textarea").blur(function() {  
		 $(this).removeClass("focusField").addClass("idleField");  
	 });  
	
	$(".watermark").watermark(); //watermark plugin
	$(".charcount").wordCharCounter(); //chars count plugin
	$(".wordcount").wordCharCounter({word:true}); // wordcount plugin
	$('.infiniteCarousel').infiniteCarousel();

});

function login()
{
	//login box
	var loginbox = '<a href="ajax.php?option=members&view=loginbox"></a>';
	$.fn.ceebox.popup(loginbox,{onload:true,htmlWidth:500,htmlHeight:400,width:400,height:450,titles:false});
}

function isValidEmail(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);
}


function validateFormOnSubmit(re,fclass) 
{	
 var counter = 0;
 var counter1 = 0;
 var fclass1	= (fclass ? "."+fclass : '');
 $(fclass1+" #f_msg").show();

 
$(fclass1+" input, "+fclass1+" textarea, "+fclass1+" select").each(function()
{
	
		if($(this).hasClass('must'))
		{
			if ($(this).val().length == 0 || ($(this).hasClass('watermark') && $(this).val() == $(this).attr('title')))
			{
				$(this).addClass('input_error');
				counter++;
			}
			else
			{
				$(this).removeClass('input_error');
			}
			
			//check for email 
				if (counter == 0) 
				{	
					if($(this).hasClass('email') && $(this).val().length > 0)
					{
						if(!isValidEmail($(this).val()))
						{
							$(this).addClass('input_error');
							 $(fclass1+" #f_msg").html('<div class="nor_error">Invalid Email Address</div>');
							counter1++;
							counter++;
						}
					}

					if($(this).is('select'))
					{
							if($(this).val() == '')
							{
								$(this).addClass('input_error');
								counter++;
							}
					}

					//check is number
					if($(this).hasClass('int'))
					{
						if( isNaN($(this).val()) )
						{
							$(this).addClass('input_error');
							 $(fclass1+" #f_msg").html('<div class="nor_error">Invalid number</div>');
							counter1++;
							counter++;
						}
					}

					//validate mobile
					if($(this).hasClass('mobile') && $(this).val().length > 0)
					{
						if(isNaN($(this).val()) || $(this).val().length < 10)
						{
							$(this).addClass('input_error');
							 $(fclass1+" #f_msg").html('<div class="nor_error">Invalid Mobile No.(ex:9123456789)</div>');
							counter1++;
							counter++;
						}
					}
				
				}
			
	
		}
	 });
	 
	 if (counter > 0) 
	 {
			if(counter1 == 0)
			{
				 $(fclass1+" #f_msg").html('<div class="nor_error">fields in red are required</div>');
			}
			
		if(re)
			return 0;
		else
			return false;
	 }
		if(re)
			return 1;
		else
			return true;
}

/**
Vertigo Tip by www.vertigo-project.com
Requires jQuery
*/

this.vtip = function() {    
    this.xOffset = 0; // x distance from mouse
    this.yOffset = 10; // y distance from mouse       
    $(".vtip").unbind().hover(
							
        function(e) {
            this.t = this.title;
            this.title = ''; 
            this.top = (e.pageY + yOffset); this.left = (e.pageX + xOffset);
            
            $('body').append( '<p id="vtip"><img id="vtipArrow" />' + this.t + '</p>' );
                        
            $('p#vtip #vtipArrow').attr("src", 'media/vtip_arrow.png');
            $('p#vtip').css("top", this.top+"px").css("left", this.left+"px").fadeIn("slow");
            
        },
        function() {
            this.title = this.t;
            $("p#vtip").fadeOut("slow").remove();
        }
    ).mousemove(
        function(e) {
            this.top = (e.pageY + yOffset);
            this.left = (e.pageX + xOffset);
                         
            $("p#vtip").css("top", this.top+"px").css("left", this.left+"px");
        }
    );            
    
};

$(window).bind('load',function($){vtip();}) 


