$(document).ready( function() {

    $(".buttom_2").mouseover( function() {
        $(this).css("background-position","0px -23px");
    })
    $(".buttom_2").mouseout( function() {
        $(this).css("background-position","0px 0px");
    })
    $(".buttom_1").mouseover( function() {
        $(this).css("background-position","0px -23px");
    })
    $(".buttom_1").mouseout( function() {
        $(this).css("background-position","0px 0px");
    })
    $(".list tr").mouseover( function() {
        $(this).addClass("over");
    })
    $(".list tr").mouseout( function() {
        $(this).removeClass("over");
    })

})
function validate(data,datatype) {
    switch(datatype) {
        case  "Require" :
            if(data=="") {
                return true;
            }
            break;
    }
}

function receve() {
 window.setTimeout( function() {
    $.ajax({
        async:true,
        type: "POST",
        url: "/Mail/_receve",
        data: "ajax=1&alert=1",
        dataType: "json",
        success: function(msg) {
            $("#msgBox .msg").html(msg.info);
            $("#left_nav a[node=113] span.count").append("("+msg.data+")");
            $("#msgBox").show();
            window.setTimeout( function() {
                $("#msgBox").hide();
            },5000);
        }
    })},001);
}

function redirect(url){
  $("#_content").attr("src",url);
}

function check_form(sform) {
    var check_flag;
    check_flag=true;
    $(".msgbox").each( function(i) {
        $(this).text("");
    })
    $("#"+sform+" :input").each( function(i) {
        if($(this).attr("check") && validate($(this).val(),$(this).attr("check"))) {
            $("#msgbox_"+$(this).attr("id")).text($(this).attr("msg"));
            check_flag=false;
        };
    })
    return check_flag;
}

function sendAjax(url,vars) {
    var isAlert=(vars.indexOf("alert=1")>0);
    var urlto=vars.slice(vars.indexOf("url="));
    urlto=urlto.slice(4,urlto.indexOf('&'));
    return $.ajax({
        type: "POST",
        url: url,
        data: vars,
        dataType: "json",
        success: function(msg) {
            if (isAlert) {
                if (urlto.length>1) {
                    ui_alert(msg.info,'系统提示信息',urlto);
                } else {
                    ui_alert(msg.info,'系统提示信息');
                }
            }else{
				if (urlto.length>1) {
                  window.location.href=window.location.href;
                }
			}
        }
    });
}

function sendAjax2(url,vars) {
    var isAlert=(vars.indexOf("alert=1")>0);
    var urlto=vars.slice(vars.indexOf("url="));
    urlto=urlto.slice(4,urlto.indexOf('&'));
    $.ajax({
        async:false,
        type: "POST",
        url: url,
        data: vars,
        dataType: "json",
        success: function(msg) {
            if (isAlert) {
                $("#msgBox .msg").html(msg.info);
                $("#left_nav a[node=113] span.count").append("("+msg.data+")");
                $("#msgBox").show();
                window.setTimeout( function() {
                    $("#msgBox").hide();
                },5000);
            }
        }
    });
}

function sendForm(formId,url){
    if($("#ajax").val()==1) {
        var vars=$("#"+formId).serialize();
        $.ajax({
            type: "POST",
            url: url,
            data: vars,
            dataType: "json",
            success: function(msg){
                switch(formId) {
                    case "frm_add":
                        var redirecturl=url.replace("insert",'edit/id/'+msg.data);
                        ui_alert(msg.info, '系统提示信息',redirecturl);
                        break
                    case "frm_edit":
                        ui_alert(msg.info, '系统提示信息',window.location.href);
                        break
                    default:
                        if (msg.status=='1') {
                            ui_alert(msg.info, '系统提示信息',window.location.href);
                        } else {
                            ui_alert(msg.info, '系统提示信息');
                        }
                }
                return msg.status;
            }
        });
    }else {
        $("#"+formId).attr("action",url);
        $("#"+formId).submit();
    }
}

function sendForm2(formId,url){
    if($("#ajax").val()==1) {
        var vars=$("#"+formId).serialize();
		var action=$("#"+formId).attr("action");
        $.ajax({
            type: "POST",
            url:action,
            data: vars,
            dataType: "json",
            success: function(msg){
                if (msg.status=='1') {
                       ui_alert(msg.info, '系统提示信息',window.location.href);
                    } else {
                         ui_alert(msg.info, '系统提示信息');
                    }           
            }
        });
    }else {
        $("#"+formId).attr("action",url);
        $("#"+formId).submit();
    }
}

