﻿/*显示信息-------------------
author:leo zhang
date:2009-02-26 12:20
*/
function showTip(name,type)
{   
    if(type==true)
    {
        $("#"+name+"_Err").show();               
        $("#"+name+"_Tip,#"+name+"_Success").hide();  
        
    }    
    if(type==false)
    {
        $("#"+name+"_Success").show();               
        $("#"+name+"_Err,#"+name+"_Tip").hide();            
    }    

}/*------------------显示信息-------------------
author:leo zhang
date:2009-02-26 12:20
*/
function showTip3(name,type,code)
{   
    if(type==true)    
    {
        $("#"+name+"_Err").show();        
        $("#"+name+"_Err span[code='"+code+"']").show();
        $("#"+name+"_Tip,#"+name+"_Success").hide();              
        $("#hiddenReturn").val($(this).val()*2);
    }    
    if(type==false)
    {
        $("#"+name+"_Success").show();   
        $("#"+name+"_Err span[code='"+code+"']").hide();            
        $("#"+name+"_Err,#"+name+"_Tip").hide();            
        $("#hiddenReturn").val($(this).val()*3);
    }    
    
}
/*-------------自定义并显示信息------------------
author:leo zhang
date:2009-02-26 14:20
*/
function showTip2(name,type,msg)
{   
    if(type==true)
    {
        $("#"+name+"_Err").text(msg).show();               
        $("#"+name+"_Tip,#"+name+"_Success").hide(); 
        return 0;             
    }    
    if(type==false)
    {
        $("#"+name+"_Success").show();               
        $("#"+name+"_Err,#"+name+"_Tip").hide();            
        return 1;
    }    
}
/*-----------全文行格式变动-----------------------
author:leo zhang
date:2009-02-26 13:28
*/
function trTip()
{
    $("tr").hover(
        function(){$(this).find("span.inline-block").addClass("tip").css("border","0px solid #7ABDF1")},
        function(){$(this).find("span.inline-block").removeClass("tip").css("border","0px solid #fff")}
        ); 
}

/*-------------浮动层-----------------------------
author:leo zhang 
date:2009-02-26 17:20
*/
function floatDiv(divWidth,innerCode)
{
    //$("html").css("overflow-y","hidden");
    $("body").append("<div id='divBottom' style='width:100%;height:"+$(document).height()+"px;left:0px;overflow:hidden; background-color:#000;position:absolute;top:0;filter:alpha(opacity=30);-moz-opacity:0.7;z-index:1500;'></div>");           
    $("body").append("<div id='floatDiv' style='background:none repeat scroll 0% 0%; width:"+divWidth+"px;"+
     "; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; position: fixed; _position:absolute; left: 50%; top:50%;margin-left:-"+divWidth/2+"px; margin-top:-200px ;z-index:2000;'>"+innerCode+"</div>");   
    //$("#floatDiv").animate({opacity:"1"},500);
    $("#divClose").live("click",function(){        
        $("#floatDiv,#divBottom").remove();$("body").css("overflow-y","visible");$("html").css("overflow-y","auto");
    });
}

function showPic(title,url){
	var ht="<div class=\"divAlpha\"></div>"+
	"<div class=\"wrapper_shadow\">"+
	
		"<div class=\"floatingContent\">"+
	    
	        "<div class=\"title\">"+
	            "<h1>图片预览</h1>"+
	            "<div id='divClose' class=\"close\"><a href=\"#\">关闭</a></div>"+
	            "<div class=\"tl\"></div>"+
	          	"<div class=\"tr\"></div>"+
	        "</div><!--/title-->"+
	        
	        "<div class=\"floatingMainContent\">"+
	        
				"<div class=\"floatingMainContentPicPreview\">"+
					"<img src=\""+url+"\" /><br />"+
					title+
				"</div>"+            
	       " </div><!--/floatingMainContent-->"+        
	    "</div><!--/floatingContent-->"+
	"</div>";
	floatDiv(200,ht);		
}

