﻿// JScript File

function ShowDialog(url,wid,hig) 
{ 
    var  iWidth=wid ; //模态窗口宽度
    var  iHeight=hig;//模态窗口高度
    var  iTop=(window.screen.height-iHeight)/2;
    var  iLeft=(window.screen.width-iWidth)/2;
    window.open(url,"Detail", "Scrollbars=yes,Toolbar=no,Location=no,Direction=no,Resizeable=no,   Width="+iWidth+" ,Height="+iHeight+",top="+iTop+",left="+iLeft) 
} 

//function Evaluate(word)
//{
//    return word.replace(/^(?:([a-z])|([A-Z])|([0-9])|(.)){6,}|(.)+$/g, "$1$2$3$4$5").length;
//}
function Evaluate(passwd) {
intScore = 0;
//if (passwd.match(/[a-z]/)) // [verified] at least one lower case letter
//{
//intScore = (intScore+1)
//} if (passwd.match(/[A-Z]/)) // [verified] at least one upper case letter
//{
//intScore = (intScore+5)
//}
 // NUMBERS
if (passwd.match(/\d+/)) // [verified] at least one number
{
intScore = (intScore+5)
} if (passwd.match(/(\d.*\d.*\d)/)) // [verified] at least three numbers
{
intScore = (intScore+5)
} 
if (passwd.length  >=6) // [verified] at least three numbers
{
intScore = (intScore+5)
} 
// SPECIAL CHAR
//if (passwd.match(/[!,@#$%^&*?_~]/)) // [verified] at least one special character
//{
//intScore = (intScore+5)
//} if (passwd.match(/([!,@#$%^&*?_~].*[!,@#$%^&*?_~])/)) // [verified] at least two special characters
//{
//intScore = (intScore+5)
//} // COMBOS
//if (passwd.match(/[a-z]/) && passwd.match(/[A-Z]/)) // [verified] both upper and lower case
//{
//intScore = (intScore+2)
//} if (passwd.match(/\d/) && passwd.match(/\D/)) // [verified] both letters and numbers
//{
//intScore = (intScore+2)
//} // [Verified] Upper Letters, Lower Letters, numbers and special characters
//if (passwd.match(/[a-z]/) && passwd.match(/[A-Z]/) && passwd.match(/\d/) && passwd.match(/[!,@#$%^&*?_~]/))
//{
//intScore = (intScore+2)
//}
return intScore;
}
function strstrong()
{
    var pas =  document.getElementById('txtPas').value;
    var hid  =  document.getElementById('hid');
    var Text1  =  document.getElementById('Text1');
    
    
    hid.value = Evaluate(pas);
//    Text1.value = Evaluate(pas);
}

  function ShowHideHelp(obj,obj1,obj2)
 {
    if (obj.style.display == "none")
        obj.style.display = "block"; 
    else
        obj.style.display = "none"; 
        obj1.style.display = "none"; 
        obj2.style.display = "none"; 
 } 

//when there have not image, it display default image.
 function changeImage(obj) {
     if (document.getElementById(obj))
         document.getElementById(obj).src = "../images/nophoto_501.jpg";
     else {
         $(obj).attr('src', '../images/nophoto_501.jpg');
     }
 }

   function changeFriendImage(obj) {
       if (document.getElementById(obj))
           document.getElementById(obj).src = "../images/nophoto.jpg";
       else {
           $(obj).attr('src', '../images/nophoto.jpg');       
       }
   }
  
    function funShowContactInformation(e,divid)
     {
        document.getElementById("plholder").innerHTML = document.getElementById(divid).innerHTML;     
        document.getElementById("plholder").style.display="";        
        funShowInfromationLayer(e, "plholder");
    }
    
    function funShowClearInformation() 
    {    
        document.getElementById("plholder").innerHTML = "";
        document.getElementById("plholder").style.display="none";
    }
   
  ///Check the browser is IE6 or IE7 
  function CheckIE()
  {
    var browser=navigator.appName 
    var b_version=navigator.appVersion 
    var version=b_version.split(";"); 
    var trim_Version=version[1].replace(/[ ]/g,""); 
    
    if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE7.0") 
    { 
        return "IE7";
    } 
    else if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE6.0") 
    { 
        return "IE6";
    }     
  }  
    
    function funShowInfromationLayer(e, divlayer) {
        var x, y;
       
       if (CheckIE() == "IE7")
       {
            x = e.offsetX + 100;
            y = e.y - 100;
       }
       else if (e.pageX) {
            x = e.pageX - 820;
            y = e.pageY - 150;
        }
        else 
        {
            x = e.offsetX + 100;
            y = e.y + 300;
        }

            document.getElementById(divlayer).style.right = x  + "px";
            document.getElementById(divlayer).style.top = y  + "px";
    }   
   
