﻿//公共资源类定义 start
function Resource(){
	//校验是否为广东移动用户号段，正则表达式


	this.regExp=/^13[4-9]{1}[\d]{8}$|^14[7]{1}[\d]{8}$|^15[0|1|2|7|8|9]{1}[\d]{8}$|^18[0-9]{1}\d{8}$/;	
};
var resource = new Resource();
//公共资源类定义 end

var ajaxPlayAll = new RBTAjax();
function listentone(checkboxname)
{
      var hotmusic = document.getElementsByName(checkboxname);
      var toneChannelCodeArray = new Array();
      var toneChannelCode = "";
      var n=0;
      for(var i=0;i<hotmusic.length;i++)
      {
          if(hotmusic[i].value != undefined&&hotmusic[i].value !="")
          {
             toneChannelCodeArray[n] = hotmusic[i].value;
             toneChannelCode = toneChannelCode + hotmusic[i].value + "#";
             n=n+1;
          }
      }
      toneChannelCode = toneChannelCode.substring(0,toneChannelCode.length-1);
      var maxNum = $('maxnumlistentone').value;
      if(n>maxNum)
      {
            var j= n-maxNum;
            toneChannelCode = "";
            for(;j<n;j++)
            {
                 toneChannelCode = toneChannelCode + toneChannelCodeArray[j] + "#";
            } 
            toneChannelCode = toneChannelCode.substring(0,toneChannelCode.length-1);
      }
      if(toneChannelCode=="")
      {
          alert("\u8BF7\u5148\u9009\u62E9\u6B4C\u66F2\u518D\u64AD\u653E\uFF01");
          return;
      }
      var playAllURL = "/cl/listen/player.screen";
      
      var ajaxPlayURL = "/cl/listen/ajaxplayer.screen";
      var param = "toneinfo="+toneChannelCode;
      ajaxPlayAll.isExec=false;
      ajaxPlayAll.isAsynch=false;
      ajaxPlayAll.doPost(ajaxPlayURL,param);
      var m_win_player = window.open(playAllURL,"mwlisten","width=850,height=650,top=100,left=100");
      m_win_player.focus();
}
var ajaxPitchOn = new RBTAjax();
function listenSelectTone(cbNameArray)
{
      var hotmusic = cbNameArray;
      var toneChannelCodeArray = new Array();
      var toneChannelCode = "";
      var n=0;
      for(var i=0;i<hotmusic.length;i++)
      {
          if(hotmusic[i].checked)
            {
                  toneChannelCodeArray[n] = hotmusic[i].value;
                  toneChannelCode = toneChannelCode + hotmusic[i].value + "#";
                  n=n+1;
            } 
      }
      toneChannelCode = toneChannelCode.substring(0,toneChannelCode.length-1);
      var maxNum = $('maxnumlistentone').value;
      if(n>maxNum)
      {
          var j= n-maxNum;
          toneChannelCode = "";
          for(;j<n;j++)
          {
                 toneChannelCode = toneChannelCode + toneChannelCodeArray[j] + "#";
          } 
          toneChannelCode = toneChannelCode.substring(0,toneChannelCode.length-1);
      }
      if(toneChannelCode=="")
      {
          alert("\u8BF7\u5148\u9009\u62E9\u6B4C\u66F2\u518D\u64AD\u653E\uFF01");
          return;
      }
      var playPitchOnURL = "/cl/listen/player.screen";
      
      var ajaxPitchOnURL = "/cl/listen/ajaxplayer.screen";
      var param = "toneinfo="+toneChannelCode;
      ajaxPitchOn.isExec=false;
      ajaxPitchOn.isAsynch=false;
      ajaxPitchOn.doPost(ajaxPitchOnURL,param);
      var m_win_player = window.open(playPitchOnURL,"mwlisten","width=850,height=650,top=100,left=100");
      m_win_player.focus();
}
function querySinger(catalogType,singerType,flag,category,singerSex,firstname,secondname)
{
    document.myform.catalogType.value =catalogType;
    document.myform.singerType.value =singerType;
    document.myform.flag.value =flag;
    document.myform.category.value =category;
    document.myform.singerSex.value =singerSex;
    document.myform.firstname.value =firstname;
    document.myform.secondname.value =secondname;
    document.myform.buff.value ="0";
    document.myform.action="/cl/querysingerinfos.do";
    document.myform.submit();
}
function queryByType(category,flag,firstname,secondname)
{
    document.myform.category.value =category;
    document.myform.flag.value =flag;
    document.myform.firstname.value =firstname;
    document.myform.secondname.value =secondname;
    document.myform.singerSex.value ="";
    document.myform.buff.value ="0";
    document.myform.action="/cl/showtone.do";
    document.myform.submit();
}
function searchSinger(singer){    
    document.searchKeyToneName.action= "/cl/querytonebytype.do";
    document.searchKeyToneName.condition.value=singer;
    document.searchKeyToneName.field.value = "singer";
    document.searchKeyToneName.submit();
}
function detailcheck(url)
{
    document.mytoneform.action= url;
    document.mytoneform.submit();
}
function  backgroundImageCache(){
        var ua = navigator.userAgent.toLowerCase();   
        var isIE6 = ua.indexOf("msie 6") > -1;
        
        
        if(isIE6){   
            try{   
               document.execCommand("BackgroundImageCache", false, true);   
           }catch(e){}   
       }  
}
var ajaxUtilTone=new RBTAjax();
 ajaxUtilTone.isExec=false;
 ajaxUtilTone.isAsynch=false;