/*--------------各常用验证的正则表达式-----------------
author:leo zhang
date:2009-02-27 12:32
parameters:
    valueType:verify type
    value:text of input
return:trun/false
*/
function verify(valueType,value)
{
    var reg;
    switch(valueType)
    {
        case "email":                    
            reg=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
        break;
        case "phone":
           // reg=/^((\d{2,3}\-)|(\d{2,3}))?((\d{2,4}-)|(\d{2,4}))?[1-9]\d{6,7}$/;
          // reg=/^(\d{1,4}[-_－—]?)?\d{1,4}([-_－—]?\d{5,8})?([-_－—]?\d{6,8})?([-_－—]?\d{1,4})?$/;
          reg=/^(\d{0,4}[-_－—]?)\d{0,4}([-_－—]?\d{5,8})([-_－—]?\d{0,4})?$/;
        break;
        case "mobile":
            reg=/((^(\d{1,4}[-_－—]?)?\d{6,11}$)|(^(?:86|\+86|086)?1[3|5|8]\d{9}$)|(^((\(\d{3}\))|(\d{3}\-))?13\d{9}|15\d{9}$))/; 
        break;
        case "idCard":
            reg= /^\d{15}(\d{2}[A-Za-z0-9])?$/;
        break;
        case "zip":
            reg=/^[1-9]\d{5}$/;
        break;
        case "qq":
            reg=/^[1-9]\d{4,12}$/;
        break;
        case "integer":
            reg=/^[-\+]?\d+$/;
        break;
        case "double":
            reg=/^[-\+]?\d+(\.\d+)?$/;
        break;
        case "english":
           reg=/^[\x00-\xFF|–|　]+$/;
		   return true;//不需要验证了
        break;
        case "chinese":
            reg=/^([,.?!，。？！:：]*[\u4e00-\u9fa5]*)*$/;
        break;
        case "smallletter":
            reg=/^[a-z]+$/;
        break;
        case "bigletter":
            reg=/^[A-Z]+$/;
        break;
        case "numberletter":
            reg=/^[A-Za-z0-9]+$/;
        break; 
		case "number":
            reg=/^\d+$/;
        break; 
    }
    return reg.test($.trim(value));
}

//验证radio和checkbox是否被选中
function valiCheckBox(name){
    var a=0;
    $("input[name='"+name+"']").each(function(){
        if($(this).attr("checked")==true){
           a+=1;                  
        }
    });
    if(a>0){return true;}
    else{return false;} 
}

//获取小数点后的位数








function getLengthAfterDot(value,length){
	var dotIndex=value.toString().indexOf('.')
	return value.toString().substring(0,dotIndex+length+1);
}


/*-------------通用浮动层---------------------------
author:wangshude
date:2009-03-25 12:37
parameters:
    title 		标题
    html  		html
	maxHeight	最大高度*/
function floatShow(title,html,maxHeight)
{  
   // $("html").css("overflow-y","hidden");
    window.scrollTo(0,0);
    $(".divAlpha").css("height",$(document).height()+"px");
	if(maxHeight==null){maxHeight = 500;}	
	$(".wrapper_shadow,.divAlpha").show();
	$(".title h1").html(title);
	$(".floatingMainContent").empty();
	$(".floatingMainContent").html(html);
	if($(".floatingMainContent").height()>maxHeight){$(".floatingMainContent").height(maxHeight)};	
	
	$("#divClose").click(function(){
	  hidelayer();
	  //$("html").css("overflow-y","auto");
    });	
}
/*-------------关闭通用浮动层---------------------------
author:wangshude
date:2009-03-26 19：34
*/
function hidelayer(){
    $(".wrapper_shadow,.divAlpha").hide();
    $(".floatingMainContent").empty();
//    $("body").css("overflow-y","visible");
//    $("html").css("overflow-y","auto");   
}

 //用于指定页的转向