//check browser   
function getOs()
{
   if(navigator.userAgent.indexOf("MSIE")>0)return 1;
   if(isFirefox=navigator.userAgent.indexOf("Firefox")>0)return 2;
   if(isSafari=navigator.userAgent.indexOf("Safari")>0)return 3;   
   if(isCamino=navigator.userAgent.indexOf("Camino")>0)return 4;
   if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0)return 5;
   return 0;

}

function PlayAudio(baseUrl, user, id) {
    var soaudio = new SWFObject(baseUrl + "js/audio_player/audioPlayer.swf", "playeraudio", "320", "102", "6", null);
    soaudio.addVariable("xmlPath", baseUrl + "Profiles/Data/XMLMusic_" + user + ".xml?" + Math.random());
    soaudio.addParam("wmode", "transparent");
    soaudio.write("flashaudiocontent" + id);    
}

function PlayVideo(ctrlID, urlf, url, baseUrl, width, height)
{    
    document.getElementById(ctrlID).innerHTML = "<div name='preview' id='preview'></div>";
    var player = null;
    var str = baseUrl + 'js/mediaplayer/player.swf';
    var s1 = new SWFObject(str,'JW', width, height,'9');
    s1.addParam('allowscriptaccess', 'always');
    s1.addParam('wmode','transparent');
    s1.addParam('allowfullscreen','true');
    s1.addVariable('fullscreen','true');
    s1.addVariable('javascriptid', 'JW');
    s1.addVariable('autostart', 'false'); 
    s1.addVariable('width', width);
    s1.addVariable('height', height);
    s1.addVariable('image', baseUrl + 'images/nophoto_500.jpg');
    s1.addVariable('file', encodeURIComponent(urlf));
    s1.addVariable('type', 'video');
    s1.addVariable('plugins', 'sharing-1');
    s1.addVariable('sharing.link', url);
    s1.addVariable('sharing.code', "%3Cembed%20src%3D%22" + str + "%22%20height%3D%22" + height + "%22%20width%3D%22" + width + "%22%20allowscriptaccess%3D%22always%22%20allowfullscreen%3D%22true%22%20flashvars%3D%22file%3D" + encodeURIComponent(urlf) + "%26sharing.link%3D" + url + "?level%3D0%26type%3Dvideo%26javascriptid%3DJW%26image%3D" + baseUrl + "images%2Fnophoto_500.jpg%26bandwidth%3D239%26dock%3Dfalse%26plugins%3Dsharing-1%22%20" + "wmode = %22transparent%22 " + "%2F%3E");
    s1.addVariable('type', 'video');
    s1.write('preview');
}

