var jQuery = $;
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') {
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 1 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString();
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

//弹出登录窗口
function divshow(showmsg) {
	document.getElementById("id1").style.height = window.parent.screen.height + "px";
	document.getElementById("id1").style.width = window.parent.screen.width + "px";
	document.getElementById("id1").style.display = 'block';
	document.getElementById("pop_content").style.display = 'block';
}

//隐藏登录窗口
function divhide(){   
	document.getElementById("id1").style.display = 'none'
	document.getElementById("pop_content").style.display = 'none'
}

var num = 59;
var aa;
function excuteSend() {   
	var sendResults = xmlHttp.responseText;
	var promt;
	if (sendResults == "sendYes") {
		//window.parent.ShowAlert('提示框','<B>wap信息下发成功',200,100);
		alert("WAP信息下发成功");
		num = 59;
		//clearInterval(aa); 
		//aa=setInterval(showPromt,1000);
	} else {
		//var obj = document.getElementById("promt");
		//obj.style.display="block";
		//obj.innerHTML = "发送失败";
		alert("发送失败");
	}
}
  
function showPromt() {
	var obj = document.getElementById("promt");
	alert("obj="+obj);
    if (num >= 0) {	
    	obj.innerHTML = "";
    	obj.style.display="block";
    	//obj.innerHTML = "如果您在一分钟之内没有收到，请重新再试一次。"+"还剩<font color='red'>"+num+"</font>秒";
    	num--;
    } else {
    	clearInterval(aa);
    	obj.style.display="none";
    	num = 3;
    }	
}

//登录
function mobileServiceLogin() {			
	if (!trimAll(frmPersonLoginMobile.mobile.value)) {
		alert("请填写您的手机号码");
		frmPersonLoginMobile.mobile.focus();
		return false;
	}
	if (frmPersonLoginMobile.mobile.value.length != 11) {
		alert("您输入的手机号码长度不对,请重新输入");
		var r_date = new Date();
		frmPersonLoginMobile.imgValid.src = "/validCode.jsp?onlyNumber=true&r=" + r_date;
		frmPersonLoginMobile.mobile.focus();
		return false;
	}
	if (!trimAll(frmPersonLoginMobile.password.value)) {
		alert("请填写您的密码");
		frmPersonLoginMobile.password.focus();
		return false;
	}
	if (frmPersonLoginMobile.password.value.length != 6) {
		alert("您输入密码长度不对,请重新输入");
		var r_date = new Date();
		frmPersonLoginMobile.imgValid.src = "/validCode.jsp?onlyNumber=true&r=" + r_date;
		frmPersonLoginMobile.password.focus();
		return false;
	}
	if (!trimAll(frmPersonLoginMobile.validCode.value)) {
		alert("请填写验证码");
		frmPersonLoginMobile.validCode.focus();
		return false;
	}
	if (frmPersonLoginMobile.validCode.value.length != 4) {
		alert("您输入的验证码长度不对,请重新输入");
		var r_date = new Date();
		frmPersonLoginMobile.imgValid.src = "/validCode.jsp?onlyNumber=true&r=" + r_date;
		frmPersonLoginMobile.validCode.value = "";
		frmPersonLoginMobile.validCode.focus();
		return false;
	}
	frmPersonLoginMobile.action="/login.do?callback=mobileServiceLoginCallBack";
	frmPersonLoginMobile.submit();
	return true;	
}

function mobileServiceLoginCallBack(success, type, message) {
	if(success) {
		//var selectList=document.getElementById("serviceList");
		//var selectIndex = selectList.selectedIndex;
		//window.location.href="/mobileService/mobileService.jsp?selectIndex="+selectIndex;
		//selectList.options[selectIndex].selected();
		window.location.reload();
	} else {
		alert(message);
		if(type == "mobile") {
			var r_date = new Date();
			frmPersonLoginMobile.imgValid.src = "/validCode.jsp?onlyNumber=true&r=" + r_date;
			frmPersonLoginMobile.mobile.select();
			frmPersonLoginMobile.mobile.focus();
			frmPersonLoginMobile.password.value = "";
			frmPersonLoginMobile.validCode.value = "";
		} else if(type == "password") {
			var r_date = new Date();
			frmPersonLoginMobile.imgValid.src = "/validCode.jsp?onlyNumber=true&r=" + r_date;
			frmPersonLoginMobile.password.value = "";
			frmPersonLoginMobile.password.focus();
			frmPersonLoginMobile.validCode.value = "";
		} else if(type == "validcode") {
			var r_date = new Date();
			frmPersonLoginMobile.imgValid.src = "/validCode.jsp?onlyNumber=true&r=" + r_date;
			frmPersonLoginMobile.validCode.value = "";
			frmPersonLoginMobile.validCode.focus();
		}
	}		
}
	
//用户退出
function toLogoutForMobile() {
	var f = frames["_index_login_iframe_mobile"];
	window.location.href = "/login.do?action=logout&callback=toLogoutCallBackForMobile";
	window.top.location.reload();
}
/*
function toLogoutCallBackForMobile(success, type, message) {
	alert(success);
	if(success) {
		window.location.href = path + "golde100/login_index.jsp";
	} else {
		alert("退出时发生错误，请稍后再试");
	}
}*/
			
