// IndexOf Prototype for Internet Explorer 6
if (!Array.indexOf) { Array.prototype.indexOf = function(obj){for(var i=0;i<this.length;i++){if(this[i]==obj)return i;}return -1;}}

// Menu Click - Change Page
function change_page (obj) {
	document.location = 'index.php?page=' + obj.id;
}

// Input Change
function input_change (obj) {
	if ($(obj).hasClass('wrong_input')) {
		$(obj).removeClass('wrong_input');
	}
}

// Check if String is Numeric
function is_numeric (input) {
    return (input - 0) == input && input.length > 0;
}

// Reload Captcha
function reload_captcha () {
	var randomnumber = Math.floor(Math.random() * 1001);
	$('#captcha_img').attr("src", 'includes/captcha.php?num=' + randomnumber);
	$('#captcha').val('');	
}

// Disable Enter Click
function disableEnterKey (obj) {
     var key;
	 
     if (window.event) key = window.event.keyCode; // IE
     else key = e.which; // Firefox
	 
     if (key == 13) return false;
     else return true;
}

// CheckBox Change
function check_change () {
	if ($('#accept_text').hasClass('red')) {
		$('#accept_text').removeClass('red');
	}
}

// Login Mail Input Click
function login_mail_click (obj) {
	if ($(obj).val() == lang_email) {
		$(obj).val('');
	}
}

// Login Mail Input Blur
function login_mail_blur (obj) {
	if ($(obj).val() == '') {
		$(obj).val(lang_email);
	}
}

// Login Password Input Click
function login_password_click (obj) {
	if ($(obj).val() == lang_password) {
		$(obj).val('');
	}
}

// Login Password Input Blur
function login_password_blur (obj) {
	if ($(obj).val() == '') {
		$(obj).val(lang_password);
	}
}

// Start Verification
function start_verification (obj) {
	var send_status = true; // Send Status
	
	// Password
	if (jQuery.trim($('#password').val()) == '') {
		$('#password').addClass('wrong_input');
		$('#alert_area').html(lang_fill_required_fields);
		send_status = false;
	}
	
	// Repeat Password
	if (jQuery.trim($('#repeat_password').val()) == '') {
		$('#repeat_password').addClass('wrong_input');
		$('#alert_area').html(lang_fill_required_fields);
		send_status = false;
	}
	
	// Passwords Minimum Length
	if ($('#password').val() != '' && $('#password').val().length < conf_password_min_length) {
		$('#password').addClass('wrong_input');
		$('#alert_area').html(lang_password_min_length);
		send_status = false;
	} 
	
	// Compare Passwords
	if (jQuery.trim($('#password').val()) != '' && jQuery.trim($('#password').val()) != jQuery.trim($('#repeat_password').val())) {
		$('#repeat_password').addClass('wrong_input');
		$('#alert_area').html(lang_repeat_password_not_correct);
		send_status = false;
	} 
	
	// Check E-Mail
	if (jQuery.trim($('#email').val()) == '') {
		$('#email').addClass('wrong_input');
		$('#alert_area').html(lang_fill_required_fields);
		send_status = false;
	} else {
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;	// E-Mail Filter
		if (!filter.test($('#email').val())) {
			$('#email').addClass('wrong_input');
			$('#alert_area').html(lang_email_not_correct);
			send_status = false;
		}
	}
	
	// Check Personal Number
	if (jQuery.trim($('#personal_number').val()) == '') {
		$('#personal_number').addClass('wrong_input');
		$('#alert_area').html(lang_fill_required_fields);
		send_status = false;
	} else if (jQuery.trim($('#personal_number').val()).length != 11 || !is_numeric(jQuery.trim($('#personal_number').val()))) {
		$('#personal_number').addClass('wrong_input');
		$('#alert_area').html(lang_personal_number_not_correct);
		send_status = false;
	}
	
	// Check Phone
	if (jQuery.trim($('#phone').val()) == '') {
		$('#phone').addClass('wrong_input');
		$('#alert_area').html(lang_fill_required_fields);
		send_status = false;
	} else if (jQuery.trim($('#phone').val()).length < conf_phone_min_length || jQuery.trim($('#phone').val()).length > conf_phone_max_length || !is_numeric(jQuery.trim($('#phone').val()))) {
		$('#phone').addClass('wrong_input');
		$('#alert_area').html(lang_phone_not_correct);
		send_status = false;
	}
	
	// If All Variables Correct
	if (send_status) {
		// Clear Alert Area
		$('#alert_area').html('');
		
		// Show Loading
		$('.loader').show();
		
		// Disable Button
		$(obj).attr('disabled', true);
		
		// Request Registration Check Page
		$.post ('scripts/verification_check.php', $("#verification_form").serialize(),
		function (data) {
			// Hide Loading
			$('.loader').hide();
			
			// Enable Button
			$(obj).attr('disabled', false);
			
			// Data
			switch (data) {
				case 'success': // Success
					$("#verification_form").submit();
					break;
				case 'fill_graphs': // Incorrect First and Last Name
					$('#alert_area').html(lang_fill_required_fields);
					break;
				case 'incorrect_password': // Incorrect Password
					$('#password').addClass('wrong_input');
					$('#repeat_password').addClass('wrong_input');
					$('#alert_area').html(lang_password_not_correct);
					break;
				case 'incorrect_mail': // Incorrect Mail
					$('#email').addClass('wrong_input');
					$('#alert_area').html(lang_email_not_correct);
					break;
				case 'incorrect_personal_number': // Incorrect Personal Number
					$('#personal_number').addClass('wrong_input');
					$('#alert_area').html(lang_personal_number_not_correct);
					break;
				case 'incorrect_phone': // Incorrect Phone
					$('#phone').addClass('wrong_input');
					$('#alert_area').html(lang_phone_not_correct);
					break;
				case 'incorrect_user': // Incorrect User
					$('#alert_area').html(lang_user_not_match);
					break;
				default: // Error
					$('#alert_area').html(lang_error);
			}
		});
	}
}

