﻿String.prototype.trim   =   function()   
{       
      return   this.replace(/(^\s*)|(\s*$)/g,   "");   
} 


/**绝对位置*/
function getAbsolutePosition(element) {
    if ( element ) {

        var offsetTop = element.offsetTop;
        var offsetLeft = element.offsetLeft;
        var offsetWidth = element.offsetWidth;
        var offsetHeight = element.offsetHeight;
        while( element = element.offsetParent ) {
             offsetTop += element.offsetTop;
             offsetLeft += element.offsetLeft;
        } 

        var posi = new Object();
        posi.top = offsetTop;
        posi.left = offsetLeft;
        posi.width = offsetWidth;
        posi.height = offsetHeight;

        return posi;

    }
}


var Rectangle = function(x,y,width,height)
{
    this.x=x;this.y=y;this.width=width;this.height=height;
}

var getElementRectangle=function(elemObj)
{
    if(elemObj==undefined)
    {
        return null;
    } 
    var rect=null;
    if(navigator.userAgent.indexOf("MSIE")!=-1)
    {
        var orect=elemObj.getBoundingClientRect();
        var x=orect.left;
        var y=orect.top;
        var width=orect.right-orect.left;
        var height=orect.bottom-orect.top;
        rect=new Rectangle(x,y,width,height);
    }
    else
    {
        var orect=document.getBoxObjectFor(elemObj);
        var x=orect.x;
        var y=orect.y;
        var width=orect.width;
        var height=orect.height;
        rect=new Rectangle(x,y,width,height);
    }
    return rect;
} 

//参数为id字符串或字符串数组
function ShowTab(selected,unSelected,type)
{
//    document.getElementById(unSelected).style.backgroundImage = 'url(images/top_tab_gray.gif)';
    document.getElementById(unSelected).className = 'indexBackGround sprite-top_tab_gray';
    document.getElementById(unSelected).style.color='#000000';
//    document.getElementById(selected).style.backgroundImage = 'url(images/top_tab.gif)';
    document.getElementById(selected).className = 'indexBackGround sprite-top_tab';
    document.getElementById(selected).style.color='#FFFFFF';
    document.getElementById('hiddenSearchType').value = type;
    
    if(type =='0')
    {
        document.getElementById('txtQuery').value = '请输入您要找的歌曲或者歌手名';
    }
    else
        document.getElementById('txtQuery').value = '请输入您要找的音乐盒名称';
}

function OnTabClick(selectedId,unSelectedId,selectedBgImg,unSelectedBgImg)
{
    document.getElementById(selectedId).style.backgroundImage='url('+selectedBgImg+')';
    document.getElementById(unSelectedId).style.backgroundImage='url('+unSelectedBgImg+')';
}

function showHotImgdown(item){
    if(item.style)
	    item.style.backgroundPosition = 'bottom';
	else
	    event.srcElement.style.backgroundPosition = 'bottom';
}
function showImgdown(item){
    if(item.style)
	    item.style.backgroundPosition = 'top';
	else
	    event.srcElement.style.backgroundPosition = 'top';
}
//Add by fengxu
function showHotPosition(item)
{
    ShowTopMenuHotStyle(item);
//    if(document.readyState=="complete")
//    {
//        var height = parseInt(item.currentStyle.height);
//        var x = parseInt(item.currentStyle.backgroundPositionX);
//        var y = parseInt(item.currentStyle.backgroundPositionY);
//        item.style.backgroundPosition = x+'px '+(y-height)+'px';
//    }
}
function showPosition(item)
{
    ShowTopMenuStyle(item);
//    if(document.readyState=="complete")
//    {
//        var height = parseInt(item.currentStyle.height);
//        var x = parseInt(item.currentStyle.backgroundPositionX);
//        var y = parseInt(item.currentStyle.backgroundPositionY);
//        item.style.backgroundPosition = x+'px '+(y+height)+'px';
//    }
}

