
var UA = navigator.userAgent;
if(/MSIE 6/.test(UA)){
	UA = 'ie';
}else if(/Gecko/.test(UA)){
	UA = 'gecko';
}else if(/MSIE 7/.test(UA)){
	UA = 'ie7';
}else if(/MSIE 8/.test(UA)){
	UA = 'ie8';
}else if(/MSIE 9/.test(UA)){
	UA = 'ie9';
}else if(/Opera/.test(UA)){
	UA = 'opera';
}
try{
document.domain="crossmo.com";
}catch(e)
{}
var ErrArray=new Array();
ErrArray[0]="如果您还没登录或者连接手机，请登录或连接手机。";
ErrArray[1]="此mp3文件可能不被工具支持或者复制到手机时出现错误，请复制上面的错误信息以及您下载的文件和使用的机型<a href='sendmsg.php?userid=1' target='_blank'>反馈给crossmo</a>。";
ErrArray[2]="下载文件到手机过程中出现错误，请检查手机是否有足够空间，手机与PC连接是否正常。如果故障未解除，请把下载的文件和使用的机型，以及上面的错误信息<a href='sendmsg.php?userid=1' target='_blank'>反馈给crossmo</a>";
ErrArray[3]="您没有安装十字猫软件，请点此<a href='tools/mycrossmo_setup.exe'><font color=red><b>立即安装</b></font></a>。";
ErrArray[4]="您需要确认当前连接的手机型号。Crossmo给每款手机提供特定的文件以保证用户获得最佳体验，请在列表中确认你当前连接的手机。如果列表是空的，请<a href='mymobile.php' target='_blank'>打开设置页</a>进行设置，设置完毕后请回本页重试。<br><br>如果从设置页找不到您的机型，请<a href='sendmsg.php?userid=1' target='_blank'>反馈给crossmo</a>，我们将完善对您手机的支持。";
ErrArray[5]="请检查是否从手机端设置了连接类型。如果多次尝试不成功，建议关掉浏览器后再打开本页进行尝试。<br><br>设置方法请查看 <a href='help' target='_blank'>帮助</a>.";
ErrArray[6]="系统没有设定您下载的文件应该存储到您手机上的位置，此问题需要crossmo解决，请把您下载的文件和您的机型<a href='sendmsg.php?userid=1' target='_blank'>反馈给crossmo</a>。";
ErrArray[7]="需要安装诺基亚的驱动软件。您可以从<a href='http://www.nokia.com.cn/cn/support/software/pcsuite/index.shtml' target='_blank'>诺基亚站点</a>下载适合您机型的PC套件程序(约20M)。";
ErrArray[8]="需要安装摩托手机的驱动软件，您可以<a href='/tools/Motorola_EU_Driver_Installation.msi'>从这里下载</a>驱动软件。";
ErrArray[9]="Microsoft ActiveSync没有安装，请<a href='http://www.microsoft.com/china/windowsmobile/activesync/activesync45.mspx' target='_blank'>点此</a>下载安装";
ErrArray[10]="没有找到与PC连接的手机,现在请将手机与PC连接。<br><br>如果手机已经连接，请检查手机端的设置。诺基亚手机推荐PC套件方式，摩托linux机型和索爱机型推荐USB数据连接方式。更详细设置方法请查看 <a href='help' target='_blank'>帮助</a>";
ErrArray[11]="文件较大时，下载到手机需要花费较长时间。<br><br>时间长短取决于与Crossmo连接的网速和手机的处理能力。<b><font color=red>请不要打开新下载页或刷新本页</font></b>。";
ErrArray[12]="需要下载的文件链接打开失败，可能文件已经被删除。您可以尝试使用其他手机来下载，或者<a href='sendmsg.php?userid=1' target='_blank'>反馈给crossmo</a>";

