var u = "6480";
var uu = "6480_mini";
var placeid = "";
var rootURL = "http://channel.support.12530.com/";//根路径；
var dynamicURL = "http://my.12530.com/newchannel/orderTone/";//静态域名
//var dynamicURL = "http://channel.support.12530.com/newchannel/orderTone/";//动态域名
var branch = "newchannel/tpl/channel3/";
var ringBranch = "newchannel/tpl/ring/";
var fromServer = false;

function $(i){
    return document.getElementById(i);
}

function sendCOMBD(id){
	datetime = nowdatetime();
	window.open( dynamicURL + id +'/1/'+u+'/' + uu +'/-/-/order.htm','','width=640,height=460,toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=yes');
	return false;
}
function jump2Ring(id){
	datetime = nowdatetime();
	window.open(rootURL + ringBranch + 'pushIndex.jsp?msgid='+u+datetime+'&objname='+id+'&type=1&from='+u+'&subfrom='+placeid+'&placeid=' + uu +'','','width=640,height=460,toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=yes');
	return false;
}

function GetQueryString(name){
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return unescape(r[2]);
    }
    return null;
}

function nowdatetime(){
    Date.prototype.format = function(format){
        var o = {
            "M+": this.getMonth() + 1, //month
            "d+": this.getDate(), //day
            "h+": this.getHours(), //hour
            "m+": this.getMinutes(), //minute
            "s+": this.getSeconds(), //second
            "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
            "S": this.getMilliseconds() //millisecond
        }
        if (/(y+)/.test(format)) {
            format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        }
        for (var k in o) {
            if (new RegExp("(" + k + ")").test(format)) {
                format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
            }
        }
        return format;
    }
    var ddd = new Date();
    return ddd.format('yyyyMMddhhmmssS');
}

function arrayClone(sourceArray){
    var tempArray = new Array;
    tempArray = sourceArray.concat();
    for (var i = 0; i < sourceArray.length; i++) {
        tempArray[i] = $(sourceArray[i] + "s").innerHTML;
        $(sourceArray[i] + "s").innerHTML = "";
    }
    return tempArray.concat();
}

function looseFocus(array){
    for (var i = 0; i < array.length; i++) {
        var tmp = array[i];
        if ($(tmp).className == "current") {
            $(tmp).className = "";
        }
    }
}

function init(){
	placeid = GetQueryString('id');
    u = GetQueryString('u');
    uu = GetQueryString('uu');
	var url = window.location.href;
    if (u == null) {
		var pattern = new RegExp("/");
		var r = url.split(pattern,5);
	    if (r != null && (new RegExp('^[0-9]*$').test(r[3])) ) {
			u = unescape(r[3]);
			uu = unescape(r[4]);
		} else {
			u = "4201";
		}
    }
    if (u == "4201" && uu == null) {
        uu = "mini";
    } else if (uu == null) {
            uu = "";
        }
    if (placeid == null) {
        placeid = "";
    }
    var width = (screen.width / 2) - 60;
    var height = (screen.height / 2) - 110;
}