// Start Registration
function start_registration (obj) {
	var send_status = true; // Send Status
	
	// Check Rules
	if (!$('#accept').attr("checked")) {
		$('#accept_text').addClass('red');
		send_status = false;
	}
	
	// Check Captcha
	if (jQuery.trim($('#captcha').val()) == '') {
		$('#captcha').addClass('wrong_input');
		$('#alert_area').html(lang_fill_required_fields);
		send_status = false;
	} else if (jQuery.trim($('#captcha').val()).length != 4 || !is_numeric(jQuery.trim($('#captcha').val()))) {
		$('#captcha').addClass('wrong_input');
		$('#alert_area').html(lang_captcha_not_correct);
		send_status = false;
	}
	
	// If All Variables Correct
	if (send_status) {
		// Clear Alert Area
		$('#alert_area').html('');
		
		// Show Loading
		$('.loader').show();
		
		// Disable Button
		$(obj).attr('disabled', true);
		
		// Request Registration Check Page
		$.post ('scripts/registration_check.php', $("#registration_form").serialize(),
		function (data) {
			// Hide Loading
			$('.loader').hide();
			
			// Enable Button
			$(obj).attr('disabled', false);
			
			// Data
			switch (data) {
				case 'success': // Success
					$("#registration_form").submit();
					break;
				case 'incorrect_captcha': // Incorrect Captcha
					$('#captcha').addClass('wrong_input');
					$('#alert_area').html(lang_captcha_not_correct);
					break;
				case 'user_exist': // User Exist
					$('#alert_area').html(lang_user_already_registered);
					break;
				default: // Error
					$('#alert_area').html(lang_error);
			}
			
			// Reload Captcha
			reload_captcha ();
		});
	}
}

// Start Activation
function start_activation (obj) {
	var send_status = true; // Send Status
	
	// Check Activation Code
	if (jQuery.trim($('#activation_code').val()) == '') {
		$('#activation_code').addClass('wrong_input');
		$('#alert_area').html(lang_fill_activation_code);
		send_status = false;
	} else if ($('#activation_code').val().length != 5) {
		$('#activation_code').addClass('wrong_input');
		$('#alert_area').html(lang_incorrect_activation_code);
		send_status = false;
	}
	
	// If All Variables Correct
	if (send_status) {
		// Clear Alert Area
		$('#alert_area').html('');
		
		// Show Loading
		$('.loader').show();
		
		// Disable Button
		$(obj).attr('disabled', true);
		
		// Request Registration Check Page
		$.post ('scripts/activation_check.php', $("#activation_form").serialize(),
		function (data) {
			// Hide Loading
			$('.loader').hide();
			
			// Enable Button
			$(obj).attr('disabled', false);
			
			// Data
			switch (data) {
				case 'activation_ready': // Activation Ready
					$('#tools_div').html('<div class="green">' + lang_activation_ready + '</div>');
				break;
					case 'activate_mail': // Activate Mail
					$('#tools_div').html('<div class="green">' + lang_activate_email + '</div>');
				break;
					case 'invalid_activation_code': // Invalid Activation Code
					$('#alert_area').html(lang_incorrect_activation_code);
					break;
				default: // Error
					$('#alert_area').html(lang_error);
			}
		});
	}
}

