﻿//注：本文件很多方法Lswweb.Controls中都用到，所以必须引入本文件

//直接运行部分
//取消点击连接时连接字符四周出现虚框
$(function(){
    $("a").focus(
        function() {
            this.blur();
        }
    );
});

$(function(){
    $("table[summary=InputTable] td").each(function(i){
        if(i%2 == 0)$(this).addClass('title');          
    });
})

$(function(){
    $("table[summary=Remove] td").each(function(i){
        if(i%2 == 0)$(this).removeClass('title');          
    });
})

//tabs
function Tabs(expression,moveClass,outClass)
{
    $(expression).mouseover(function(){
        $(this).attr("class",moveClass);
    }).mouseout(function(){
        if($(expression + "[class='" + moveClass + "']").length>1)$(this).attr("class",outClass);   
    }).click(function(){
        $(expression).removeAttr("class");
        $(this).attr("class",moveClass);     
    })
}

///转换
Convert=function(){};
Convert.ToInt32=function(strNum)
{
    var label=parseInt(strNum);
    if(isNaN(label))
        label= 0;
    return label;
} 

//字符串，添加format方法 使用方法 var a="1213{0},fdsfdsf{1}";a.format("1","2");
String.prototype.format = function() 
{ 
    var args = arguments; 
    return this.replace(/\{(\d+)\}/g, 
        function(m,i){ return args[i]; }
    ); 
} 

//取得页面大小。pageWidth,pageHeight为整个页面大小，windowWidth,windowHeight为windows窗口可视区域大小。
function GetPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


//鼠标mouseover或mouseout的css效果
function ChangeMouseView(elements,overClassName,outClassName)
{
    $(elements).attr("class",outClassName);
    
    $(elements).mouseover(function(){
        this.className=overClassName;
    });
    
    $(elements).mouseout(function(){
        this.className=outClassName;
    });
}


//根据窗口大小配置改变控件大小
function Resize(controlId,removeWidth,removeHeight,orientationMode,referToControlId)
{
    var control=$("#" + controlId)
    if(control[0]==null)return;
        
    control.hide(); //当control潜套在referControl时，因为在鼠标拖动缩小窗口时control会撑着referToControl使其不会变小（最小也是当前control的大小）所以会造成窗口不会缩小的现像。
                    //在这里先隐藏control使referControl大小正常无误的进行改变，之后再参考referControl的大小改变control的大小，最后再将control显示出来。
     
    var height,width;  
    if(referToControlId==null || referToControlId=='' || referToControlId==undefined)
    {
        var pageSize=GetPageSize(); 
        width=pageSize[2];
        height=pageSize[3];
    }
    else
    {
        var referToControl=$("#" + referToControlId);
        if(referToControl[0]==null)return;    
        width=referToControl.width();   
        height=referToControl.height();
    }

    width=width - removeWidth - Convert.ToInt32(control.css("border-left-width")) - Convert.ToInt32(control.css("border-right-width")) - Convert.ToInt32(control.css("padding-left")) - Convert.ToInt32(control.css("padding-right")) - Convert.ToInt32(control.css("margin-left")) - Convert.ToInt32(control.css("margin-right"));
    height=height - removeHeight - Convert.ToInt32(control.css("border-top-width")) - Convert.ToInt32(control.css("border-bottom-width")) - Convert.ToInt32(control.css("padding-top")) - Convert.ToInt32(control.css("padding-bottom")) - Convert.ToInt32(control.css("margin-top")) - Convert.ToInt32(control.css("margin-bottom"));
    
    if(orientationMode=='All')
        control.height(height).width(width);
    else if(orientationMode=='Width')
        control.width(width);
    else if(orientationMode=='Height')
        control.height(height);

    control.show();
}

function ImagePreviewClick(obj)
{
    $.blockUI({css:{padding:15},overlayCSS:{opacity:'0'},message:'<p><img src='+ $(obj).attr('PreviewUrl') + ' /></p><input id=closeAlertMessage type=button value=关闭 />'});$('#closeAlertMessage').click(function(){$.unblockUI();});
}

     