function PlayList(url, baseUrl, width, height, id, publicurl) {
   // document.writeln("<div name='preview" + id + "' id='preview" + id + "'></div>");
    var player = null;
    var str = baseUrl + 'js/mediaplayer/player-viral.swf';
    var s1 = new SWFObject(str, 'JW', width, height, '9');
    s1.addParam('allowscriptaccess', 'always');
    s1.addParam('wmode', 'transparent');
    s1.addParam('allowfullscreen', 'true');
    s1.addVariable('fullscreen', 'true');
    s1.addVariable('javascriptid', 'JW');
    s1.addVariable('autostart', 'false');
    s1.addVariable('width', width);
    s1.addVariable('height', height);
    s1.addVariable('image', baseUrl + 'images/nophoto_500.jpg');
    s1.addVariable('file', encodeURIComponent(url));
    s1.addVariable('plugins', 'sharing-1');
    s1.addVariable('sharing.link', baseUrl + publicurl);
    s1.addVariable('sharing.code', "%3Cembed%20src%3D%22" + str + "%22%20height%3D%22" + height + "%22%20width%3D%22" + width + "%22%20allowscriptaccess%3D%22always%22%20allowfullscreen%3D%22true%22%20flashvars%3D%22file%3D" + encodeURIComponent(url) + "%26sharing.link%3D" + baseUrl + publicurl + "?level%3D0%26type%3Dvideo%26javascriptid%3DJW%26image%3D" + baseUrl + "images%2Fnophoto_500.jpg%26bandwidth%3D239%26dock%3Dfalse%26plugins%3Dsharing-1%22%20" + "wmode = %22transparent%22 " + "%2F%3E");
    s1.addVariable('type', 'video'); 
    s1.write('preview' + id);
}

function Play(url, baseUrl, width, height, ispublic, publicurl)
{
    document.writeln("<div name='preview' id='preview'></div>");
    var player = null;

    var str = ispublic == "True" ? baseUrl + 'js/mediaplayer/player.swf' : baseUrl + 'js/mediaplayer/privateplayer.swf';

    var s1 = new SWFObject(str, 'JW', width, height, '9');
    s1.addParam('allowscriptaccess', 'always');
    s1.addParam('wmode', 'opaque');
    s1.addParam('allowfullscreen', 'true');
    s1.addVariable('fullscreen','true');
    s1.addVariable('javascriptid', 'JW');
    s1.addVariable('autostart','false'); 
    s1.addVariable('width', width);
    s1.addVariable('height', height);
    s1.addVariable('image', baseUrl + 'images/nophoto_500.jpg');
    s1.addVariable('file', encodeURIComponent(url));

    if (publicurl != "") {
        s1.addVariable('plugins', 'sharing-1');
        s1.addVariable('sharing.link', baseUrl + publicurl);
        s1.addVariable('sharing.code', "%3Cembed%20src%3D%22" + str + "%22%20height%3D%22" + height + "%22%20width%3D%22" + width + "%22%20allowscriptaccess%3D%22always%22%20allowfullscreen%3D%22true%22%20flashvars%3D%22file%3D" + encodeURIComponent(url) + "%26sharing.link%3D" + baseUrl + publicurl + "?level%3D0%26type%3Dvideo%26javascriptid%3DJW%26image%3D" + baseUrl + "images%2Fnophoto_500.jpg%26bandwidth%3D239%26dock%3Dfalse%26plugins%3Dsharing-1%22%20" + "wmode = %22transparent%22 " + "%2F%3E");
    }
        
    s1.addVariable('type', 'video'); 
    s1.write('preview');
}

function PlayControl(url, baseUrl, width, height, ispublic, publicurl)
{
    var player = null; 
    var str = ispublic == "True" ? baseUrl + 'js/mediaplayer/player-viral.swf' : baseUrl + 'js/mediaplayer/privateplayer.swf';

    var s1 = new SWFObject(str, 'JW', width, height, '9');
    s1.addParam('allowscriptaccess', 'always');
    s1.addParam('wmode','transparent');
    s1.addParam('allowfullscreen','true');
    s1.addVariable('fullscreen','true');
    s1.addVariable('javascriptid', 'JW');
    s1.addVariable('autostart','false'); 
    s1.addVariable('width', width);
    s1.addVariable('height', height);
    s1.addVariable('image', baseUrl + 'images/nophoto_500.jpg');
    s1.addVariable('file', encodeURIComponent(url));
    
    if (publicurl != "") {
        s1.addVariable('plugins', 'sharing-1');
        s1.addVariable('sharing.link', baseUrl + publicurl);
        s1.addVariable('sharing.code', "%3Cembed%20src%3D%22" + str + "%22%20height%3D%22" + height + "%22%20width%3D%22" + width + "%22%20allowscriptaccess%3D%22always%22%20allowfullscreen%3D%22true%22%20flashvars%3D%22file%3D" + encodeURIComponent(url) + "%26sharing.link%3D" + baseUrl + publicurl + "?level%3D0%26type%3Dvideo%26javascriptid%3DJW%26image%3D" + baseUrl + "images%2Fnophoto_500.jpg%26bandwidth%3D239%26dock%3Dfalse%26plugins%3Dsharing-1%22%20" + "wmode = %22transparent%22 " + "%2F%3E");
    }
    
    s1.addVariable('type', 'video'); 
    s1.write('preview');
}