// Resend Activation
function resend_activation (obj) {
	var send_status = true; // Send Status
	
	// Check Captcha
	if (jQuery.trim($('#captcha').val()) == '') {
		$('#captcha').addClass('wrong_input');
		$('#alert_area_2').html(lang_fill_required_fields);
		send_status = false;
	} else if (jQuery.trim($('#captcha').val()).length != 4 || !is_numeric(jQuery.trim($('#captcha').val()))) {
		$('#captcha').addClass('wrong_input');
		$('#alert_area_2').html(lang_captcha_not_correct);
		send_status = false;
	}
	
	// If All Variables Correct
	if (send_status) {
		// Clear Alert Area
		$('#alert_area_2').html('');
		
		// Show Loading
		$('.loader_2').show();
		
		// Disable Button
		$(obj).attr('disabled', true);
		
		// Request Registration Check Page
		$.post ('scripts/resend_activation_check.php', $("#resend_activation_form").serialize(),
		function (data) {
			// Hide Loading
			$('#loader_2').hide();
			
			// Enable Button
			$(obj).attr('disabled', false);
			
			// Data
			switch (data) {
				case 'activation_sent': // Activation Ready
					$('#tools_2_div').html('<div class="green">' + lang_activation_sent + '</div>');
				case 'incorrect_captcha': // Incorrect Captcha
					$('#captcha').addClass('wrong_input');
					$('#alert_area_2').html(lang_captcha_not_correct);
					reload_captcha();
					break;
				default: // Error
					$('#alert_area_2').html(lang_error);
					reload_captcha();
			}
		});
	}
}

// Log In Key Up Trigger
function login_key_up (event) {
	if (event.keyCode == 13){
		start_login ($("#login_btn"));
	}
}

// Start Log In
function start_login (obj) {
	var send_status = true; // Send Status
	$('#main_alert').hide();
	
	// Check E-Mail
	if (jQuery.trim($('#user_email').val()) == '') {
		$('#user_email').addClass('wrong_input');
		$('#main_alert').show();
		$('#main_alert').html(lang_fill_required_fields);
		send_status = false;
	} else {
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;	// E-Mail Filter
		if (!filter.test($('#user_email').val())) {
			$('#user_email').addClass('wrong_input');
			$('#main_alert').show();
			$('#main_alert').html(lang_email_not_correct);
			send_status = false;
		}
	}
	
	// Check Pssword
	if (jQuery.trim($('#user_password').val()) == '') {
		$('#user_password').addClass('wrong_input');
		$('#main_alert').show();
		$('#main_alert').html(lang_fill_required_fields);
		send_status = false;
	} 
	
	// If All Variables Correct
	if (send_status) {
		// Clear Alert Area
		$('#main_alert').html('');
		
		// Show Loading
		$('.login_loader').show();
		
		// Disable Button
		$(obj).attr('disabled', true);
		
		// Request Registration Check Page
		$.post ('scripts/login_check.php', $("#login_form").serialize(),
		function (data) {
			// Hide Loading
			$('.login_loader').hide();
			
			// Enable Button
			$(obj).attr('disabled', false);
			
			// Data
			switch (data) {
				case 'success': // Success
					document.location = 'index.php';
					break;
				case 'incorrect_password': // Incorrect Password
					$('#main_alert').show();
					$('#main_alert').html(lang_invalid_user_or_password);
					break;
				case 'user_not_found': // User Not Found
					$('#main_alert').show();
					$('#main_alert').html(lang_invalid_user_or_password);
					break;
				case 'user_not_activated': // User Not Activated
					$("#login_form").submit();
					break;
				case 'phone_not_activated': // Phone Not Activated
					$("#login_form").submit();
					break;
				case 'mail_not_activated': // Mail Not Activated
					$('#main_alert').show();
					$('#main_alert').html(lang_email_not_activated);
					break;
				case 'account_not_activated': // Account Not Activated by Office
					$('#main_alert').show();
					$('#main_alert').html(lang_account_not_activated);
					break;
				default: // Error
					$('#main_alert').show();
					$('#main_alert').html(lang_error);
			}
		});
	}
}

// Activate Tabs
function activate_tabs () {
	if (total_items == 1) {
		$('div.item_details:first').show();
	}
	
	$(".tab_content").hide(); // Hide all content
	
	$.each($('ul.tabs'), function(key, value) { 
		$(value).find('li:first').addClass("active").show(); // Activate first tab
	});
	
	$.each($('div.tab_container'), function(key, value) { 
		$(value).find('div:first').show(); // Show first tab content
	});
	
	// On Click Event
	$("ul.tabs li").click(function() {
		$.each($(this).parent().find('li'), function(key, value) { 
			$(value).removeClass("active"); // Remove any "active" class
		});
		
		var tmp_nm = $(this).parent().attr('id');
		tmp_nm = tmp_nm.substring(5);
		
		var activeTab = $(this).find("span").attr("id"); // Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); // Fade in the active ID content
		
		$.each($('#cont_' + tmp_nm).find('div.tab_content'), function(key, value) { 
			if (activeTab != '#' + $(value).attr("id")) $(value).hide(); // Hide all tab content
		});
		
		$(this).addClass("active"); // Add "active" class to selected tab
		return false;
	});
}