function ShowTopMenuStyle(item)
{
    item.className = item.className.replace(/_hot$/,"");
}
function ShowTopMenuHotStyle(item)
{
    if(null == item.className.match(/_hot$/))
        item.className = item.className +'_hot';
}

function MakCurrentPageHot(elementId)
{
    if(document.readyState!="uninitialized")
    {
        var oElement=document.getElementById(elementId); 
        oElement.onmouseout='';
        oElement.detachEvent('onmouseout',ShowTopMenuStyle);
        oElement.onmouseover='';
        oElement.detachEvent('onmouseout',ShowTopMenuHotStyle);       
        
        ShowTopMenuHotStyle(oElement);
    }
    else
    {
        window.setTimeout("MakCurrentPageHot('"+elementId+"')", 1);
    }
}

/////
//
function ReSizeDlg()
{
    var iframe = document.getElementById("ifcover");
    var cover = document.getElementById("cover");
    
    if(iframe && cover)
    {
        iframe.style.pixelTop = document.body.scrollTop;
        iframe.style.pixelLeft = document.body.scrollLeft;
        iframe.style.width = document.body.clientWidth;
        iframe.style.height = document.body.clientHeight;
        
        cover.style.pixelTop = document.body.scrollTop;
        cover.style.pixelLeft = document.body.scrollLeft;
        cover.style.width = document.body.clientWidth;
        cover.style.height = document.body.clientHeight;
    }
    else
    {
        return;
    }
}   

/********以下是用户登陆所用****************************/
function CloseCover()
{
    for(var i=0;i<arguments.length;i++)
    {
        var obj = document.getElementById(arguments[i]);
        if(obj)
        {
            obj.style.display = 'none';
        }
    }
} 
function ShowCover()
{
    for(var i=0;i<arguments.length;i++)
    {
        var obj = document.getElementById(arguments[i]);
        if(obj)
        {
            obj.style.display = 'block';
        }
    }
}

function Login(phoneRegexpStr)
{
    var phoneNo;
    var pwd;
    var authenticode;
    
    phoneNo = $get('inputPhoneNo').value;
    if($get('inputPhoneNo').value==''||$get('inputPhoneNo').value=='请输入手机号码')
    {
        $get('inputPhoneNo').focus()
        alert('请输入手机号码');
        return;
    }
    var reg;
    if(phoneRegexpStr && ''!=phoneRegexpStr)
    {
        reg = new RegExp(phoneRegexpStr);
    }
    else
    {
        reg = new RegExp("^\d{11}$","g");
    }
    if(null ==$get('inputPhoneNo').value.match(reg))
    {
        $get('inputPhoneNo').focus()
        alert('请输入正确的手机号码');
        return;
    }
    else
        phoneNo =$get('inputPhoneNo').value;
    
    if($get('inputPwd').value == '')
    {
        alert('请输入密码');
        return;
    }
    if(null == $get('inputPwd').value.match(/^\d{6,8}$/))
    {
//        $get('inputPwdTitle').focus()
        alert('请输入正确的密码');
        return;
    }
    else
        pwd = $get('inputPwd').value;
    
    if('' ==$get('inputCode').value)
    {
        $get('inputCode').focus()
        alert('请输入验证码');
        return;
    }

    if(null ==$get('inputCode').value.match(/^\d{4}$/))
    {
        $get('inputCode').focus()
        alert('请输入正确的验证码');
        return;
    }
    else
        authenticode = $get('inputCode').value;
    
    var context='';
    ShowCover('divProgressing');
    PageMethods.Login(phoneNo,pwd,authenticode,OnLoginSuccess,OnLoginFalied,context);
}