function ChangeAllTextBoxFont() 
{     
   var theForm = document.forms['aspnetForm'];
    if (!theForm) 
        theForm = document.aspnetForm;

   
   var formElemnets = theForm.elements; 
       
   for (var i=0; i<formElemnets.length; i++)  
   {        
        var element = formElemnets[i];        
                
        if ((element.tagName == "INPUT" && element.type == "text") || element.tagName == "TEXTAREA")
        { 
            element.onclick = function()
            {
                this.className = "biggerFont";
            }
            
            element.onblur = function()
            {
                this.className = "";
            }
        }     
     }
} 


/******ModalPopupExtender***********************************/
 var _obj;
        var _btnObj;
        var out_div = true;

        function getObj(obj, btnObj) {
            _obj = $find(obj);

            if (_obj == null) _obj = $(obj);
            
            _btnObj = document.getElementById(btnObj);
        }
        
        //close popup
        function closePopup()
        {
            if (_obj != null)
            {
                _obj.hide();
               _obj=null; 
            }
        }
        
        //if the mouse is in the field, set out_div is true;
        function Setonmouseover()
        {
            out_div = false;
            _btnObj = null;
        }
        
        //if the mouse is out of the field, set out_div is true;
        function Setonmouseout() {
           
            out_div = true;
            _btnObj = null;
        }
        
        document.onmouseover = function(event)
        {   
            _btnObj = null;
        }
        
        //if clicking other field, the popup will close.
        document.onclick = function(event) { 
            if(out_div && 
               _btnObj == null)
            {
                closePopup();
            }
        }
/*****************************************/
// Selects/Unselects record
function fnSelectAllRecord(chkAll, chkItems, btnArray, txtIds)
{	
    if(typeof(txtIds) != "object")
    {
        return;
    }

    var idsArray = new Array();
    if(txtIds.value.length != 0)
    {
       idsArray = txtIds.value.split(",");
    }
        
    for(var i=0; i<chkItems.length; i++)
    {
	    if (chkItems[i].disabled)
	    {
	        continue;
	    }
		
	    chkItems[i].checked = chkAll.checked;
	    fn_fillSelectedValue_privte(idsArray, chkItems[i])
    }

    txtIds.value = idsArray.join(",");
    
	var isDisabled = idsArray.length == 0;
	if(btnArray instanceof Array)
	{
	    for(var i=0; i<btnArray.length; i++)
	    {
		    if(typeof(btnArray[i]) == "object")
		    {
		        btnArray[i].disabled = isDisabled;
		    }
	    } 
	}
}

// Enable buttons by selected count.
function fnEnableButtonBySelected(chkItem, btnArray, txtIds)
{	
    if(typeof(txtIds) != "object")
    {
        return;
    }
    
    var idsArray = new Array();
    if(txtIds.value.length != 0)
    {
       idsArray = txtIds.value.split(",");
    }
    
    fn_fillSelectedValue_privte(idsArray, chkItem);
    
    txtIds.value = idsArray.join(",");
    
    var isDisabled = idsArray.length == 0;
	
	if(btnArray instanceof Array)
	{
	    for(var i=0; i<btnArray.length; i++)
	    {
		    if(typeof(btnArray[i]) == "object")
		    {
		        btnArray[i].disabled = isDisabled;
		    }
	    } 
	}
}