// View Details
function view_details (obj) {
	$.each($('div.item_details'), function(key, value) {
		if ($(value).attr("name") != $(obj).next().attr("name")) {
			$(value).slideUp(); // Hide all tab content
		}
	});
	
	if ($(obj).next().is(':hidden') ) {
		$(obj).next().slideDown();
	} else {
		$(obj).next().slideUp();
	}
}

// Input Box Only Numbers
function onlyNumbers(e){
    var keynum;
    var keychar;
	
	// Internet Explorer
    if (window.event) {
        keynum = e.keyCode;
    }
	
	// Netscape / Firefox / Opera
    if (e.which) { 
        keynum = e.which;
    }
	
	// Calculate Sum
	window.setTimeout(function(){ calculate_sum(); }, 1);
	
	// Allowed Characters
    if((keynum == 8 || keynum == 9 || keynum == 46 || (keynum >= 35 && keynum <= 40) || (event.keyCode >= 96 && event.keyCode <= 105)))
		return true;
	
	// Char
    keychar = String.fromCharCode(keynum);
	
	// Return Result
    return !isNaN(keychar);
}

// Calculate Sum
function calculate_sum () {
	var sum = 0;
	
	$.each($('#accounts_list input'), function(key, value) { 
		sum += Number(value.value);
	});
	
	$('#money_sum').html(sum);
}

// Scratch Recharge
function scratch_recharge (obj) {
	var send_status = true; // Send Status
	
	// Check Code
	if (jQuery.trim($('#scratch_code').val()) == '') {
		$('#scratch_code').addClass('wrong_input');
		$('#alert_area').html(lang_fill_required_fields);
		send_status = false;
	} 
	
	// Check Captcha
	if (jQuery.trim($('#captcha').val()) == '') {
		$('#captcha').addClass('wrong_input');
		$('#alert_area').html(lang_fill_required_fields);
		send_status = false;
	} else if (jQuery.trim($('#captcha').val()).length != 4 || !is_numeric(jQuery.trim($('#captcha').val()))) {
		$('#captcha').addClass('wrong_input');
		$('#alert_area').html(lang_captcha_not_correct);
		send_status = false;
	}
	
	if (send_status) {
		// Clear Alert Area
		$('#alert_area').html('');
		
		// Show Loading
		$('.loader').show();
		
		// Disable Button
		$(obj).attr('disabled', true);
		
		// Request Registration Check Page
		$.post ('scripts/scratch_check.php', $("#scratch_recharge_form").serialize(),
		function (data) {
			// Hide Loading
			$('.loader').hide();
			
			// Enable Button
			$(obj).attr('disabled', false);
			
			// Data
			switch (data) {
				case 'session_time_out': // Session time Out
					document.location = 'index.php';
				case 'incorrect_captcha': // Incorrect Captcha
					$('#captcha').addClass('wrong_input');
					$('#alert_area').html(lang_captcha_not_correct);
					reload_captcha();
					break;
				case 'incorrect_phone': // Incorrect Phone
					$('#alert_area').html(lang_phone_not_correct);
					reload_captcha();
					break;
				case 'incorrect_code': // Incorrect Code
					$('#scratch_code').addClass('wrong_input');
					$('#alert_area').html(lang_incorrect_scratch_code);
					reload_captcha();
					break;
				case 'code_used_by_user': // Code Used by User
					$('#alert_area').html(lang_code_used_by_user);
					reload_captcha();
					break;
				case 'code_used_by_other': // Code Used By Other User
					$('#alert_area').html(lang_code_used_by_other);
					reload_captcha();
					break;
				case 'card_inactive': // Card Inactive
					$('#alert_area').html(lang_inactive_card);
					reload_captcha();
					break;
				case 'incorrect_brand': // Incorrect Brand
					$('#alert_area').html(lang_incorrect_brand);
					reload_captcha();
					break;
				case 'error': // Error
					$('#alert_area').html(lang_error);
					reload_captcha();
					break;
				default: // Success
					$('#text_div').html('<span class="large green">' + $('#service_type option:selected').text() + ' ' + lang_recharged + ' ' + data + ' ' + lang_gel + '</span>');
					$('#tools_div').html('<input type="button" class="red_btn" value="' + lang_back + '" onclick=document.location="index.php?page=recharge_account_with_scratch" />');
			}
		});
	}
}