var globeRedirect ='';
function OnLoginSuccess(result,userContext,methdName)
{
    var info = Sys.Serialization.JavaScriptSerializer.deserialize(result);
    if(info.isSuccess == "true")
    {
        $get('divLogined').style.visibility = 'visible';
       $get('inputHiddenLoginedPhoneNo').value =  info.phoneNo;
        $get('ctl00_lblUserPhoneNo').innerText = info.phoneNo;
        $get('iframeWriteCookie').src = 'WriteCookiesCaller.aspx?caller='+info.phoneNo;
       if(info.description.indexOf("您的炫铃正处于暂停状态")>-1)
       {
            alert(info.description);
       }
       if(globeRedirect!='')
        {
            window.location.href= globeRedirect;
           globeRedirect = ''; 
        }
        SetTimeClose(3);
    }
    else
    {
        CloseCover('divProgressing');
        $get('inputPwd').value = '';
        $get('iframeLoginCode').src='AuthenticCode.htm?Seed='+new Date().getMilliseconds();
        alert(info.description);
    }
}

function SetTimeClose(time)
{
    if(time<=0)
    {
        CloseCover('ifcoverLogin','coverLogin','divProgressing');
        $get('spanLoginInfo').innerText='正在处理中,请稍候...';
        
        //如果当前页面为注册页面，跳转到首页
        var currentUrl = window.location.href;
        if (currentUrl.substr(currentUrl.lastIndexOf('/')+1).toLowerCase() == 'userregister.aspx') {
            window.location.href = currentUrl.substr(0,currentUrl.lastIndexOf('/')+1)+'PersonalQryUserRing.aspx';
        }
    }
    else
    {
        $get('spanLoginInfo').innerText='登录成功！'+time+'秒钟后自动关闭窗口！';
        time--;
        window.setTimeout("SetTimeClose("+time+")",1000);
    }
    
}

function OnLoginFalied(error,userContent,methodName)
{
    CloseCover('divProgressing');
    $get('iframeLoginCode').src='AuthenticCode.htm?Seed='+new Date().getMilliseconds();
    alert('网络超时，请稍后再试');
}

function LoginOut()
{
    var context='';
    ShowCover('divProgressing');
    PageMethods.LoginOut(OnLoginOutSuccess,OnLoginFalied,context);
    $get('inputPwd').value = '';
    $get('inputPwd').style.display= 'none';
    $get('inputPwdTitle').style.display = 'block';
    $get('inputCode').value = '';

    //如果用户在个人铃音库中，要跳转到首页
    if(window.location.href.indexOf('ModifyPassword')>-1|| 
        window.location.href.indexOf('Library')>-1||
        window.location.href.indexOf('PersonalQryUserRing')>-1||
        window.location.href.indexOf('CloseUser')>-1 ||
        window.location.href.indexOf('CopyRing')>-1 ||
        window.location.href.indexOf('DiyRing')>-1 ||
        window.location.href.indexOf('MyOrder.aspx')>-1||
        window.location.href.indexOf('MyGroup.aspx')>-1||
        window.location.href.indexOf('EditRingSet')>-1||
        window.location.href.indexOf('CopySetting.aspx')>-1||
        window.location.href.indexOf('DiyRing.aspx')>-1||
        window.location.href.indexOf('ActiveUser.aspx')>-1)
    {
        window.location.href='default.aspx';
    }
}
function OnLoginOutSuccess()
{
    CloseCover('divProgressing');
    $get('divLogined').style.visibility = 'hidden';
    $get('ctl00_lblUserPhoneNo').innerText = '';
}


