//NEW TEMPLATE

/**
 * Part of the code is from DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

var validateShortRegistration = 
{
	"fields": {},
	
	"init": function()
	{
		this.fields['firstname'] = 
		{
			"required": true,
			"value": $('#firstname').val(),
			"inputId": 'firstname', 
			"minLength": 2,
			"error": 0
		}
		this.fields['email'] = 
		{
			"required": true,
			"value": $('#email').val(),
			"inputId": 'email', 
			"error": 0
		}
		this.fields['url'] = 
		{
			"required": true,
			"value": $('#url').val(),
			"inputId": 'url', 
			"error": 0
		}
		this.fields['selected_package'] = 
		{
			"required": false,
			"value": $('#selected_package').val(),
			"error": 0
		}
		this.fields['st'] = 
		{
			"required": false,
			"value": $('#st').val(),
			"error": 0
		}
		this.fields['ref'] = 
		{
			"required": false,
			"value": $('#ref').val(),
			"error": 0
		}
		this.fields['colors'] = 
		{
			"required": false,
			"value": $('#colors').val(),
			"error": 0
		}
		this.fields['size'] = 
		{
			"required": false,
			"value": $('#size').val(),
			"error": 0
		}
		
		validationMethods.clearErrors(this.fields);
	},
	
	
	
	"validate": function()
	{
	
		this.init();
		var that = this;
		var has_focus=false;
		$.each(this.fields, function(){
			if ((!validationMethods.validateRequired(this)) || (!validationMethods.minLength(this)))
			{
				//validationMethods.showErrorBox('Required field cannot be left blank');
				validationMethods.showInputErrorBox(this.inputId , 'Missing value');
				this.error = 1;
				if (!has_focus) {
					has_focus  = true;
					$('#'+this.inputId).focus();
				}
			}
		});
		
		if (!validationMethods.validateEmail(this.fields['email'].value))
		{
			//validationMethods.showErrorBox('Invalid email');
			validationMethods.showInputErrorBox(this.fields['email'].inputId , 'Invalid email');
			this.fields['email'].error = 1;
			if (!has_focus) {
				has_focus  = true;
				$('#'+this.fields['email'].inputId).focus();
			}
		}
		
		if (!validationMethods.validateURL(this.fields['url'].value))
		{
			//validationMethods.showErrorBox('Invalid url');
			validationMethods.showInputErrorBox(this.fields['url'].inputId , 'Invalid url');
			this.fields['url'].error = 1;
			if (!has_focus) {
				has_focus  = true;
				$('#'+this.fields['url'].inputId).focus();
			}
		}
		
		if (!validationMethods.markErrors(this.fields))
		{
			this.sendForm();
		}
			
	}, 
	
	"sendForm": function()
	{
		var that = this;
		$.ajax({ 
		   type: "POST", 
		   dataType: 'json',
		   cache: false,
		   url: "/owner_public/owner-beta-save-registeration.php", 
		   data: {
		   			'firstname': that.fields['firstname'].value, 
		   			'email': that.fields['email'].value, 
		   			'url': that.fields['url'].value, 
		   			'st': that.fields['st'].value, 
		   			'selected_package': that.fields['selected_package'].value,
		   			'colors': that.fields['colors'].value, 
		   			'size': that.fields['size'].value, 
		   			'ref': that.fields['ref'].value
		   },
		   
		   beforeSend: function()
		   {
		   		validationMethods.loadingAnimation();
		   }, 
		   
		   success: function(msg){ 
		     if (msg.errorCode)
		     {
		     	switch (msg.errorCode)
		     	{
		     		case 1:
		     			that.fields['email'].error = 1;
		     			break;
		     		case 2:
		     			that.fields['email'].error = 1;
		     			validationMethods.showInputErrorBox(that.fields['email'].inputId ,'Email exists.')
		     			break;
		     		case 3:
		     			that.fields['firstname'].error = 1;
		     			validationMethods.showInputErrorBox(that.fields['firstname'].inputId ,'invalid name')
		     			break;
		     		case 8:
		     			that.fields['email'].error = 1;
		     			validationMethods.showInputErrorBox(that.fields['firstname'].inputId ,'contact support' )
		     			break;
		     	}
		     	validationMethods.markErrors(that.fields);
		     	validationMethods.loadingAnimation();
		     } 
		     else if (msg.url)
		     {
		     	//Success
				if (typeof(pageTracker)!='undefined' && pageTracker)
					pageTracker._trackPageview("registration_success_"+that.fields['st'].value);
		     	
		     	window.location.href = msg.url;
		     }
		   } 
		 });
	}
}
////////////////////////////////////////////////////////////
var validateLongRegistration = 
{
	"fields": {},
	
	"init": function()
	{
		this.fields['firstname'] = 
		{
			"required": true,
			"value": $('#firstname').val(),
			"inputId": 'firstname', 
			"minLength": 2,
			"error": 0
		}
		this.fields['email'] = 
		{
			"required": true,
			"value": $('#email').val(),
			"inputId": 'email', 
			"error": 0
		}
		this.fields['notify'] = 
		{
			"required": true,
			"value": $('#notify').val(),
			"inputId": 'notify', 
			"error": 0
		}
		this.fields['rpassword'] = 
		{
			"required": true,
			"value": $('#rpassword').val(),
			"inputId": 'rpassword', 
			"minLength": 6,
			"error": 0
		}
		this.fields['confpassword'] = 
		{
			"required": true,
			"value": $('#confpassword').val(),
			"inputId": 'confpassword', 
			"error": 0
		}
		this.fields['phone'] = 
		{
			"required": true,
			"value": $('#phone').val(),
			"inputId": 'phone', 
			"error": 0
		}
		this.fields['url'] = 
		{
			"required": true,
			"value": $('#url').val(),
			"inputId": 'url', 
			"error": 0
		}
		this.fields['agree'] = 
		{
			"required": true,
			"value": ($('#agree').is(":checked")) ? 1 : 0,
			"inputId": 'agree', 
			"error": 0
		}
		this.fields['subscribe'] = 
		{
			"required": false,
			"value": ($('#subscribe').is(":checked")) ? 1 : 0,
			"inputId": 'subscribe', 
			"error": 0
		}
		this.fields['selected_package'] = 
		{
			"required": false,
			"value": $('#selected_package').val(),
			"error": 0
		}
		this.fields['temp_pwd'] = 
		{
			"required": false,
			"value": $('#temp_pwd').val(),
			"error": 0
		}
		this.fields['ref'] = 
		{
			"required": false,
			"value": $('#ref').val(),
			"error": 0
		}

		
		validationMethods.clearErrors(this.fields);
	},
	
	
	
	"validate": function()
	{
		this.init();
		var that = this;
		$.each(this.fields, function(){
			if ((!validationMethods.validateRequired(this)) || (!validationMethods.minLength(this)))
			{
				this.error = 1;
				validationMethods.showInputErrorBox(this.inputId , 'Missing value');
			}
		});
		if (!validationMethods.validateURL(this.fields['url'].value))
		{
			this.fields['url'].error = 1;
			validationMethods.showInputErrorBox(this.fields['url'].inputId , 'Invalid URL');
		}
		if (!validationMethods.validateCompare(this.fields['rpassword'].value, this.fields['confpassword'].value))
		{
			this.fields['rpassword'].error = 1;
			this.fields['confpassword'].error = 1;
		}
		if (!validationMethods.markErrors(this.fields))
		{
			this.sendForm();
		}
	}, 
	
	"sendForm": function()
	{
		var that = this;
		$.ajax({ 
		   type: "POST", 	
		   dataType: 'json',
		   cache: false,
		   url: "/owner_public/owner-save-registeration.php", 
		   data: {
		   			'firstname': that.fields['firstname'].value, 
		   			'email': that.fields['email'].value, 
		   			'url': that.fields['url'].value, 
		   			'temp_pwd': that.fields['temp_pwd'].value, 
		   			'rpassword': that.fields['rpassword'].value, 
		   			'confpassword': that.fields['confpassword'].value, 
		   			'street': '', 
		   			'street_2': '', 
		   			'question': 0, 
		   			'answer': '', 
		   			'state': 'NA', 
		   			'zip': '', 
		   			'phone': that.fields['phone'].value, 
		   			'company': '', 
		   			'notify': that.fields['notify'].value, 
		   			'subscribe': that.fields['subscribe'].value, 
		   			'selected_package': that.fields['selected_package'].value,
		   			'ref': that.fields['ref'].value
		   },
		   
		   beforeSend: function()
		   {
		   		validationMethods.loadingAnimation();
		   }, 
		   
		   success: function(msg){ 
		     if (msg.errorCode)
		     {
		     	switch (msg.errorCode)
		     	{
		     		case 1:
		     			that.fields['email'].error = 1;
		     			validationMethods.showInputErrorBox(that.fields['email'].inputId ,'Email address already exists');
		     			break;
		     		case 2:
		     			that.fields['rpassword'].error = 1;
		     			that.fields['confpassword'].error = 1;
		     			break;
		     		case 3:
		     			that.fields['firstname'].error = 1;
		     			break;
		     		case 4:
		     			that.fields['email'].error = 1;
		     			validationMethods.showInputErrorBox(that.fields['email'].inputId ,'Email address already exists');
		     			break;		     			
		  
		     		case 5:
		     		case 6:
		     			alert('General Error');
		     			break;
		     		case 8:
		     			that.fields['email'].error = 1;
		     			validationMethods.showInputErrorBox(that.fields['email'].inputId ,'Problem with registeration - please contact support');
		     			break;
		     	}
		     	validationMethods.markErrors(that.fields);
		     	validationMethods.loadingAnimation();
		     } 
		     else if (msg.url)
		     {
		     	window.location.href = msg.url;
		     }
		   } 
		 });
	}, 
	
	"selector": function(item,selected)
	{
		$.ajax({ 
		   type: "POST", 
		   cache: false,
		   url: "/owner/functions/selectors.php", 
		   data: {
		   			'param': 'state', 
		   			'item': item, 
		   			'selected': selected
		   },
		   
		 success: function(msg){ 
		     $('#state_area').html(msg);
		 }
		});
	}
}


































////////////////////////////////////////////////////////////
var validateDemoRequest = 
{
"fields": {},

"init": function()
{
this.fields['firstname'] = 
{
"required": true,
"value": $('#firstname').val(),
"inputId": 'firstname', 
"minLength": 2,
"error": 0
}
this.fields['email'] = 
{
"required": true,
"value": $('#email').val(),
"inputId": 'email', 
"error": 0
}
this.fields['phone'] = 
{
"required": true,
"value": $('#phone').val(),
"inputId": 'phone', 
"error": 0
}
this.fields['url'] = 
{
"required": true,
"value": $('#url').val(),
"inputId": 'url', 
"error": 0
}
this.fields['comments'] = 
{
"required": false,
"value": $('#comments').val(),
"inputId": 'comments', 
"error": 0
}
validationMethods.clearErrors(this.fields);
},



"validate": function()
{
	this.init();
	var that = this;
	$.each(this.fields, function(){
		if ((!validationMethods.validateRequired(this)) || (!validationMethods.minLength(this)))
		{
			this.error = 1;
			validationMethods.showInputErrorBox(this.inputId , 'Missing value');
		}
	});
	if (!validationMethods.validateEmail(this.fields['email'].value))
	{
		this.fields['email'].error = 1;
		validationMethods.showInputErrorBox(this.fields['email'].inputId , 'Invalid email');
	}
	if (!validationMethods.validateURL(this.fields['url'].value))
	{
		this.fields['url'].error = 1;
		validationMethods.showInputErrorBox(this.fields['url'].inputId , 'Invalid URL');
	}
	if (!validationMethods.markErrors(this.fields))
	{
		this.sendForm();
	}
}, 

"sendForm": function()
{
	var that = this;
	$.ajax(
	{ 
		type: "POST", 
		dataType: 'json',
		cache: false,
		url: "/owner_public/request-demo-save.php", 
		data: {
		'firstname': that.fields['firstname'].value, 
		'email': that.fields['email'].value, 
		'url': that.fields['url'].value, 
		'phone': that.fields['phone'].value, 
		'comments': that.fields['comments'].value
	},

	beforeSend: function()
	{
		validationMethods.loadingAnimation();
	}, 
	
	success: function(msg)
	{ 
		if (msg.errorCode)
		{
			validationMethods.markErrors(that.fields);
			validationMethods.loadingAnimation();
		}
		else if (msg.url)
		{
			window.location.href = msg.url;
		}
	} 
	
	}); // end of ajax request
}, 

"selector": function(item,selected)
{
$.ajax({ 
type: "POST", 
cache: false,
url: "/owner/functions/selectors.php", 
data: {
'param': 'state', 
'item': item, 
'selected': selected
},

success: function(msg){ 
$('#state_area').html(msg);
}
});
}
}