// Payment Recharge
function payment_recharge (obj) {
	var send_status = true; // Send Status
	var amount = $('#amount').val() * 100;
	
	// Check Amount
	if (jQuery.trim($('#amount').val()) == '') {
		$('#amount').addClass('wrong_input');
		$('#alert_area').html(lang_fill_required_fields);
		send_status = false;
	}
	
	// Check Captcha
	if (jQuery.trim($('#captcha').val()) == '') {
		$('#captcha').addClass('wrong_input');
		$('#alert_area').html(lang_fill_required_fields);
		send_status = false;
	} else if (jQuery.trim($('#captcha').val()).length != 4 || !is_numeric(jQuery.trim($('#captcha').val()))) {
		$('#captcha').addClass('wrong_input');
		$('#alert_area').html(lang_captcha_not_correct);
		send_status = false;
	}
	
	if (send_status) {
		// Clear Alert Area
		$('#alert_area').html('');
		
		// Show Loading
		$('.loader').show();
		
		// Disable Button
		$(obj).attr('disabled', true);
		
		// Request Registration Check Page
		$.post ('scripts/payment_check.php', { 'phone_number': $('#phone_number').val(), 'captcha': $('#captcha').val(), 'amount': $('#amount').val() },
		function (data) {
			// Hide Loading
			$('.loader').hide();
			
			// Enable Button
			$(obj).attr('disabled', false);
			
			// Data
			switch (data) {
				case 'session_time_out': // Session time Out
					document.location = 'index.php';
				case 'incorrect_captcha': // Incorrect Captcha
					$('#captcha').addClass('wrong_input');
					$('#alert_area').html(lang_captcha_not_correct);
					break;
				case 'incorrect_amount': // Incorrect Amount
					$('#amount').addClass('wrong_input');
					$('#alert_area').html(lang_amount_not_correct);
					break;
				case 'large_amount': // Large Amount
					$('#amount').addClass('wrong_input');
					$('#alert_area').html(lang_large_amount);
					break;
				case 'success': // Success
					if ($('#contract_id').val() == 0 || $('#contract_id').val() == 1) {
						document.location = 'https://sb3d.georgiancard.ge/payment/start.wsm?lang=' + lang + '&merch_id=F7B1A4A84F71723E19BFECECFAB65352&back_url_s=' + escape('https://online.magticom.ge') + '&back_url_f=' + escape('https://online.magticom.ge') + '&o.amount=' + amount + '&o.phone=' + $('#phone_number').val();
					} else if ($('#contract_id').val() == 2) {
						document.location = 'https://sb3d.georgiancard.ge/payment/start.wsm?lang=' + lang + '&merch_id=982EAEDF35EB9984C65ADA210FDFDDB7&back_url_s=' + escape('https://online.magticom.ge') + '&back_url_f=' + escape('https://online.magticom.ge') + '&o.amount=' + amount + '&o.phone=' + $('#phone_number').val() + '&o.accountId=99';
					} else if ($('#contract_id').val() == 6) {
						document.location = 'https://sb3d.georgiancard.ge/payment/start.wsm?lang=' + lang + '&merch_id=6EAE620DFBC96E40F3F5C81ECE4C65D2&back_url_s=' + escape('https://online.magticom.ge') + '&back_url_f=' + escape('https://online.magticom.ge') + '&o.amount=' + amount + '&o.phone=' + $('#phone_number').val();
					} else if ($('#contract_id').val() == 14) {
						document.location = 'https://sb3d.georgiancard.ge/payment/start.wsm?lang=' + lang + '&merch_id=1C9A69BF67EFE76DF904E83BF18F76A5&back_url_s=' + escape('https://online.magticom.ge') + '&back_url_f=' + escape('https://online.magticom.ge') + '&o.amount=' + amount + '&o.phone=' + $('#phone_number').val();
					}
					
					break;
				default: // Error
					$('#alert_area').html(lang_error);
			}
			
			reload_captcha();
		});
	}
}

// Goto Recharge
function goto_scratch (obj) {
	var mobile_id = obj.id.split('_');
	$('#scratch_form_' + mobile_id[1]).submit();;
}

// Goto Details
function goto_payment (obj) {
	var mobile_id = obj.id.split('_');
	$('#payment_form_' + mobile_id[1]).submit();;
}

// Goto Details
function goto_details (obj) {
	var mobile_id = obj.id.split('_');
	$('#details_form_' + mobile_id[1]).submit();;
}