function DrawImage(ImgD,flag)
{
	var image=new Image();
	
	var iwidth = ImgD.getAttribute("iwidth");
	var iheight = ImgD.getAttribute("iheight");
	image.src=ImgD.src;
	ImgD.style.display = "inline";

	if(image.width>0 && image.height>0)
	{	
		if(arguments[1])
		{
			ImgD.width=iwidth;
			ImgD.height=(image.height*iwidth)/image.width;
			ImgD.style.width=iwidth+"px";
			ImgD.style.height=(image.height*iwidth)/image.width+"px";
			
			ImgD.parentNode.style.width = iwidth+"px";
			ImgD.parentNode.style.height = iheight+"px";
			ImgD.parentNode.style.display = "block";
			
			ImgD.parentNode.style.overflow = "hidden";
			if(ImgD.height>=iheight)
			{
				ImgD.parentNode.scrollTop = (ImgD.height-iheight)/2;
			}
			else
			{
				ImgD.style.marginTop = Math.floor((iheight-ImgD.height)/2)+"px";
			}
		}
		else
		{	
			if(image.width/image.height>= iwidth/iheight)
			{
				ImgD.width=iwidth;
				ImgD.height=(image.height*iwidth)/image.width;
				ImgD.style.width=iwidth+"px";
				ImgD.style.height=(image.height*iwidth)/image.width+"px";
				ImgD.style.marginTop = Math.floor((iheight-(image.height*iwidth)/image.width)/2)+"px";
			}
			else
			{
				ImgD.width=(image.width*iheight)/image.height;
				ImgD.height=iheight;
				ImgD.style.height=iheight+"px";
				ImgD.style.width=(image.width*iheight)/image.height+"px";		
			}
		}
	}
}

//调用：<img src="图片" iwidth="预定宽度"  iheight="预定高度" onload="javascript:DrawImage(this)">

//获取弹出窗口实际尺寸和位置
function fGetViewPortSize() 
{
	var myWidth = 0, myHeight = 0, myLeft = 0, myTop = 0;
	if(typeof(window.innerWidth ) == 'number' && typeof(window.pageXOffset ) == 'number') 
	{//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
		myTop = window.pageYOffset;
		myLeft = window.pageXOffset;
	} 
	else
	{
		if(document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight )) 
		{//IE 6
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
			myTop = document.documentElement.scrollTop;
			myLeft = document.documentElement.scrollLeft;
		} 
		else 
		{
			if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
			{ //IE 4
				myWidth = document.body.clientWidth;
				myHeight = document.body.clientHeight;
				myTop = document.body.scrollTop;
				myLeft = document.body.scrollLeft;
			}
		}
	}
	return [myWidth, myHeight, myLeft, myTop];
} 


function bgshow(rect)
{
	var bgobj = $("#PageCover");
	var screenHeight = rect[1];
	var h = $('#wrap').height(); 
	var screenWidth = rect[0];
	var w = $('#wrap').width();	
	var panwidth = ((w<screenWidth) ? screenWidth: w)+"px";
	var panheight = ((h<screenHeight) ? screenHeight: h)+"px";
	bgobj.contents().find("body").css("background-color","#333333");
	bgobj.css("width", panwidth);	
	bgobj.css("height", panheight);	
	bgobj.show();	
	
}

//弹出登录框
function logpanshow(flag)
{
  try
  {	
	var rect = fGetViewPortSize();
	var screenHeight = rect[1];
	var screenWidth = rect[0];
	var w = $('#wrap').width();	
	var scrollLeft = rect[2];
	var scrollTop = rect[3];
	bgshow(rect);

	var objstyle = $('#toolspan');
	var obj = objstyle.contents();
	obj.find("#login").css("display", "none");
	obj.find("#loginpan").css("display","block");
	obj.find("#uid").attr("value","");
	obj.find("#pwd").attr("value","");
	obj.find("#reginfo").html("");

	obj.find("#youke").hide();
	obj.find("#download").hide();
	
	var panleft = parseInt((w<screenWidth)?(screenWidth-obj.find("#loginpan")[0].offsetWidth)/2 : (w-obj.find("#loginpan")[0].offsetWidth)/2 )+"px";
	var pantop = parseInt((screenHeight-obj.find("#loginpan")[0].offsetHeight)/2+scrollTop)+"px";	
	objstyle.css("left",panleft);
	objstyle.css("top",pantop);
	objstyle.width(obj.find("#loginpan")[0].offsetWidth);
	objstyle.height(obj.find("#loginpan")[0].offsetHeight);	
	obj.find("#uid")[0].focus();
  }
  catch(e)
  {
	 setTimeout("logpanshow("+flag+")",1000);   
  }
}