function listenRankAllTone(checkboxname)
{
      var hotmusic = document.getElementsByName(checkboxname);
      var toneChannelCodeArray = new Array();
      var toneChannelCode = "";
      var n=0;
      for(var i=0;i<hotmusic.length;i++)
      {  
                toneChannelCodeArray[n] = hotmusic[i].value;
                toneChannelCode = toneChannelCode + hotmusic[i].value + "#";
                n=n+1;
      }
      toneChannelCode = toneChannelCode.substring(0,toneChannelCode.length-1);
      var maxNum = $('#maxnumlistentone').value;
      if(n>maxNum)
      {
            var j= n-maxNum;
            toneChannelCode = "";
            for(;j<n;j++)
            {
                  toneChannelCode = toneChannelCode + toneChannelCodeArray[j] + "#";
            } 
            toneChannelCode = toneChannelCode.substring(0,toneChannelCode.length-1);
     }
      if(toneChannelCode=="")
      {
          alert("没有可播放的歌曲..");
          return;
      }
      var playURL = "/cl/listen/player.screen";
      
      var ajaxPlayURL = "/cl/listen/ajaxplayer.screen";
      var param = "toneinfo="+toneChannelCode;
      ajaxUtilTone.isExec=false;
      ajaxUtilTone.isAsynch=false;
      ajaxUtilTone.doPost(ajaxPlayURL,param);
      var m_win_player = window.open(playURL,"mwlisten","width=850,height=650,top=100,left=100");
      m_win_player.focus();
}
  function playmusic(toneChannelCode)
  {
          if(toneChannelCode!=="")
          {
              var playURL = "/cl/listen/player.screen";
              var ajaxPlayURL = "/cl/listen/ajaxplayer.screen";
              var param = "toneinfo="+toneChannelCode;
              ajaxUtilTone.doPost(ajaxPlayURL,param);
              var m_win_player = window.open(playURL,"mwlisten","width=850,height=650,top=100,left=100");
              m_win_player.focus();
        }
 }
function listenShockTone(ringid,channelCode,operType)
{
    var requrl="/cl/browseshocktone.do?ringid="+ringid+"&channelCode="+channelCode;
    window.open(requrl,"","width=650,height=500,top=100,left=100");
}
  