// Get Details
function get_details (obj) {
	var send_status = true; // Send Status
	var date_type = 'last_day';
	
	if ($('#last_week').attr('checked')) {
		date_type = 'last_week';
	}
	
	// Check Captcha
	if (jQuery.trim($('#captcha').val()) == '') {
		$('#captcha').addClass('wrong_input');
		$('#alert_area').html(lang_fill_required_fields);
		send_status = false;
	} else if (jQuery.trim($('#captcha').val()).length != 4 || !is_numeric(jQuery.trim($('#captcha').val()))) {
		$('#captcha').addClass('wrong_input');
		$('#alert_area').html(lang_captcha_not_correct);
		send_status = false;
	}
	
	// If All Variables Correct
	if (send_status) {
		// Clear Alert Area
		$('#alert_area').html('');
		
		// Show Loading
		$('.loader').show();
		
		// Disable Button
		$(obj).attr('disabled', true);
		
		// Request Registration Check Page
		$.post ('scripts/details_check.php', { 'captcha': $('#captcha').val(), 'date_type': date_type },
		function (data) {
			// Hide Loading
			$('.loader').hide();
			
			// Enable Button
			$(obj).attr('disabled', false);
			
			// Data
			switch (data) {
				case 'session_time_out': // Session time Out
					document.location = 'index.php';
				case 'incorrect_captcha': // Incorrect Captcha
					$('#captcha').addClass('wrong_input');
					$('#alert_area').html(lang_captcha_not_correct);
					break;
				case 'success': // Success
					TINY.box.show({iframe:'includes/view_details.php', width:950, height:600});
					break;
				default: // Error
					$('#alert_area').html(lang_error);
			}
			
			reload_captcha();
		});
	}
}

// Start Password Recovery
function start_password_recovery (obj) {
	var send_status = true; // Send Status
	
	// Check E-Mail
	if (jQuery.trim($('#email').val()) == '') {
		$('#email').addClass('wrong_input');
		$('#alert_area').html(lang_fill_required_fields);
		send_status = false;
	} else {
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;	// E-Mail Filter
		if (!filter.test($('#email').val())) {
			$('#email').addClass('wrong_input');
			$('#alert_area').html(lang_email_not_correct);
			send_status = false;
		}
	}
	
	// Check Phone
	if (jQuery.trim($('#phone').val()) == '') {
		$('#phone').addClass('wrong_input');
		$('#alert_area').html(lang_fill_required_fields);
		send_status = false;
	} else if (jQuery.trim($('#phone').val()).length < conf_phone_min_length || jQuery.trim($('#phone').val()).length > conf_phone_max_length || !is_numeric(jQuery.trim($('#phone').val()))) {
		$('#phone').addClass('wrong_input');
		$('#alert_area').html(lang_phone_not_correct);
		send_status = false;
	}
	
	// Check Captcha
	if (jQuery.trim($('#captcha').val()) == '') {
		$('#captcha').addClass('wrong_input');
		$('#alert_area').html(lang_fill_required_fields);
		send_status = false;
	} else if (jQuery.trim($('#captcha').val()).length != 4 || !is_numeric(jQuery.trim($('#captcha').val()))) {
		$('#captcha').addClass('wrong_input');
		$('#alert_area').html(lang_captcha_not_correct);
		send_status = false;
	}
	
	// If All Variables Correct
	if (send_status) {
		// Clear Alert Area
		$('#alert_area').html('');
		
		// Show Loading
		$('.loader').show();
		
		// Disable Button
		$(obj).attr('disabled', true);
		
		// Request Registration Check Page
		$.post ('scripts/password_recovery_check.php', $("#password_recovery_form").serialize(),
		function (data) {
			// Hide Loading
			$('.loader').hide();
			
			// Enable Button
			$(obj).attr('disabled', false);
			
			// Data
			switch (data) {
				case 'success': // Success
					$("#password_recovery_form").submit();
					break;
				case 'incorrect_user': // Incorrect User
					$('#alert_area').html(lang_mail_and_phone_not_registred);
					break;
				case 'incorrect_captcha': // Incorrect Captcha
					$('#captcha').addClass('wrong_input');
					$('#alert_area').html(lang_captcha_not_correct);
					break;
				default: // Error
					$('#alert_area').html(lang_error);
			}
			
			reload_captcha();
		});
	}
}

// Confirm Password Recovery
function confirm_password_recovery (obj) {
	var send_status = true; // Send Status
	
	// Check Activation Code
	if (jQuery.trim($('#activation_code').val()) == '') {
		$('#activation_code').addClass('wrong_input');
		$('#alert_area').html(lang_fill_required_fields);
		send_status = false;
	} else if ($('#activation_code').val().length != 5) {
		$('#activation_code').addClass('wrong_input');
		$('#alert_area').html(lang_incorrect_activation_code);
		send_status = false;
	}
	
	// Password
	if (jQuery.trim($('#password').val()) == '') {
		$('#password').addClass('wrong_input');
		$('#alert_area').html(lang_fill_required_fields);
		send_status = false;
	}
	
	// Repeat Password
	if (jQuery.trim($('#repeat_password').val()) == '') {
		$('#repeat_password').addClass('wrong_input');
		$('#alert_area').html(lang_fill_required_fields);
		send_status = false;
	}
	
	// Passwords Minimum Length
	if ($('#password').val() != '' && $('#password').val().length < conf_password_min_length) {
		$('#password').addClass('wrong_input');
		$('#alert_area').html(lang_password_min_length);
		send_status = false;
	} 
	
	// Compare Passwords
	if (jQuery.trim($('#password').val()) != '' && jQuery.trim($('#password').val()) != jQuery.trim($('#repeat_password').val())) {
		$('#repeat_password').addClass('wrong_input');
		$('#alert_area').html(lang_repeat_password_not_correct);
		send_status = false;
	} 
	
	// If All Variables Correct
	if (send_status) {
		// Clear Alert Area
		$('#alert_area').html('');
		
		// Show Loading
		$('.loader').show();
		
		// Disable Button
		$(obj).attr('disabled', true);
		
		// Request Registration Check Page
		$.post ('scripts/password_recovery_check.php', $("#password_recovery_form").serialize(),
		function (data) {
			// Hide Loading
			$('.loader').hide();
			
			// Enable Button
			$(obj).attr('disabled', false);
			
			// Data
			switch (data) {
				case 'success': // Success
					$("#password_recovery_form").submit();
					break;
				case 'incorrect_activation_code': // Incorrect Activation Code
					$('#activation_code').addClass('wrong_input');
					$('#alert_area').html(lang_incorrect_activation_code);
					break;
				default: // Error
					$('#alert_area').html(lang_error);
			}
			
			reload_captcha();
		});
	}
}

