﻿/*
$(document).ready(function(){


	// ---- Countdown timer ----

	$('#counter').countdown({
		timestamp : (new Date()).getTime() + 11*24*60*60*1000
	});


	// ---- Animations ----

	$('#links a').hover(
		function(){ $(this).animate({ left: 3 }, 'fast'); },
		function(){ $(this).animate({ left: 0 }, 'fast'); }
	);

	$('footer a').hover(
		function(){ $(this).animate({ top: 3 }, 'fast'); },
		function(){ $(this).animate({ top: 0 }, 'fast'); }
	);


	// ---- Using Modernizr to check if the "required" and "placeholder" attributes are supported ---- 

	if (typeof(Modernizr) != 'undefined' && !Modernizr.input.placeholder) {
		$('.email').val('Input your e-mail address here...');
		$('.email').focus(function() {
			if($(this).val() == 'Input your e-mail address here...') {
				$(this).val('');
			}
		});
	}

	// for detecting if the browser is Safari
	var browser = navigator.userAgent.toLowerCase();

	if(typeof(Modernizr) != 'undefined' && !Modernizr.input.required || (browser.indexOf("safari") != -1 && browser.indexOf("chrome") == -1)) {
		$('form').submit(function() {
			$('.popup').remove();
			if(!$('.email').val() || $('.email').val() == 'Input your e-mail address here...') {
				$('form').append('<p class="popup">Please fill out this field.</p>');
				$('.email').focus();
				return false;
			}
		});
		$('.email').keydown(function() {
			$('.popup').remove();
		});
		$('.email').blur(function() {
			$('.popup').remove();
		});
	}


});
*/

$(document).ready(function(){
	 $('#myModal').on('hidden.bs.modal', f_modalCloseEvent);
});

var g_defaultError = "网络连接异常，稍后重试。";

function f_sendAjax(url, data, succFuc) {
	var deviceId = $.md5(navigator.userAgent);
	if(!f_isEmpty(g_curUserName)) {
		deviceId = g_curUserName;
	}
	url = url + "&channel_id=4001&device_id=" + deviceId;
	$.ajax( { 
	  url: url,
	  data:data, 
	  type:'post', 
	  dataType:'json', 
	  success: succFuc, 
	  error : function() {
		alert(g_defaultError); 
	  } 
	});
}

function f_checkRequestStatus(data) {
	var result = false;
	if(data) {
		if(data.return_code == 0) {
			result = true;
		}else {
			f_alertError(data.return_msg);
		}
	}
	else {
		f_alertError(g_defaultError);
	}
	
	return result;
}

function f_alertSuccess(content) {
	alert(content);
}

function f_alertError(content) {
	alert(content);
}

function f_isEmpty(str) {
	var result = false;
	if(typeof(str) == "undefined" || str == null || str == "" || str == "null") {
		result = true;
	}
	return result;
}

function f_isMobileValid(phone) {  
	var flag = false;  
	var message = "";  
	var myreg = /^(((1[3-9]{1}[0-9]{1}))+\d{8})$/;  
	if (f_isEmpty(phone)) {
		message = "手机号码不能为空！";  
	}
	else if (phone.length != 11) {  
		message = "请输入11位手机号码！";  
	} 
	else if (!myreg.test(phone)) {  
		message = "请输入有效的手机号码！";  
	}
	else {  
		flag = true;  
	}
	
	if (!flag) {  
		f_alertError(message);  
	}
	
	return flag;  
}

function f_modalCloseEvent() {}