// The function is private, fill selected value to array.
function fn_fillSelectedValue_privte(idsArray, chkItem)
{
    if(chkItem.checked)
    {
        idsArray.push(chkItem.value);
    }
    else
    {
       for(var i=0; i<idsArray.length; i++)
       {
            if(chkItem.value == idsArray[i])
            {
                idsArray.splice(i, 1);
                break;
            }
       }
    }
}

// Initializes selected items. If you need to maintain selected status on every page, Please invoke the method.
function fnInitSelectAll(chkItems, btnArray, txtIds)
{   
    if(typeof(txtIds) != "object")
    {
        return;
    }

    var idsArray = new Array();
    if(txtIds.value.length != 0)
    {
       idsArray = txtIds.value.split(",");
    }
    
    var isDisabled = idsArray.length == 0;
	for(var i=0; i<chkItems.length; i++)
    {	    
	   for(var j=0; j<idsArray.length; j++)
       {
          if(chkItems[i].value == idsArray[j])
          {
             chkItems[i].checked = true;
             break;
          }
       }
    }
    
	if(btnArray instanceof Array)
	{
	    for(var i=0; i<btnArray.length; i++)
	    {
		    if(typeof(btnArray[i]) == "object")
		    {
		        btnArray[i].disabled = isDisabled;
		    }
	    } 
	}
}

//Hidden message
function HiddenMessage(obj)
{
    document.getElementById(obj).style.display = "none";
}

function HiddenURLMessage(obj, url)
{
    document.getElementById(obj).style.display = "none";
   window.location.href = url; 
}

function HiddenParentURLMessage(obj, url, parentUrl) {
    document.getElementById(obj).style.display = "none";

    if (parentUrl)
        window.parent.location.href = url;
}

String.prototype.trim = function() {
    return this.replace(/(^s*)|(s*$)/g, "");
}

//check checkboxlist
function ValidateCheckBoxList(sender, args) {
    args.IsValid = false;

    $(".CheckBoxList").find(":checkbox").each(function() {
        if ($(this).attr("checked")) {
            args.IsValid = true;
            return;
        }
    });
}

function Init(btnArray, checkArray, tbxArray, groupName) {
    var group = "";
    if (Init.arguments.length == 4)
        group = groupName;
    if(btnArray instanceof Array) {
        for(var i=0; i<btnArray.length; i++)
        {
            if(typeof(btnArray[i]) == "object")
            {
                btnArray[i].onclick = function() {
                    if (!HiddenReq(group)) {
                        if (checkArray instanceof Array) {
                            for (var i = 0; i < checkArray.length; i++) {
                                if (typeof (checkArray[i]) == "object" &&
                                   checkArray[i] != null) {
                                    if (tbxArray[i].value.trim() == "") {
                                        checkArray[i].style.visibility = "visible";
                                        checkArray[i].style.color = "Red";
                                        checkArray[i].style.fontWeight = "Bold";
                                    }
                                    else {
                                        checkArray[i].style.visibility = "visible";
                                        checkArray[i].style.color = "#000000";
                                        checkArray[i].style.fontWeight = "normal";
                                    }
                                }
                            }
                        }
                    }
                }
             }
        } 
    }   
    
    if(tbxArray instanceof Array)
    {
        for(var i=0; i<tbxArray.length; i++)
        {
            if(typeof(tbxArray[i]) == "object" &&
               tbxArray[i] != null)
            {
                tbxArray[i].onblur = function()
                {
                    return ShowReq(this, tbxArray, checkArray);
                }
             }
        } 
    }
    
    if(checkArray instanceof Array)
    {
        for(var i=0; i<checkArray.length; i++)
        {
            if(typeof(checkArray[i]) == "object" &&
               checkArray[i] != null)
            {
                checkArray[i].style.visibility = "visible";
                checkArray[i].style.color = "#000000";
                checkArray[i].style.fontWeight = "normal";
             }
        } 
    }  
}