//用户登录
function userlogin(code)
{
	var obj = $('#toolspan').contents();
	if(obj.find("#saveusername").attr("checked"))
	{
		var pwd = 1
	}
	else
	{
		var pwd = 0;
}

	var userarr = {"UserName":encodeURIComponent(obj.find("#uid").attr("value")), 
				"Password":encodeURIComponent(obj.find("#pwd").attr("value")),
				"SavePwd":pwd
				};
	agent.call("","CommonUserLogin","callback_userlogin",userarr,1);
	obj.find("#reginfo").html("正在登录，请稍候...");

	this.callback_userlogin = function(userstatus) { //回调函数

	    if (userstatus[0]) {
	        $("#toolspan").css("left", "-9999px");
	        obj.find("#reginfo").html("");
	        $("#PageCover").hide();
	        if (code) {
	            eval(code);
	        }
	        else {

	            window.location.reload(true);
	        }
	    }
	    else {
	        if (userstatus[1] != "激活") {
	            obj.find("#reginfo").html(userstatus[1]);
	        }
	        else {
	            window.location.reload();
	        }
	    }
	}
}
//快速注册
function userlogin_fast(code) {
    var obj = $('#toolspan').contents();
    if (obj.find("#fast_saveusername").attr("checked")) {
        var pwd = 1
    }
    else {
        var pwd = 0;
    }
    var userarr = { "UserName": encodeURIComponent(obj.find("#fast_uid").attr("value")),
        "Password": encodeURIComponent(obj.find("#fast_pwd").attr("value")),
        "SavePwd": pwd
    };
    agent.call("", "CommonUserLogin", "callback_userlogin", userarr, 1);
    obj.find("#fast_reginfo").html("正在登录，请稍候...");

    this.callback_userlogin = function(userstatus) { //回调函数
        // alert(userstatus);
        if (userstatus[0]) {
            $("#toolspan").css("left", "-9999px");
            obj.find("#fast_reginfo").html("");
            $("#PageCover").hide();
            if (code) {
                eval(code);
            }
            else {
                var sid = $('#softid').val();
              //  alert(sid);
                contentphone(sid, 3);
                setTimeout("window.location.reload(true);", 2000);

            }
        }
        else {

            obj.find("#fast_reginfo").html(userstatus[1]);
        }
    }
}
//用户注册
function userreg()
{
	window.open("../reg.php","_blank");	
	$("#toolspan").css("left","-9999px");
	$("#PageCover").hide();
}


//关闭小窗口
function closewindow()
{
	$("#toolspan").contents().find("#loginpan").hide();
	$("#toolspan").contents().find("#phonesel").hide();
	$("#toolspan").css("left","-9999px");
	$("#PageCover").hide();
}


function showflash(src,id,width,height,flashvars,wmode)
{
	if(!wmode)
	{
		wmode = "transparent";
	}
	var str = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"  codebase="http://fpdownload.macromedia.com/get/flashplayer/current/licensing/win/install_flash_player_active_x.exe#version=9,0,115,0" width="'+width+'" height="'+height+'"  id="'+id+'" align="middle">';
	str += '<param name="allowScriptAccess" value="sameDomain" />';
	str += '<param name="movie" value="'+src+'" />';
	str += '<param name="play" value="true" />';
	str += '<param name="loop" value="true" />';
	str += '<param name="menu" value="false" />';
	str += '<param name="quality" value="high" />';
	str += '<param name="wmode" value="'+wmode+'" />';
	str += '<param name="allowFullScreen" value="true" />';
	str += '<param name="bgcolor" value="#ffffff" />';
	str += '<param name="flashvars" value="'+flashvars+'" />';
	str += '<embed src="'+src+'" loop="true" menu="false" quality="high" wmode="'+wmode+'" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="'+id+'" flashvars="'+flashvars+'" allowFullScreen="true" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	str += '</object>';
	document.write(str);
}


