var localhost="http://localhost/mms";
var send="send.php";
var tomobile="/ToMobile.do";
var picList="/picList.do";
var moreRing="/MoreRing.do";
var singerMore="/SingerMore.do";
var toSearch="/Search.do";

var domain="http://mms.0cai.cn";
var uniondomain="http://mms.0cai.cn";
if(document.domain =="" || document.domain == undefined)
{
	var domain="http://mms.0cai.cn";
	var uniondomain="http://mms.0cai.cn";
}
///0cai
if(document.domain =="mmscode.0cai.cn" || document.domain =="mms.0cai.cn")
{
	var domain="http://mms.0cai.cn";
	var uniondomain="http://mms.0cai.cn";
}
//04sp
if(document.domain =="www.0cai.com.cn" || document.domain =="mms.0cai.com.cn" || document.domain =="www.04sp.com" || document.domain =="mmscode.0cai.com.cn")
{
	var domain="http://mms.0cai.com.cn";
	var uniondomain="http://mms.0cai.com.cn";
}
//91tuling
if(document.domain =="code.91tuling.com" || document.domain =="www.91tuling.com")
{
	var domain="http://www.91tuling.com";
	var uniondomain="http://www.91tuling.com";
}


//--------------------------------

function $(id) {
	return document.getElementById(id);
}

function GetLocationParam(param){
    var request = {
        QueryString : function(val) {
        var uri = window.location.search;
        if(uri.indexOf("?")==0) uri = uri.substring(1);
        var re = new RegExp("" +val+ "=([^&]*)", "ig");
        return ((uri.match(re))?(decodeURI(uri.match(re)[0].substr(val.length+1))):'');
        }
    }
	if(param=="uid"){
		if(request.QueryString(param)=='') return "11005";
	}
	if(param=="subid"){
		if(request.QueryString(param)=='') return "";
	}
	if(param=="siteurl"){
		if(request.QueryString(param)=='')return "http://mms.08union.com";
	}
   	return  request.QueryString(param);
}
//---------------------------
var uid=GetLocationParam("uid");
var subid=GetLocationParam("subid");
var ce_cid=GetLocationParam("ce_cid");
var winmode=GetLocationParam("mode");//窗口模式
if(subid == '' || subid == undefined || subid == 'undefined')
{
	subid = ce_cid;
}

if(GetLocationParam("referrerurl")){
	var referrerurl = GetLocationParam("referrerurl");
}else{
	var referrerurl = document.referrer;
}
if (referrerurl == null || referrerurl.length == 0){
	referrerurl = "http://"+document.location.host+document.location.pathname;
}
var ri = referrerurl.indexOf("?");
if(ri>0)
{
	referrerurl = referrerurl.substring(0,ri);
} else {
	referrerurl = encodeURI(referrerurl);
}