function listenTonebox(toneBoxCode,channelCode,operType)
{
    var requrl="/cl/querytoneboxdetail.do?flag=0&toneBoxCode="+toneBoxCode+"&channelCode="+channelCode;
    window.open(requrl,"","width=650,height=500,top=100,left=100");
}



function clickLogin(url)
{
    var strUrl;
    strUrl = "/cl/getvalidcode.screen?tmpurl=" + url;
    openwindow(strUrl,"validcode",400,300);
}




function openwindow( url, winName, width, height) 
{
xposition=0; yposition=0;

if ((parseInt(navigator.appVersion) >= 4 ))
{
xposition = (screen.width - width) / 2;
yposition = (screen.height - height) / 2;
}
theproperty= "width=" + width + "," 
+ "height=" + height + "," 
+ "screenx=" + xposition + "," 
+ "screeny=" + yposition + "," 
+ "left=" + xposition + "," 
+ "top=" + yposition; 
var chdwin=window.open( url,winName,theproperty );
chdwin.focus();
}




function headerLogin()
{
var phoneNumber = document.getElementById("userPhoneNumber").innerHTML.replace(/<.+?>/gim,"");
document.getElementById("loginLink").innerHTML="您好，"+phoneNumber+"用户";
document.getElementById("loginDivide").className="hidden";
document.getElementById("loginDivide").innerHTML="";
document.getElementById("registerOrLogout").innerHTML="[安全退出]";
document.getElementById("registerOrLogout").href="/cl/logout.screen";
document.getElementById("myToneLink").href="/cl/querypersonaltone.do?type=tone";
headerLogin = null;
}
function searchToneName(toneName)
{
    document.searchKeyToneName.field.value = "tonename";
    document.searchKeyToneName.condition.value = toneName;
    document.searchKeyToneName.action="/cl/querytonebytype.do";
    document.searchKeyToneName.submit();
}
var isSearchSubmit = true;
function initSearchDiv(){

    var textObj = document.searchform.searchtext;
    var value = textObj.value;
    var textObj = document.searchform.searchtext;
    var inputShowName = document.searchform.inputShowName.value;
    if("请输入歌曲名称或歌手名称" != value && "请输入歌曲名称" != value && "请输入歌手名称" != value && inputShowName != value)
    {
        textObj.className = "notNullText";
    }
    else{
        textObj.className = "nullText";
    }
    var searchIndex;
    var field = document.searchform.field.value;
    if("tonename" == field){
        searchIndex = 1;
    }
    else if("singer" == field){
        searchIndex = 2;
    }
    else{
        searchIndex = 0;
    }
    var searchTypeObjs = document.getElementById("search").childNodes[0].childNodes[0].childNodes;
    if(searchTypeObjs.length ==2)
    {
        searchIndex -=1;
    }
    clickSearch(searchTypeObjs[searchIndex]);
}


function addOnLoadEvent(fun){
    if(window.attachEvent){
        window.attachEvent("onload",fun);
    }
    else if(window.addEventListener){
       window.addEventListener("load",fun,false);
    }
}

function clickSearch(obj){
    var searchLabels = obj.parentNode.childNodes;
    var labelLength = searchLabels.length;
    var searchTypeId;
    var searchClassType;
    var searchType = obj.innerHTML.replace(/<.+?>|\s/gim,"");
    var inputShowName = document.searchform.inputShowName.value;
    switch (searchType) {
       case "全部":
           searchTypeId = 1;
           if(null == inputShowName || "" == inputShowName){
               textFormat("请输入歌曲名称或歌手名称");
           }else{
               textFormat(inputShowName);
           }
           document.searchform.field.value = "all";
           break;
       case "歌名":
           searchTypeId = 2;
           if(null == inputShowName || "" == inputShowName){
               textFormat("请输入歌曲名称");
           }else{
               textFormat(inputShowName);
           }
           document.searchform.field.value = "tonename";
           break;
       case "歌手":
           searchTypeId = 3;
           textFormat("请输入歌手名称");
           document.searchform.field.value = "singer";
           break;
       default:
           return;
    }
    switch (labelLength) {
       case 2:
           searchClassType = searchTypeId - 1;
           break;
       case 3:
           searchClassType = searchTypeId;
           break;
       default:
           return;
    } 
    var qType = document.searchform.qType;
    if(typeof qType == "object")
    {
        qType.value = searchTypeId;
    }
    var searchClass = "searchBg" + searchClassType;
    for(var i=0;i<labelLength;i++)
    {  
        if(i+1 != searchClassType)
        {
            searchLabels[i].className = "searchLink";
        }
    }
    document.getElementById("search").className = searchClass;
    obj.className = "searchActive";
    obj.blur();
}

