function JScript(returnPath)
{
	this._ajaxurl = 'register.php';
	this._returnPath = returnPath;
}
JScript.prototype.changeState = function(elem)
{
	var obj = this;
	var countryBox = elem;
	var stateBox = $('#' + $(elem).attr('stateElement'));
	$(stateBox).attr('readonly', true);
	var otherField = $('#' + $(stateBox).attr('otherField'));
	$(otherField).val('');
	
	var data = {
		mode:		'changeState',
		countryID: $(countryBox).val()
	};
	$.ajax({
		url: 		obj._ajaxurl,
		data:		data,
		type:		'POST',
		timeout: 	1200,
		//dataType:	'json',
		success:	function(jData, textStatus){
			var dropDown = '<select id="' + $(stateBox).attr('id') + '" name="' + $(stateBox).attr('name') + '" style="width:auto" onchange="JavaScript: return js.changeCity(this);" cityElement="' + $(stateBox).attr('cityElement') + '">';
			dropDown += jData;
			dropDown += '</select>';
			$(stateBox).replaceWith(dropDown);
		}		
	});
}
JScript.prototype.changeCity = function(elem)
{
	
	
	var obj = this;
	var stateBox = elem;
	var cityBox = $('#' + $(elem).attr('cityElement'));
	$(cityBox).attr('readonly', true);
	
	if($(stateBox).val()!='6')
	{
		//alert($(cityBox).attr('id'));
	    //return;
		var textBox = '<input type="text" id="' + $(cityBox).attr('id') + '" name="' + $(cityBox).attr('name') + '" style="width:auto">';
		$(cityBox).replaceWith(textBox);
	}
	else
	{
	       var data = {
				mode:		'changeCity',
				stateID: $(stateBox).val()
			};
			$.ajax({
				url: 		obj._ajaxUrl,
				data:		data,
				type:		'POST',
				timeout: 	3000,
				//dataType:	'json',
				success:	function(jData, textStatus){
					var dropDown = '<select id="' + $(cityBox).attr('id') + '" name="' + $(cityBox).attr('name') + '" style="width:auto">';
					dropDown += jData;
					dropDown += '</select>';
					$(cityBox).replaceWith(dropDown);
				},
				error:		function(XMLHttpRequest, textStatus, errorThrown){
					var errors = new Array();
					if (textStatus == 'timeout')
					{
						errors.push('Sorry! Request Timeout.<br />Please check you internet connection.');
					}
					else if (textStatus == 'parsererror')
					{
						errors.push('Invalid Response returned by Server.');
					}
					else
					{
						errors.push('Unknown Error.');
					}
					$('.errors:eq(0)').html(obj.formatErrors(errors)).slideDown(500);
				}		
			});	
	}
	
}
JScript.prototype.checkOther = function(elem)
{
	var obj = this;
	var otherElement = '#' + $(elem).attr('otherField');
	
	if ($(elem).val() == 'other')
	{
		$(otherElement).attr('readonly', false);
		$(otherElement).val('');
	}
	else if ($(elem).isEmpty())
	{
		$(otherElement).attr('readonly', true);
		$(otherElement).val('');
	}
	else
	{
		$(otherElement).attr('readonly', true);
		$(otherElement).val($(elem).find('option').filter(':selected').text());
	}
}
JScript.prototype.createAccount = function(elem)
{
	var obj = this;
	var errors = new Array();
	
	if ($('#acc_uname').isEmpty())
	{
		errors.push('Enter Username.');
	}
	if ($('#acc_password').isEmpty() || $('#acc_conf_password').isEmpty())
	{
		if ($('#acc_password').isEmpty())
		{
			errors.push('Enter Password.');
		}
		if ($('#acc_conf_password').isEmpty())
		{
			errors.push('Re-enter Password..');
		}
	}
	else if ($('#acc_password').val() != $('#acc_conf_password').val())
	{
		errors.push('Passwords not matching.');
	}
	if ($('#acc_fname').isEmpty())
	{
		errors.push('Enter First Name.');
	}
	if ($('#acc_lname').isEmpty())
	{
		errors.push('Enter Last Name.');
	}
	if ($('#acc_address_1').isEmpty())
	{
		errors.push('Enter Address 1.');
	}
	/*if ($('#acc_city').isEmpty())
	{
		errors.push('Enter City.');
	}*/
	if ($('#acc_country').isEmpty())
	{
		errors.push('Select Country.');
	}
	if ($('#acc_state').isEmpty())
	{
		errors.push('Select/Enter State.');
	}
	if ($('#acc_zip').isEmpty())
	{
		errors.push('Enter Zip/Postal Code.');
	}
	if ($('#acc_phone').isEmpty())
	{
		errors.push('Enter Phone.');
	}
	if ($('#acc_email').isEmpty())
	{
		errors.push('Enter Email.');
	}
	else if (!$('#acc_email').emailCheck())
	{
		errors.push('Enter valid Email.');
	}
	if (errors.length == 0)
	{
		$(elem).attr('disabled', true);
		var data = {
			mode:		'createAccount'
		};
		$('#frmCreateAccount').ajaxSubmit({
			url: 		obj._ajaxurl,
			data:		data,
			type:		'POST',
			timeout: 	1200,
			dataType:	'json',
			success:	function(jData, textStatus){
				if (jData.isDone)
				{
					if (obj._returnPath.length == 0)
					{
						window.location.href = 'myaccount.php';
					}
					else
					{
						window.location.href = obj._returnPath;
					}
				}
				else
				{
					alert(jData.message.join('\n'));
					$(elem).attr('disabled', false);
				}
			}		
		});
	}
	else
	{
		alert(errors.join('\n'));
	}
	return false;
}