function indexuserlogin()
{
	if($("#saveusername").attr("checked"))
	{
		var pwd = 1
	}
	else
	{
		var pwd = 0;
    }
	//alert("");
	var userarr = {	"UserName":encodeURIComponent($("#username").attr("value")), 
					"Password":encodeURIComponent($("#userpwd").attr("value")),
					"SavePwd":pwd
				};
	agent.call("","CommonUserLogin","callback_userlogin",userarr,1);
	$("#logininfo").html("登录中，请稍候..");
	
	this.callback_userlogin = function(userstatus){//回调函数
		if(userstatus[0])
		{
			if(UA=="ie" || UA=="ie7" || UA=="ie8" || UA=="ie9")
			{
				setInterval("window.location.reload(true)",1);
			}
			else
			{
				window.location.reload(true);
			}
		}
		else
		{
			if(userstatus[1]=="激活")
			{
				//alert("您的账号需要激活！");
			//	location.href="activechose.php?t=mobile&u="+userarr["UserName"];
			}
			else
			{
				$("#logininfo").html(userstatus[1]);
			}
		}
	}
}


function pwdalert()
{
	if($("#saveusername").attr("checked"))
	{
		alert("密码将被保存一周，网吧等公共场所请勿使用该功能");	
	}
}


function switchtab(obj, idbase, idxcount, classname)
{
	height = $("#"+idbase+"_c").height();
	for(i=0;i<=idxcount;i++)
	{
		if(obj.id == idbase+"_"+i)
		{
			$("#"+idbase+"_"+i).attr("class",classname+1);
			$("#"+idbase+"_c")[0].scrollTop = i*height;
		}
		else
		{
			$("#"+idbase+"_"+i).attr("class",classname+2);
			
		}
	}
	
	
}

//flash调用函数
function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}


function callflash(str,param) {

   eval('thisMovie("flplayer").'+str+'("'+param+'");');

}

//保存播放时间
function savetime(zsj, cid)
{
	
	if(typeof(cid)=="undefined")
	{
		cid=globalcontentid;
	}
	agent.call("", "ajax_savetime", "", zsj,cid);
}

function collectcontent(contentid,cateid)
{
	if(contentid>0 )
	{
		agent.call("","ajax_CollectContent","callback_collectcontent",contentid,cateid);
	}
	
	this.callback_collectcontent = function(val)
	{ //回调函数
		if(val[0])
		{
			alert(val[1]);
		}
		else
		{
			alert(val[1])	
			
		}
	} 
	
}

function btn_confirm(e) { 
	event.returnValue = confirm("确认是否删除？"); 
} 


function resetuserphone(aId,aType,re) {
  //  alert("");
	$.cookie('PhoneID', null, { path: '/', domain: 'crossmo.com', secure: false});
	$.cookie('ConnectType', null, { path: '/', domain: 'crossmo.com', secure: false});	
	$.cookie('PhoneName', null, { path: '/', domain: 'crossmo.com', secure: false});
	//$.cookie('PhoneID', null, { path: '/', secure: false});
	//$.cookie('ConnectType', null, { path: '/', secure: false});	
	//$.cookie('PhoneName', null, { path: '/', secure: false});	
	contentphone(aId,aType,re);

}



window.onresize = function() {
	if($("#PageCover").css("display")!="none")
	{
		rect = fGetViewPortSize() ;
		//bgshow(rect)
	

	var screenHeight = rect[1];
	var screenWidth = rect[0];
	var w = $('#wrap').width();	
	var scrollLeft = rect[2];
	var scrollTop = rect[3];
	bgshow(rect);

	var objstyle = $('#toolspan');
	var obj = objstyle.contents();
//	
	
	var panleft = parseInt((w<screenWidth)?(screenWidth-obj.find("#loginpan")[0].offsetWidth)/2 : (w-obj.find("#loginpan")[0].offsetWidth)/2 )+"px";
	var pantop = parseInt((screenHeight-obj.find("#loginpan")[0].offsetHeight)/2+scrollTop)+"px";	
	objstyle.css("left",panleft);//alert(panleft);
	objstyle.css("top",pantop);
	objstyle.width(obj.find("#loginpan")[0].offsetWidth);
	objstyle.height(obj.find("#loginpan")[0].offsetHeight);	
	//obj.find("#uid")[0].focus();		
		
	}

}