function urlByPage(pageIndex){
    var cL=$(".pathCurrent").attr("href");	
    var url=location.toString();
	var full=url.substring(0,url.indexOf('?'))+cL;	
	var reg=/pageCurrent=(\d*)/i;	
	location=full.replace(reg,"pageCurrent="+pageIndex.toString());    
}
 //用于指后台定页的转向
function urlByPage2(pageIndex){
    var cL=$(".current").attr("href");	
    var url=location.toString();
	var full=url.substring(0,url.indexOf('?'))+cL;	
	var reg=/pageCurrent=(\d*)/;	
	location=full.replace(reg,"pageCurrent="+pageIndex.toString());    
}

//----------------------发留言
function messageResult(result){
    if(result==1){
        $("#textareaMsg").text('').addClass("messageRight").click(function(){
            $(this).removeClass("messageRight");
        });
    }
    else{
        $("#textareaMsg").addClass("messageWrong").click(function(){
            $(this).removeClass("messageWrong");
        });
    }                    
}

//------------------------浮动登录
function floatLogin(){
     if($.cookie("loginStatus")==0){
        $("body").append("<div id=\"divLoginfloat\" style=\"position:absolute;top:50%;margin-top:-100px; left:50%; margin-left:-335px\"></div>");
        $("#divLoginfloat").load("/user/floatLogin.asp  .floatingContent",function(){
        
            //window.scrollTo(0,0);
            floatDiv(667,$(this).html());
            //登录		                
            $("#btnSubmit").click(function(){
                $.ajax({
                    type:"POST",
                    url:"/user/login_ajax.asp",
                    data:"email="+$("#email").val()+"&password="+$("#password").val()+"&GetCodeText="+$("#GetCodeText").val(),
                    success:function(result){                               
                         //ajaxSuccess(result);             
						 if(result==1){document.location.reload();}         
						else if(result==-1)
						{alert(cWrongCode);}
						else{
						  alert(cLoginInfo);                                          
						} 
                    }
                });
            });
            
        });				    
        $("#divLoginfloat").remove();                
    }            
}

//------------------------------提示框插件







jQuery.extend({
        alte:function(title,value){
            if($("#divAlter").length>0){
                $("#divAlter").remove();
            }
            $("body").append("<div id='divAlter' style=\" z-index:1000; position:fixed; left:50%; top:50%; border: 1px solid #1482C4;min-height: 120px;min-width: 200px;max-width: 400px;background-color: #8CD3EF;filter: alpha(opacity=80);-moz-opacity: 0.8;font-size:12px\">"
            +"<div style=\"height:22px;padding:10px 10px 0px 10px; min-width:180px;max-width: 400px\">"+title
            +"</div>"
            +"<div style=\"width:100%; border-top:1px solid #1482C4; \">"                                                                                                                 
            +"    <div style=\"margin:10px; text-align:center; min-height:46px; min-width:180px\">"+value+"</div>"                    
            +"    <div id='ddbtn' style=\"margin:10px 0px 10px 0px; text-align:center; min-width:200px;max-width: 400px\"><input id=\"btnAlter\" style=\"border:1px solid #909090;cursor:pointer;background-color:#F6F7F1; width:76px\" type=\"button\" value=\""+cSure+"\" /></div>"
            +"</div>"
            +"<div>"
            +"</div>"
        +"</div>");         
        $("#divAlter").css({"margin-left":0-$("#divAlter").width()/2+"px","margin-top":0-$("#divAlter").height()/2+"px"})
        .hover(function(){$(this).stop().animate({opacity:1},200);},function(){$(this).stop().animate({opacity:0.8},200);});
        $("#ddbtn").css("width",$("#divAlter").width());
        $("#btnAlter").click(function(){           
           $("#divAlter").css("min-height","1px").animate({opacity:0},200,function(){$("#divAlter").remove();});
           setTimeout("$(\"#divAlter\").remove();",210);//防止动画死锁,20ms缓冲          
        });
        }
    });