// Check New Phone
function check_new_phone (obj) {
	var send_status = true; // Send Status
	
	// Check Phone
	if (jQuery.trim($('#new_phone').val()) == '') {
		$('#new_phone').addClass('wrong_input');
		$('#alert_area').html(lang_fill_required_fields);
		send_status = false;
	} else if (jQuery.trim($('#new_phone').val()).length < conf_phone_min_length || jQuery.trim($('#new_phone').val()).length > conf_phone_max_length || !is_numeric(jQuery.trim($('#new_phone').val()))) {
		$('#new_phone').addClass('wrong_input');
		$('#alert_area').html(lang_phone_not_correct);
		send_status = false;
	}
	
	// Check Captcha
	if (jQuery.trim($('#captcha').val()) == '') {
		$('#captcha').addClass('wrong_input');
		$('#alert_area').html(lang_fill_required_fields);
		send_status = false;
	} else if (jQuery.trim($('#captcha').val()).length != 4 || !is_numeric(jQuery.trim($('#captcha').val()))) {
		$('#captcha').addClass('wrong_input');
		$('#alert_area').html(lang_captcha_not_correct);
		send_status = false;
	}
	
	// If All Variables Correct
	if (send_status) {
		// Clear Alert Area
		$('#alert_area').html('');
		
		// Show Loading
		$('.loader').show();
		
		// Disable Button
		$(obj).attr('disabled', true);
		
		// Request Add New Phone Check Page
		$.post ('scripts/add_new_phone_check.php', $("#add_new_phone_form").serialize(),
		function (data) {
			// Hide Loading
			$('.loader').hide();
			
			// Enable Button
			$(obj).attr('disabled', false);
			
			// Data
			switch (data) {
				case 'success': // Success
					$("#add_new_phone_form").submit();
					break;
				case 'incorrect_phone': // Incorrect Phone
					$('#new_phone').addClass('wrong_input');
					$('#alert_area').html(lang_phone_not_correct);
					break;
				case 'incorrect_user': // Incorrect User
					$('#new_phone').addClass('wrong_input');
					$('#alert_area').html(lang_user_not_match);
					break;
				case 'incorrect_captcha': // Incorrect Captcha
					$('#captcha').addClass('wrong_input');
					$('#alert_area').html(lang_captcha_not_correct);
					break;
				case 'phone_already_added': // Phone Already Added
					$('#new_phone').addClass('wrong_input');
					$('#alert_area').html(lang_phone_already_added);
					break;
				default: // Error
					$('#alert_area').html(lang_error);
			}
			
			reload_captcha();
		});
	}
}

// Add new Phone
function add_new_phone (obj) {
	var send_status = true; // Send Status
	
	// Check Phone
	if (jQuery.trim($('#new_phone').val()) == '') {
		$('#new_phone').addClass('wrong_input');
		$('#alert_area').html(lang_fill_required_fields);
		send_status = false;
	} else if (jQuery.trim($('#new_phone').val()).length < conf_phone_min_length || jQuery.trim($('#new_phone').val()).length > conf_phone_max_length || !is_numeric(jQuery.trim($('#new_phone').val()))) {
		$('#new_phone').addClass('wrong_input');
		$('#alert_area').html(lang_phone_not_correct);
		send_status = false;
	}
	
	// Check Activation Code
	if (jQuery.trim($('#activation_code').val()) == '') {
		$('#activation_code').addClass('wrong_input');
		$('#alert_area').html(lang_fill_activation_code);
		send_status = false;
	} else if ($('#activation_code').val().length != 5) {
		$('#activation_code').addClass('wrong_input');
		$('#alert_area').html(lang_incorrect_activation_code);
		send_status = false;
	}
	
	// If All Variables Correct
	if (send_status) {
		// Clear Alert Area
		$('#alert_area').html('');
		
		// Show Loading
		$('.loader').show();
		
		// Disable Button
		$(obj).attr('disabled', true);
		
		// Request Add New Phone Check Page
		$.post ('scripts/add_new_phone_check.php', $("#new_phone_activation_form").serialize(),
		function (data) {
			// Hide Loading
			$('.loader').hide();
			
			// Enable Button
			$(obj).attr('disabled', false);
			
			// Data
			switch (data) {
				case 'success': // Success
					document.location = 'index.php?page=profile';
					break;
				break;
					case 'incorrect_activation_code': // Invalid Activation Code
					$('#alert_area').html(lang_incorrect_activation_code);
					break;
				default: // Error
					$('#alert_area').html(lang_error);
			}
		});
	}
}