function allSelect() {
    var	colInputs = document.getElementsByTagName("input");
    for	(var i=0; i < colInputs.length; i++) {
        colInputs[i].checked= true;
    }
}

function allUnSelect() {
    var	colInputs = document.getElementsByTagName("input");
    for	(var i=0; i < colInputs.length; i++) {
        colInputs[i].checked= false;
    }
}

function InverSelect() {
    var	colInputs = document.getElementsByTagName("input");
    for	(var i=0; i < colInputs.length; i++) {
        colInputs[i].checked= !colInputs[i].checked;
    }
}

function reunit(filesize) {
    var unit;
    filesize=parseInt(filesize);
    if (filesize>1024) {
        filesize=filesize/1024;
        unit="K"
    }
    if (filesize>1024) {
        filesize=filesize/1024;
        unit="M"
    }
    if (filesize>1024) {
        filesize=filesize/1024;
        unit="G"
    }
    return	Math.round(filesize*100)/100+unit;
}

function ui_alert(msg,title,url) {
    var html;
    html='<div id="dialog" title="'+title+'">';
    html=html+'<p>'+msg+'</p></div>';
    $("#ajax_ui").html(html);
    $( "#dialog" ).dialog({
        modal: true,
        buttons: {
            '确定': function() {
                $( this ).dialog( "close" );
                if ( typeof url!='undefined') {
                    window.location.href=url;
                }
            }
        }
    });
}

function ui_contact_to() {
    var html;
	var rad=Math.random();
    html='<div id="dialog" title="联系人中添加" ">';
    html=html+'<p class="validateTips"></p><iframe id="contact-dialog" frameborder="0" scrolling="no" width="400px" height="350px" src="/Contact/dialog/'+rad+'" ></iframe><p class="validateTips"></p></div>';
	html=html+'<div id="returnhtml" style="display:none"></div>';
    $("#ajax_ui").html(html);
    $( "#dialog" ).dialog({
        modal: true,
        height:490,
        width:440,
        buttons: {
            '确定': function() {
               	$("#returnhtml a.lm_addr").each( function(i) {
                        $("#recever  span.rec_wrap").append('<span emp_id="'+$(this).attr("emp_id")+'" title="'+$(this).attr("title")+'">'+jQuery.trim($(this).text())+'; </span>');
                });
                $( this ).dialog( "close" );
            },
            '取消': function() {
                $( this ).dialog( "close" );
            }
        }
    });
}

function ui_contact_cc() {
    var html;
	var rad=Math.random();
    html='<div id="dialog" title="联系人中添加" ">';
    html=html+'<p class="validateTips"></p><iframe id="contact-dialog" frameborder="0" scrolling="no" width="400px" height="350px" src="/Contact/dialog/rad/'+rad+'" ></iframe><p class="validateTips"></p></div>';
	html=html+'<div id="returnhtml"  style="display:none"></div>';
    $("#ajax_ui").html(html);
    $( "#dialog" ).dialog({
        modal: true,
        height:490,
        width:440,
        buttons: {
            '确定': function() {
				$("#returnhtml a.lm_addr").each( function(i) {
				  $("#copy_to  span.rec_wrap").append('<span emp_id="'+$(this).attr("emp_id")+'" title="'+$(this).attr("title")+'">'+ jQuery.trim($(this).text())+'; </span>');
                });
                $( this ).dialog( "close" );
            },
            '取消': function() {
                $( this ).dialog( "close" );
            }
        }
    });
}

function ui_contact_inside(target){
    var html;
	var rad=Math.random();
    html='<div id="dialog" title="联系人中添加" ">';
    html=html+'<p class="validateTips"></p><iframe id="contact-dialog" frameborder="0" scrolling="no" width="400px" height="350px" src="/Contact/dialog2/rad/'+rad+'" ></iframe><p class="validateTips"></p></div>';
	html=html+'<div id="returnhtml"  style="display:none"></div>';
    $("#ajax_ui").html(html);
    $( "#dialog" ).dialog({
        modal: true,
        height:490,
        width:440,
        buttons: {
            '确定': function(){
				$("#returnhtml a.lm_addr").each(function(i){
				  $("#div_"+target+"  span.rec_wrap").append('<span position_no="'+$(this).attr("position_no")+'" emp_id="'+$(this).attr("emp_id")+'" title="'+$(this).attr("title")+'">'+ jQuery.trim($(this).text())+'; </span>');
                });
              //  $( this ).dialog( "close" );
            },
            '取消': function() {
                $( this ).dialog( "close" );
            }
        }
    });
}


