/* //////////////////////////////////
//
// SEQOY Development S/A 
// www.seqoy.com 
//
//////////////////////////////////
 
 Creation Date: May, 14. 2009
 Reutilization Date: March, 30 . 2010
 Created by: SEQOY Development Team
 
 This file it's a open source Javascript file, 
 you can use this code as free as you want.

////////////////////////////////// */

//<![CDATA[
/* Replacement calls. Please see documentation for more information. */

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//	Field Input Functions  
//
// Clear Field Value when focused or highlight the text.
function clearValue(field) { 
	if (field.defaultValue == field.value) {
		field.value = "" ;
	}
	field.focus();
	field.select();
	
	// Avoid to lose selection.
	 event.returnValue = false;
     event.cancelBubble = true;

	 $('#signUpDoneMessage').hide();

}

// Check if the when lose focus are empty.
function checkEmptyValue(field) { 
	if ( field.value.length==0 ) {
		field.value = field.defaultValue ;
	}
}



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//	Main Website Object
//
// Base URL
var base_url = "http://" + window.location.hostname;

var objPubliyou = {
		is_ie: navigator.userAgent.indexOf('MSIE') > 0,
		
		attr: {
			/**
			 * Cannot call : objPubliyou.is_ie. It hasn't registered yet. If you call it
			 * below this declaration, IE will not allow it. Firefox will. So you must go
			 * through the motion of using navigator.userAgent again here.
			 */
			onClick: navigator.userAgent.indexOf('MSIE') >0 ? 'onclick' : 'onClick'
		},

		user: {

		}
}

///////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//	Sign Up Section - Javascript Actions
//

objPubliyou.user = {
	
}

// Newsletter Sign Up. 
objPubliyou.user = {
	request_signup: function(){
		$.post( base_url + '/db_actions/signup_user.php',
		 {
		 userName:	 $('#input_field_userName').val(),
		 firstName:	 $('#input_field_firstName').val(),
		 lastName:	 $('#input_field_lastName').val(),
		 password: 	 $('#input_field_password').val(),
		 email:		 $('#input_field_email').val()
	     }, 
		
		function( data ) { 
				 	
					$('#signUpMessage').html( data );
				   
			   }	   
		);
	},
	
	///////////////////////////////////////////////////////////////////////////////////
	check_user: function(){
		$('#sign_user_info').html('Checking availability...');
		$.post( base_url + '/db_actions/check_user.php',
		 {
		 userName:	 $('#input_field_userName').val()
 		 }, 
		
		function( data ) { 
				 	
					$('#signUpMessage').html( data );
				   
			   }	   
		);	
	},
	
	///////////////////////////////////////////////////////////////////////////////////
	check_firstName: function(){
	
		var name = $('#input_field_firstName').val();

		// Check if is empty.
		if( name ) {
			$('#sign_name_info').html('Keep it up.');
			$('#sign_name_info').css('color', 'green');
			
		} else {
			$('#sign_name_info').html('Please inform a valid First Name.');
			$('#sign_name_info').css('color', 'red');
		
		}


	},
	
	///////////////////////////////////////////////////////////////////////////////////
	check_lastName: function(){
	
		var name = $('#input_field_lastName').val();
	
		// Check if is empty.
		if( name ) {
			$('#sign_lastname_info').html('Almost there.');
			$('#sign_lastname_info').css('color', 'green');
			
		} else {
			$('#sign_lastname_info').html('Please inform a valid Last Name.');
			$('#sign_lastname_info').css('color', 'red');
		
		}
	
	
	},
	
	///////////////////////////////////////////////////////////////////////////////////
	check_password: function(){
		$.post( base_url + '/db_actions/check_password.php',
		 {
			 password:	 $('#input_field_password').val()
			 }, 
		
		function( data ) { 
				 	
					$('#signUpMessage').html( data );
				   
			   }	   
		);	
	},
	
	///////////////////////////////////////////////////////////////////////////////////
	check_mail: function(){
		$.post( base_url + '/db_actions/check_mail.php',
		 {
		 mail: $('#input_field_email').val()
			 }, 
		
		function( data ) { 
				 	
					$('#signUpMessage').html( data );
				   
			   }	   
		);	
	},
	
			
}
		


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//	Sign Up Section - Javascript Test Field Actions
//
function hideContainerMessage() {
	$('#commentMessageContainer').animate({ opacity: 0 }, "slow");
}
///
objPubliyou.checkUser = {
	checkUser: function(){
		
		
		var name 	= $('#comment_input_author').val();
		var email 	= $('#comment_input_email').val();
		var web 	= $('#comment_input_url').val();
		var text 	= $('#comment_input_body').val();
		var post 	= $('#comment_post_ID').val();
		var parent 	= $('#comment_parent').val();
		
		/////
		
		 var comment_author_default		  = $('#post_author_default').val();
		 var comment_author_email_default = $('#post_author_email_default').val();
		 var comment_author_url_default   = $('#post_author_url_default').val();	
		 var comment_body_text			  = $('#post_author_body').val();	
	
		/////
		
		var ret		=	'';
			
		// Author Name. 
		if( ! jQuery.trim( name ) || name == comment_author_default ) {
		 	ret += 'Por favor informe tu nombre.<br />';
		 	$('#comment_input_author').val( comment_author_default );
			
		}
 
 		// E-mail.
		if( ! jQuery.trim(  email ) || email == comment_author_email_default ) {
		
			ret += 'Por favor informe tu direcci&oacute;n de e-mail.<br />';
			$('#comment_input_email').val( comment_author_email_default );
			
		} 
		
		// Valid e-mail.
		else if ( ! /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,5})+$/.test(email) ) {
			
			ret += 'Informe un e-mail v&aacute;lido. <br />';
			$('#comment_input_email').val( comment_author_email_default );
			
		}
		
		// URL.
	 	if( web == comment_author_url_default  ) {
	 	
	 		web = "";
	 		
	 	}

		// Comment Text.
		if( ! jQuery.trim( text ) || text == comment_body_text ) {
		
			ret += "No olvid&eacute;s tu coment&aacute;rio.";
 			$('#comment_input_body').val( comment_body_text	 );
 		}
 		
		if( ret != '' ) {
			$('#commentMessageContainer').html(ret);
			$('#commentMessageContainer').animate({ opacity: 1 }, "slow");
			
		} else {
		
		//	document.commentform.submit();
			
			$.post( base_url + "/wp-comments-post.php",
				{
				author: name,
				email: email,
				url: web,
				comment: text,
				comment_post_ID: post,
				comment_parent: parent
				},
				function(data){
					$('#commentMessageContainer').html("<span style='color:#666;'>Tu coment&aacute;rio fue enviado<br>y est&aacute; aguardando aprovaci&oacute;n.");
					$('#commentMessageContainer').animate({ opacity: 1 }, "slow");
					$('#comment_name').val('');
					$('#comment_email').val('');
					$('#comment_website').val('');
					$('#comment_text').val('');
 
				});
		}
	}
}

//]]>