function doSearch(){
	var viewPage = 1;
	var keyword = document.getElementById("searchKeyword").value;
	if( keyword==null || keyword=="" ){
		alert("请输入搜索关键字！");
		return false;
	}
	keyword = keyword.replace(/\s+/g, "");
	if (keyword != "") {
		recordKeyword(keyword);
		keyword = encodeURI(keyword);
		if (fromServer) {
			window.open('http://movement.12530.com/search/' + keyword + '/' + viewPage + '/search.htm?u=' + u + '&uu=' + uu, '', 'width=' + screen.width + ',height=' + screen.height + ',toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
		}
		else {
			window.open('http://movement.12530.com/newchannel/tpl/miniHome/search.jsp?current=' + viewPage + '&keyword=' + keyword + '&u=' + u + '&uu=' + uu + '', '', 'width=' + screen.width + ',height=' + screen.height + ',toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
		}
	} else {
		window.open('http://movement.12530.com/more/155669/1/more.htm?u=' + u + '&uu=' + uu, '', 'width=' + screen.width + ',height=' + screen.height + ',toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
	}
}
function doSearchKeyword(keyword){
	var viewPage = 1;
	keyword = keyword.replace(/\s+/g, "");
	recordKeyword(keyword);
	keyword = encodeURI(keyword);

	window.open('http://movement.12530.com/search/' + keyword + '/' + viewPage + '/search.htm?u=' + u + '&uu=' + uu, '', 'width=' + screen.width + ',height=' + screen.height + ',toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
	
}

function viewPage(pageName,viewPage,id,cnStr){
	cnStr = encodeURI(cnStr);
	if (fromServer) {
		if( pageName=="fairyland.jsp" ){
			pageName = "fairyland";
		} else if ( pageName=="recommendSongList.jsp" ){
			pageName = "more";
		} else if( pageName=="recommendAlbumList.jsp" ){
			pageName = "album";
		} else if( pageName=="recommendSinger.jsp" ){
			pageName ="singers";
		}
		if (cnStr.length > 0) {
			window.location.href = '/' + pageName + '/' + id + '/' + cnStr + '/' + viewPage + '/' + pageName + '.htm?u=' + u + '&uu=' + uu;
		} else {
			window.location.href = '/' + pageName + '/' + id + '/' + viewPage + '/' + pageName + '.htm?u=' + u + '&uu=' + uu;
		}
	} else {
		window.location.href = '/newchannel/tpl/miniHome/' + pageName + '?current=' + viewPage + '&id=' + id + '&u=' + u + '&uu=' + uu + '&cnStr=' + cnStr + '';
	}
}

function jump(pageName,id,cnStr){
	cnStr = encodeURI(cnStr);
	var viewPage = $("jumpTo").value;
	if (fromServer) {
		if( pageName=="fairyland.jsp" ){
			pageName = "fairyland";
		} else if (pageName=="recommendSongList.jsp"){
			pageName = "more";
		} else if( pageName=="recommendAlbumList.jsp" ){
			pageName = "album";
		}
		if (cnStr.length > 0) {
			window.location.href = '/' + pageName + '/' + id + '/' + cnStr + '/' + viewPage + '/' + pageName + '.htm?u=' + u + '&uu=' + uu;
		} else {
			window.location.href = '/' + pageName + '/' + id + '/' + viewPage + '/' + pageName + '.htm?u=' + u + '&uu=' + uu;
		}	
	} else {
		window.location.href = '/newchannel/tpl/miniHome/' + pageName + '?current=' + viewPage + '&id=' + id + '&u=' + u + '&uu=' + uu + '&cnStr=' + cnStr + '';
	}
}

function goUrl(url,action,width,height){
	if( width==null || width==0 || height==null || height==0){
		width = screen.width;
		height= screen.height;
	}
	var left = 0;
	var top = 0;
	if( action=="open" ){
		left = screen.width/2 - width/2;
		top = screen.height/2 - height/2;
		if (fromServer) {
			if( url.indexOf("recommendSinger")!=-1 ){
				url = "/singers/32/1/singers.htm";
			}
			window.open(url + '?u=' + u + '&uu=' + uu, '', 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
		} else {
			window.open(url + '?u=' + u + '&uu=' + uu, '', 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
		}
	} else {
		if (fromServer) {
			if( url.indexOf("recommendSinger")!=-1 ){
				url = "/singers/32/1/singers.htm";
			}
			window.location.href = url + '?u=' + u + '&uu=' + uu;
		} else {
			window.location.href = url + '?u=' + u + '&uu=' + uu;
		}
	}
}
function recordKeyword(keyword){
	
	var pagefromurl = document.referrer;
	var localurl = location.href;
	
	pagefromurl = pagefromurl.split("?")[0]; 
	localurl = localurl.split("?")[0]; 
	
	keyword = encodeURI(keyword);
	
	var scripts = document.getElementsByTagName("script");
	var sobj = document.createElement('script');
	sobj.src='http://channel.support.12530.com/newchannel/tpl/c/doRecord.jsp?from=' + pagefromurl + '&url=' + localurl + '&u=' + u + '&pa1=' + keyword + '&pa10=3';
	var headobj = document.getElementsByTagName('head')[0];
	headobj.appendChild(sobj);
}