function textFormat(content){
    var textObj = document.searchform.searchtext;
    var value = textObj.value;
    textObj.value = content;
    textObj.className = "nullText";
}

function setFont(obj){
    if("nullText" == obj.className){
        var inputShowName = document.searchform.inputShowName.value;
        if(inputShowName != obj.value){
            obj.value = "";
        }else{
            obj.select();
        }
        obj.className = "notNullText";
    }else{
        obj.select();
    }
}


function searchClick(obj){
    if(isSearchSubmit){
        if(isCanSearchSubmit()){
            isSearchSubmit = false;
            document.searchform.submit();
            obj.className = "notCanSearch";
        }
    }
}

function onSearchSubmit(){ 
    if(isSearchSubmit){ 
        if(isCanSearchSubmit()){
            isSearchSubmit = false;
            var searchButton = document.searchform.searchbutton;
            searchButton.className = "notCanSearch";
        }else{
            return false;
        }
    }else{
        return false;
    }
}

String.prototype.trim = function(){
    return this.replace(/(^\s*)|(\s*$)/g, "");
};

function isCanSearchSubmit(){
    //var qType = document.searchform.qType;
	var field = document.searchform.field.value;
    var searchTextObj = document.searchform.searchtext;
    var val = searchTextObj.value.trim();
    var inputShowName = document.searchform.inputShowName.value;
    if(null != inputShowName && "" != inputShowName && inputShowName == val)
    {
        searchTextObj.className = "notNullText";
    }
/*    if(typeof qType == "object")
    {*/
        var replaceRegExp = /[()+\.]+/g;
        var IllegalString = "\\<>\'\"`~!#@$%^&*{}|:?\-_=\/,";
        if("nullText" == searchTextObj.className || val=="")
        {
            var clew;
            /*switch (document.searchform.qType.value){
                case "1": 
                    clew = "请输入歌曲名称或歌手名称";
                    break;
                case "2":
                    clew = "请输入歌曲名称";
                    break;
                case "3":
                    clew = "请输入歌手名称";
                    break;
                default:
                    clew = "请输入歌曲名称或歌手名称";
            }*/
			if(field == "all")
			{
				clew = "请输入歌曲名称或歌手名称";
			}
			else if(field == "tonename")
			{
				clew = "请输入歌曲名称";
			}
			else if(field == "singer")
			{
				clew = "请输入歌手名称";		
			}
			else
			{
				clew = "对不起，搜索关键字不能为空，请重新输入关键字。"
			}
            alert(clew);
            document.searchform.searchtext.focus();
            return false;
        }
        for (var j=0;j<=val.length-1;j++) {
            if (IllegalString.indexOf(val.charAt(j))>=0) {
                alert("您输入的内容含有非法字符，请重新输入。");
                document.searchform.searchtext.focus();
                document.searchform.searchtext.select();
                return false;
            }
        }
        var tempval = val.replace(replaceRegExp, "")
        if("" == tempval.trim()){
            alert("您输入的内容含有非法字符，请重新输入。");
            document.searchform.searchtext.focus();
            document.searchform.searchtext.select();
            return false;
        }

/*    }
    else
    {
        var IllegalString = "\`~!#$%^&*()+{}|\\:\"<>?-_=/,\'";
        if("nullText" == searchTextObj.className || val=="")
        {
            alert("对不起，搜索关键字不能为空，请重新输入关键字。");
            document.searchform.searchtext.focus();
            return false;
        }
        for (var j=0;j<=val.length-1;j++) {
            if (IllegalString.indexOf(val.charAt(j))>=0) {
                alert("关键字包含以下无效字符："+IllegalString);
                document.searchform.searchtext.focus();
                return false;
            }
        }    

        document.searchform.condition.value=val;
    }*/
    document.searchform.action="/cl/rbt/search/search.screen";
    return true;
}
function isEmpty(field)
{
    field = trimEnter(field);
    return ((field == null) || (field.length == 0) || myTrim(field)=="");
}