function enterSubmit() {
	if (window.event.keyCode == 13) {
		if (mobileServiceLogin()) {
			frmPersonLoginMobile.action="/login.do?callback=mobileServiceLoginCallBack";
			frmPersonLoginMobile.submit();
		}
	}			
}

function handleStateChange4() {
  	if(xmlHttp.readyState==4) {
 		if(xmlHttp.status==200) {
 			excuteSend();
 		}
  	}
}

function createXMLHttpRequest() {
	if(window.ActiveXObject) {
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	} else if(window.XMLHttpRequest) {
		xmlHttp=new XMLHttpRequest();
	}
}

//发送
function sendWap(types) {
	var obSSOcookie = jQuery.cookie('ObSSOCookie');
	if(obSSOcookie != null && obSSOcookie!="" && obSSOcookie!="loggedout" && obSSOcookie!="loggedoutcontinue") {
		createXMLHttpRequest();
	   	if (null == types || "" == types) {
	   		alert("请选择下载类型");
	   		return false;
	   	} else {
		   	var names = "";
		   	var urls = "";
		   	//飞信
			if ('feixin' == types) {
				names = "feixin";
				urls = "a.10086.cn:7070/j/317";
			}
			//139邮箱
			if ('mail' == types) {
				names = "mail";
				urls = "a.10086.cn:7070/j/325";
			}
			//音乐随身听
			if ('music' == types) {
				names = "music";
				urls = "a.10086.cn:7070/j/316";
			}
			//手机地图
			if ('map' == types) {
				names = "map";
				urls = "a.10086.cn:7070/j/321";
			}
			//信息管家
			if ('information' == types) {
				names = "information";
				urls = "a.10086.cn:7070/j/322";
			}
			//号簿管家
			if ('hbgj' == types) {
				names = "hbgj";
				urls = "a.10086.cn:7070/j/323";
			}
			//手机视频
			if ('tv' == types) {
				names = "tv";
				urls = "tv";
			}
			//手机证券
			if ('paper' == types) {
				names = "paper";
				urls = "a.10086.cn:7070/j/324";
			}
			//手机阅读
			if ('read' == types) {
				names = "read";
				urls = "a.10086.cn:7070/j/318";
			}
			//掌上精彩
			if ('hand' == types) {
				names = "hand";
				urls = "jcxz.js.i139.cn";
			}
			//g+游戏包
			if ('g' == types) {
				names = "g";
				urls = "g";
			}
			//掼蛋网客户端
			if ('gdw' == types) {
				names = "gdw";
				urls = "gdw";
			}
			//g+游戏包g+至尊游戏包
			if ('g1' == types) {
				names = "g1";
				urls = "g1";
			}
			//g+游戏包热门游戏
			if ('g2' == types) {
				names = "g2";
				urls = "g2";
			}
			//g+游戏包暴风城
			if ('g3' == types) {
				names = "g3";
				urls = "g3";
			}
			//g+游戏包i游戏
			if ('g4' == types) {
				names = "g4";
				urls = "g4";
			}
			//g+游戏包游戏发烧包
			if ('g5' == types) {
				names = "g5";
				urls = "g5";
			}
			//g+游戏包电影大片
			if ('g6' == types) {
				names = "g6";
				urls = "g6";
			}
			//g+游戏包旺旺包
			if ('g7' == types) {
				names = "g7";
				urls = "g7";
			}
			//g+游戏包经典游戏
			if ('g8' == types) {
				names = "g8";
				urls = "g8";
			}
			//g+游戏包好又多
			if ('g9' == types) {
				names = "g9";
				urls = "g9";
			}
			//g+游戏包游戏狂人
			if ('g10' == types) {
				names = "g10";
				urls = "g10";
			}
			//g+游戏包最佳游戏
			if ('g11' == types) {
				names = "g11";
				urls = "g11";
			}
			//g+游戏包尽情玩吧
			if ('g12' == types) {
				names = "g12";
				urls = "g12";
			}
			//g+游戏包嘉年华	
			if ('g13' == types) {
				names = "g13";
				urls = "g13";
			}
			//g+游戏包私藏经典
			if ('g14' == types) {
				names = "g14";
				urls = "g14";
			}
			//g+游戏包游戏区
			if ('g15' == types) {
				names = "g15";
				urls = "g15";
			}
			//g+游戏包热门游戏
			if ('g16' == types) {
				names = "g16";
				urls = "g16";
			}
			//手机营业厅
			if('sjyyt'==types){
				names="sjyyt";
				urls="sjyyt";
			}
			//随e行宽带
			if('suiex'==types){
				names="suiex";
				urls="suiex";
			}
		  	var url = "/wapservice?serviceList=" + urls + "&serviceName=" + names + "&act=sendWap&downloadMode=1";
		  	xmlHttp.onreadystatechange = handleStateChange4;
		  	xmlHttp.open("GET", url, true);
		  	xmlHttp.send(null);
	   	}
	} else {
		divshow();
		return;
	}
}