function GetPassWord(phoneRegexpStr)
{
    var phoneNo;
    var authenticode;
    
    phoneNo = $get('inputPhoneNo').value;
    if($get('inputPhoneNo').value=='请输入手机号码')
    {
        alert('请输入手机号码');
        $get('inputPhoneNo').focus();
       return; 
    }
    var reg;
    if(phoneRegexpStr && ''!=phoneRegexpStr)
    {
        reg = new RegExp(phoneRegexpStr);
    }
    else
    {
        reg = new RegExp("^\d{11}$","g");
    }
    
    if(null ==$get('inputPhoneNo').value.match(reg))
    {
        $get('inputPhoneNo').focus()
        alert('请输入正确的手机号码');
        return;
    }
    else
        phoneNo =$get('inputPhoneNo').value;
     
     if($get('inputCode').value=='' )
    {
        $get('inputCode').focus()
        alert('请输入验证码');
        return;
    } 
    if(null ==$get('inputCode').value.match(/^\d{4}$/))
    {
        $get('inputCode').focus()
        alert('请输入正确的验证码');
        return;
    }
    else
        authenticode = $get('inputCode').value;
        
    var context='';
    
    ShowCover('divProgressing');
    PageMethods.GetPassWord(phoneNo,authenticode,OnGetPassWordSuccess,OnLoginFalied,context);
}
function OnGetPassWordSuccess(result,userContext,methdName)
{
    var info = Sys.Serialization.JavaScriptSerializer.deserialize(result);
    CloseCover('divProgressing');
    alert(info.description);
    $get('iframeLoginCode').src='AuthenticCode.htm?Seed='+new Date().getMilliseconds();
//    if(info.isSuccess == "true")
//    {
//    }
//    else
//    {
//    }
}
/********以上是用户登陆所用****************************/
function searchAuthorRing(authorName)
{
    if(authorName == "undefined" || authorName==null)
    {
        return; 
    }
   
    window.open("Search.aspx?authorType=1&keyword="+escape(authorName),'','').focus();  
}    


function ShowBlock(blockName)
{
    document.getElementById(blockName).style.display="block";
}

function ShowText(divid,msg)
{
    document.getElementById(divid).innerHTML=msg;
    document.getElementById(divid).style.display="block";
}

function CloseText(divid)
{
    document.getElementById(divid).innerHTML="";
    document.getElementById(divid).style.display="none";
}

function CloseBlock(blockName)
{
    document.getElementById(blockName).style.display="none";
}

/******弹出菜单*****/
var menudivsetInterval;
var menudivsetTimeOut;
//导航栏子菜单
function setDivVisible(origalDivName,targetDivName,IsVisible)
{
    if(origalDivName=='')
         div.style.display="none";
 
   var oriDiv=$get(origalDivName);
   var div=$get(targetDivName);
   
    if(IsVisible)
     { 
         div.style.left = (getPos(oriDiv,"Left")-7)+"px";
　　   div.style.top = (getPos(oriDiv,"Top") + oriDiv.offsetHeight+7)+"px";

　　  showDiv(targetDivName);
　 }
    else
     {   
     	   if(navigator.appName=="Microsoft Internet Explorer")
          	menudivsetInterval= setInterval("hideDiv('"+targetDivName+"')", 10);
          else
          	menudivsetTimeOut=setTimeout("hideDiv('"+targetDivName+"')",2000);
     }
}
　　
function getPos(el,sProp)  
{    var iPos = 0 
　while (el!=null)  
   {
      iPos+=el["offset" + sProp] 
 　　 el = el.offsetParent
     } 
　return iPos
} 

function showDiv(targetDivName)
{
	    var div=$get(targetDivName);
	    clearTimeout(menudivsetTimeOut);
	     if(navigator.appName=="Microsoft Internet Explorer")
   		 	clearInterval(menudivsetInterval);   
   		 	
   		 
   		 div.style.display='block';
   		 div.filters.alpha.opacity=100;
}
function hideDiv(targetDivName)
{
	var div=$get(targetDivName);
	
	if(navigator.appName=="Microsoft Internet Explorer")
	{
		if(	div.filters.alpha.opacity>0)
		{
			div.filters.alpha.opacity=div.filters.alpha.opacity-5;

			}
			
		else
			div.style.display='none';
	}
	else
	{
		   if(div.style.display=='block')
			div.style.display='none';
			
	}
}