function ShowReq(obj, tbxArray, checkArray) {
    if(tbxArray instanceof Array)
    {
        for(var i=0; i<tbxArray.length; i++)
        {
            if(typeof(tbxArray[i]) == "object" &&
               tbxArray[i] != null &&
               obj.id == tbxArray[i].id)
            {
                checkArray[i].style.visibility = "visible";
                checkArray[i].style.color = "#000000";
                checkArray[i].style.fontWeight = "normal";
             }
        } 
    }  
}

function HiddenReq(groupName)
{
    if (typeof (Page_ClientValidate) == 'function')
        if (groupName == "")
            return Page_ClientValidate();
        else
            return Page_ClientValidate(groupName);
    else
        return false;
}

function ApplyCorners() {
    settings = {
        tl: { radius: 10 },
        tr: { radius: 10 },
        bl: { radius: 10 },
        br: { radius: 10 },
        antiAlias: true,
        autoPad: true,
        validTags: ["div"]
    }
    var myBoxObject = new curvyCorners(settings, "roundBox");
    var myBoxObject2 = new curvyCorners(settings, "fullbox");
    myBoxObject.applyCornersToAll();
    myBoxObject2.applyCornersToAll();
}

/********Rate star*******************************************/

/* change star width */
function ChangeStarWidth(e, obj) {
    var _offsetX = window.event ? window.event.offsetX : e.originalEvent.layerX;
    var count = Math.floor(_offsetX / 16) + 1;
    var swidth = count * 16;
    $(obj).find('div').width(swidth);
}

/* clear star width */
function ClearStarWidth(obj) {
    var val = $(obj).find('input[type=hidden]').val();
    var objID = $(obj).find('div').attr("id");
    document.getElementById(objID).style.width = val + "px";
}

/* add event for the star */
function AddStarEvent() {
    var obj = $('.star');

    if (obj.length > 0) {
        obj.mouseover(function(event) { ChangeStarWidth(event, this); });
        obj.mousemove(function(event) { ChangeStarWidth(event, this); });
        obj.mouseout(function() { ClearStarWidth(this); });
    }
}

//submit star
function subStarComment(objectType, objectID, divStarID, lblVotesID, pageURL, message, hfValueID) {
    //$('#' + lblVotesID).html('<span class="loading">Loading...</span>');
    var divStarWIdth = $("#" + divStarID).width();

    $.post(pageURL,
        { objectID: objectID, objectType: objectType, starVal: divStarWIdth },
        function(data) {

            if (data.update.toLowerCase() == "false") {
                $("#" + divStarID).parents("div.star").siblings('span.repeat_vote').show();
                setTimeout(function() {
                    $("#" + divStarID).parents("div.star").siblings('span.repeat_vote').hide();
                }, 2000);
            }

            document.getElementById(divStarID).style.width = data.retScore + "px";
            $('#' + lblVotesID).html(data.retReview);
            document.getElementById(hfValueID).value = data.retScore;
        }, "json");
}
/***************************************************/

function ChangeFont(val) {
    var fontsize = document.getElementById("divFont").style.fontSize;

    if (fontsize == "") fontsize = 12 + "px";
    fontsize = fontsize.substring(0, fontsize.lastIndexOf("px"));

    if (val == "true") {
        document.getElementById("divFont").style.fontSize = (parseInt(fontsize) + 3) + "px";
    }
    else {
        document.getElementById("divFont").style.fontSize = (parseInt(fontsize) - 3) + "px";
    }
}

function compareTime(start, end) {
    var arrS = start.split("/");
    var starttime = new Date(arrS[2], arrS[0], arrS[1]);
    var starttimes = starttime.getTime();

    var arrE = end.split("/");
    var endtime = new Date(arrE[2], arrE[0], arrE[1]);
    var endtimes = endtime.getTime();
    alert(starttimes);
    alert(endtimes);

    if (starttimes >= endtimes) {
        return true;
    }
    else {
        return false;
    }
}

function GetTelerikRadWindow() {
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow;
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
    return oWindow;
}

function CloseTelerikRadWindow() {
    GetTelerikRadWindow().close();
}

function RadWindowHiddenParentURLMessage(obj, url, parentUrl) {
    CloseTelerikRadWindow();

    if (parentUrl)
        window.parent.location.href = url;
}