function trimEnter(input)
{    
    var tmp = "";
    
    for (var begin=0;begin <input.length;begin++)
    {    
        var chrCode = input.charCodeAt(begin);
        if((chrCode!=13)&&(chrCode!=10))
        tmp+=input.charAt(begin);
        
    }
    return tmp;
}
function containInvalidChar(field)
{
    for (i = 0; i < field.length; i++)
    {
        var c = field.charAt(i);

        if( c == '&' || c == '<'
           || c == '>' || c == '"'
           || c == '@' || c == '#'|| c == '\\'|| c == '`'
           || c == '$' || c == '^' || c == '\/' || c == '~' || c == '%' || c == "'")
        {
            return true;
        }
    }

    return false;
}
function trim(strValue)
{
    var iLTR, jRTL;
    var chr;

    
    for( iLTR = 0; iLTR < strValue.length; iLTR++ )
    {
        chr = strValue.charAt(iLTR) ;
        if( chr != " " ) break;
    }

    if( iLTR == strValue.length ) return "";

    
    for( jRTL = strValue.length - 1; jRTL >= 0; jRTL-- )
    {
        chr = strValue.charAt(jRTL);
        if( chr != " " ) break;
    }
    return strValue.substring(iLTR, jRTL + 1);
}

function myTrim(str)
{
    var end = false;
    var ch;

    while(!end)
    {
        if (str.length == 0) break;
        ch = str.charAt(0);

        if (ch == ' ')
        {
            str = str.substring(1,str.length);
        }
        else
        {
            end = true;
        }
    }

    end = false;

    while(!end)
    {
        if (str.length == 0)
        {
            break;
        }

        ch = str.charAt(str.length-1);

        if (ch == ' ')
        {
            str = str.substring(0,str.length-1);
        }
        else
        {
            end = true;
        }
    }

    return str;
}
backgroundImageCache();

function Random(start,end,offset,offsetbase){
	
	this.start=start;	
	this.base=offsetbase;
	this.end=end;
	this.offset = offset;
	this.index={mi:0,ci:0};
	this.arrayData = new Array();
	this.init();
		
}
Random.prototype={
	
	init:function(){	
		for(var i=0,v=this.start;v<=this.end;i++,v+=this.offset){
			this.arrayData[i]=v;	
		}
		var len= this.arrayData.length;
		var m= (len%2==0)?-1:0;
		this.index.mi=Math.floor(len/2)+m;	
		//alert(this.arrayData.length+" "+this.index.mi+" "+m);
	},
	next:function(){
		//alert(this.index.ci+this.index.mi-1);
		var index=this.index.ci+this.index.mi;
		//alert(index);
		var cv=this.arrayData[index];
		//alert(index+" "+cv);
		if(isNaN(cv)){
			//alert(cv);
			this.index.ci=0;
			cv=this.arrayData[this.index.ci+this.index.mi];	
		}
		if(this.index.ci>0){
			this.index.ci = -this.index.ci;
		}else if(this.index.ci<0){
			this.index.ci = -this.index.ci+1;
		}else{
			this.index.ci=1;
		}
		
		var os = Math.floor(this.base*Math.random());
		var t =Math.random()>0.4?1:-1;
		cv+=os*t;
		return cv<this.start?5:cv>this.end?this.end:cv;
	}		
}