// Remove Aditional Number
function remove_aditional_number (obj) {
	var send_status = true;
	
	var rem_num = obj.id.substring(4);
	
	// Check Phone
	if (rem_num == '' || rem_num.length < conf_phone_min_length || rem_num.length > conf_phone_max_length || !is_numeric(rem_num)) {
		$('#alert_area').html(lang_phone_not_correct);
		send_status = false;
	}
	
	// If All Variables Correct
	if (send_status) {
		// Clear Alert Area
		$('#alert_area').html('');
		
		// Show Loading
		$('.loader').show();
		
		// Disable Button
		$(obj).attr('disabled', true);
		
		// Set New Phone
		$('#new_phone').val(rem_num);
		
		// Request Remove Phone Check Page
		$.post ('scripts/remove_phone_check.php', $("#remove_phone_form").serialize(),
		function (data) {
			// Hide Loading
			$('.loader').hide();
			
			// Enable Button
			$(obj).attr('disabled', false);
			
			// Data
			switch (data) {
				case 'success': // Success
					$("#remove_phone_form").submit();
					break;
				default: // Error
					$('#alert_area').html(lang_error);
			}
		});
	}
}

// Remove Aditional Number
function remove_phone (obj) {
	var send_status = true; // Send Status
	
	// Check Phone
	if (jQuery.trim($('#new_phone').val()) == '') {
		$('#new_phone').addClass('wrong_input');
		$('#alert_area').html(lang_fill_required_fields);
		send_status = false;
	} else if (jQuery.trim($('#new_phone').val()).length < conf_phone_min_length || jQuery.trim($('#new_phone').val()).length > conf_phone_max_length || !is_numeric(jQuery.trim($('#new_phone').val()))) {
		$('#new_phone').addClass('wrong_input');
		$('#alert_area').html(lang_phone_not_correct);
		send_status = false;
	}
	
	// If All Variables Correct
	if (send_status) {
		// Disable Button
		$(obj).attr('disabled', true);
		
		// Request Remove Phone Check Page
		$.post ('scripts/remove_phone_check.php', $("#remove_phone_form").serialize(),
		function (data) {
			// Hide Loading
			$('.loader').hide();
			
			// Enable Button
			$(obj).attr('disabled', false);
			
			// Data
			switch (data) {
				case 'success': // Success
					$("#remove_phone_form").submit();
					break;
				break;
					case 'incorrect_activation_code': // Invalid Activation Code
					$('#alert_area').html(lang_incorrect_activation_code);
					break;
				default: // Error
					$('#alert_area').html(lang_error);
			}
		});
	}
}

// Save Profile
function save_profile (obj) {
	var send_status = true; // Send Status
	
	// If All Variables Correct
	if (send_status) {
		// Disable Button
		$(obj).attr('disabled', true);
		
		// Request Save Profile Check Page
		$.post ('scripts/profile_check.php', $("#profile_form").serialize(),
		function (data) {
			// Hide Loading
			$('.loader').hide();
			
			// Enable Button
			$(obj).attr('disabled', false);
			
			// Data
			switch (data) {
				case 'success': // Success
					$('#alert_area').html('<span class="green">' + lang_profile_saved + "</span>");
					break;
				default: // Error
					$('#alert_area').html(lang_error);
			}
		});
	}
}

// Cancel Profile
function cancel_profile (obj) {
	// Show Delete Question
	var answer = confirm(lang_delete_shure);
	
	// If Answer is True
	if (answer) {
		// Disable Button
		$(obj).attr('disabled', true);
		
		// Request Save Profile Check Page
		$.post ('scripts/cancel_profile_check.php',
		function (data) {
			// Hide Loading
			$('.loader').hide();
			
			// Enable Button
			$(obj).attr('disabled', false);
			
			// Data
			switch (data) {
				case 'success': // Success
					$('#logout_form').submit()
					break;
				default: // Error
					$('#alert_area').html(lang_error);
			}
		});
	}
}