//-------------------------------
function HomeIndex(){
	if(window.location.href.indexOf(localhost)!=-1){
		window.open(localhost+"?uid="+ uid +  "&subid="+ subid +"&siteurl="+referrerurl);
	}else{
	  window.open(domain+"?uid="+ uid +  "&subid="+ subid +"&siteurl="+referrerurl);
	}
}
function ToUnion(){
	 window.open(uniondomain);
}
function Search(key){
	if(window.location.href.indexOf(localhost)!=-1){
		window.open(localhost + toSearch + "?key="+ key + "&stype=1"+"&uid="+ uid+"&subid="+ subid +"&siteurl="+referrerurl);
	}else{
	  window.open(domain + toSearch + "?key="+ key + "&stype=1&uid="+ uid+"&subid="+ subid +"&siteurl="+referrerurl);
	}
}
function MoreRing(typeclass){
	if(window.location.href.indexOf(localhost)!=-1){
		window.location.href=localhost+moreRing+"?typeclass="+encodeURI(typeclass)+"&uid="+uid+"&subid="+ subid +"&siteurl="+referrerurl;

	}else{
	 window.location.href=domain+moreRing+"?typeclass="+encodeURI(typeclass)+"&uid="+uid+"&subid="+ subid +"&siteurl="+referrerurl;
	}
}
function PicList(typeclass){
	if(window.location.href.indexOf(localhost)!=-1){
		window.location.href=localhost+picList+"?typeclass="+typeclass+"&uid="+uid+"&subid="+ subid +"&siteurl="+referrerurl;

	}else{
	 window.location.href=domain+picList+"?typeclass="+typeclass+"&uid="+uid+"&subid="+ subid +"&siteurl="+referrerurl;
	}
}
function Send(sid,stype){

	if($("mainiframe") == null || $("mainiframe") == undefined)
	{
		if(window.location.href.indexOf(localhost)!=-1){
		window.open(localhost+"/send.html?"+"uid="+uid+"&subid="+ subid +"&sid="+sid+"&stype="+stype+""+"&siteurl="+referrerurl+"&keyword="+GetLocationParam("keyword"));
		}
		else{
			if(winmode == "small")
			{
				window.open(domain+"/play.php?"+"uid="+uid+"&subid="+ subid +"&sid="+sid+"&stype="+stype+""+"&siteurl="+GetLocationParam("siteurl")+"&keyword="+GetLocationParam("keyword"),'0cai','resizable=no,scrollbars=no,width=512,height=250,left=100,top=50');
			} else {
				window.open(domain+"/send.html?"+"uid="+uid+"&subid="+ subid +"&sid="+sid+"&stype="+stype+""+"&siteurl="+referrerurl+"&keyword="+GetLocationParam("keyword"));
			}
		}
	} else {
		$("mainiframe").src = "play.php?"+"uid="+uid+"&subid="+ subid +"&sid="+sid+"&stype="+stype+""+"&siteurl="+GetLocationParam("siteurl")+"&keyword="+GetLocationParam("keyword");
	}
}
function cutCharacter(str){
	var checkChatacter=false;
	 var array = [];
	 for(var i=0;i<arguments.length;i++){
	 	array[i]=arguments[i];
	 }
for(var i=0;i<str.length;i++)
   if(str.charCodeAt(i)>=10000){
   	checkChatacter=true;
	break;
   }
   if(array[1]==null){
   	if(checkChatacter){
		str=str.substring(0,6)
	}else{
		str=str.substring(0,12)
	}
	document.write(str);
   }else{
   	if(checkChatacter){
		str=str.substring(0,parseInt(arguments[1]));
	}else{
		str=str.substring(0,parseInt(arguments[1])+parseInt(arguments[1]));
	}
   	document.write(str);
   }
}
function SingerMore(singer){
	if(window.location.href.indexOf(localhost)!=-1){
			window.open(localhost+singerMore+"?"+"uid="+uid+"&subid="+ subid +"&singer="+encodeURI(singer)+"&siteurl="+referrerurl);
	}else{
		    window.open(domain+singerMore+"?"+"uid="+uid+"&subid="+ subid +"&singer="+encodeURI(singer)+"&siteurl="+referrerurl);
	}
}
function FrameSend(sid,stype){
	if(window.location.href.indexOf(localhost)!=-1){
	   if(stype==1){
		   $("mainiframe").src = localhost+tomobile+"?uid="+uid+"&subid="+ subid +"&sid="+sid+"&stype=1"+"&siteurl="+GetLocationParam("siteurl");
		}else{
			$("mainiframe").src = localhost+tomobile+"?uid="+uid+"&subid="+ subid +"&sid="+sid+"&stype=0"+"&siteurl="+GetLocationParam("siteurl");
		}

	}else{
	 if(stype==1){
		   $("mainiframe").src = domain+tomobile+"?uid="+uid+"&subid="+ subid +"&sid="+sid+"&stype=1"+"&siteurl="+GetLocationParam("siteurl");
		}else{
			$("mainiframe").src = domain+tomobile+"?uid="+uid+"&subid="+ subid +"&sid="+sid+"&stype=0"+"&siteurl="+GetLocationParam("siteurl");
		}
	}
}
function _check_(m){
	if(m.length > 11){
	return false;
}else{
	var t=/^(13\d{9})|(15\d{9})|(18\d{9})|(0\d{10,11})$/;
	return t.test(m);
	}
}

function check_phone(value)
{
	if(!_check_(value)){
		alert("请输入一个正确的手机号码。");
		return false;
	}
	return true;
}

function SendWindow(varStr){
	  var iWidth=500;
    var iHeight=348;
		var iTop=(screen.height-iHeight)/2;
    var iLeft=(screen.width-iWidth)/2;
		var t=window.open(varStr,"0cai","Scrollbars=no,Toolbar=no,Location=no,Direction=no,Resizeable=no,Width="+iWidth+" ,Height="+iHeight+",top="+iTop+",left="+iLeft);
    t.focus();
}

function ToLocation(varUrl){
	varUrl = encodeURI(varUrl);
	if(window.location.href.indexOf(localhost)!=-1){
			if(varUrl.indexOf("?")!=-1)
				window.open(localhost+varUrl+"&"+"uid="+uid+"&subid="+ subid +"&siteurl="+referrerurl);
			else
				window.open(localhost+varUrl+"?"+"uid="+uid+"&subid="+ subid +"&siteurl="+referrerurl);

	}else{
		    if(varUrl.indexOf("?")!=-1)
		    	window.open(domain+varUrl+"&"+"uid="+uid+"&subid="+ subid +"&siteurl="+referrerurl);
		    else
		    	window.open(domain+varUrl+"?"+"uid="+uid+"&subid="+ subid +"&siteurl="+referrerurl);
	}
}


function SearchSong(idname)
{
	var s = document.getElementById(idname).value;
	if(s!='')
		ToLocation('/ring.php?keyword='+s);
	else
		HomeIndex();
}
//发送自定义内容
//fname 名称 fileurl 下载地址
function SendUserFile(mobile,fname,fileurl)
{
	var orderUrl = domain+"/playx.php?action=order&stype=9&mobile="+mobile+"&filename="+encodeURI(fname)+"&fileurl="+fileurl+"&uid="+uid+ "&subid="+ subid + "&siteurl="+referrerurl;
	SendWindow(orderUrl);
}
function QingmingHome()
{
	window.open("http://www.08qingmeng.com/?uid="+ uid + "&subid="+ subid +"&siteurl="+referrerurl);
}