$(function(){
    $.each($("#picture_list_img").children("img"),function(i,item){
        $(item).load(function(){
            $(this).width($(this).width()>500?500:$(this).width());
        });
    });

    $(".menu_button").click(function(){
    	if($.trim($(".menu_input").val())=="Search info...")
    	{
    		alert("Please input a search term");
    		return false;
    	}
    	else
    	{
    		$(".menu_button").submit();
    	}
    });
});

//刷新验证码
$(function(){
    /*
     *增加中文验证
     **/
    $.validator.addMethod("ch", function(value, element) {
        return this.optional(element) || !(/[\u4e00-\u9fa5]+/.test(value));
      }, '<br /><img src="/images/front/error.gif" width="12" height="12" />please fill in English');

    $('#passport_sign_refresh').click(function(){
        $('#passport_sign_code').attr('src','/common/index/authcode?t='+new Date().getTime());
        $('#head_code').attr('src',$('#passport_sign_code').attr('src'));
    });
   $("#email_form").validate({
   	   onkeyup:false,
       rules:{
           "msg_name":{
               required:true,ch:true
           },
           "msg_email":{
                required:true,email:true
           },
           "msg_title":{
               required:true,ch:true
           },
           "msg_content":{
                required:true,ch:true
           },
            "auth_code":{
            	required:true,
            	remote:{
            		type:"GET",
            		url:"/common/ajax/judgeauthcode",
            		data:{
            			auth_code:function(){return $("#auth_code1").val();}
            		}
            	}
            }
       },
       messages:{
           "msg_name":{
               required:'<img src="/images/front/error.gif" width="12" height="12" />please fill your name',
               ch:'<img src="/images/front/error.gif" width="12" height="12" />please fill in English'
           },
           "msg_email":{
               required:'<img src="/images/front/error.gif" width="12" height="12" />please fill your email',
               ch:'<img src="/images/front/error.gif" width="12" height="12" />please fill in English'
           },
           "msg_title":{
               required:'<img src="/images/front/error.gif" width="12" height="12" />please fill the title',
               ch:'<img src="/images/front/error.gif" width="12" height="12" />please fill in English'
           },
           "msg_content":{
               required:'<img src="/images/front/error.gif" width="12" height="12" />please fill the content',
               ch:'<img src="/images/front/error.gif" width="12" height="12" />please fill in English'
           },
           "auth_code":{
            	required:'<img src="/images/front/error.gif" width="12" height="12" />The auth code is required',
            	remote: jQuery.format('<img src="/images/front/error.gif" width="12" height="12" />It\'s wrong,please reset')
            }
       }
   });
})

    function AddFavorite(sURL, sTitle) {
        try {
            window.external.addFavorite(sURL, sTitle);
        } catch (e) {
            try {
                window.sidebar.addPanel(sTitle, sURL, "");
            } catch (e) {
                alert("加入收藏失败，请使用Ctrl+D进行添加");
            }
        }
    }

    /**
     * 处理图片大小，以防失帧
     */
    function setImgSizeWH(theURL,sImage,imgW,imgH)
    {
        var imgObj;
        imgObj = null;
        imgObj=new Image();
        imgObj.src=theURL;
        if((imgObj.width!=0)&&(imgObj.height!=0))
        {
            if(imgObj.width>imgW||imgObj.height>imgH)
            {
                var iHeight=imgObj.height*imgW/imgObj.width;
                if(iHeight<=imgH)
                {
                    sImage.width=imgW;sImage.height=iHeight;
                }
                else
                {
                    var iWidth=imgObj.width*imgH/imgObj.height;
                    sImage.width=iWidth;sImage.height=imgH;
                }
            }
            else
            {
                sImage.width=imgObj.width;sImage.height=imgObj.height;
            }
        }
        else
        {
            sImage.width=imgW;
            sImage.height=imgH;
        }
    }

    function setElementMiddle(obj,width,height,state){
        if(state==true){
            var iHeight = obj.clientHeight;
            var iWidth = obj.clientWidth;
            if(height>0 && width>0){
                if(iHeight < height){
                        $(obj).css("margin-top",(height-iHeight)/2+"px");
                }
                if(iWidth < width){
                        $(obj).css("margin-left",(width-iWidth)/2+"px");
                }
            }
        }

    }

    /**
     * 设置图片宽度
     */
    function setImgWidth(theURL,sImage,imgWidth){
        var imgObj;
        imgObj = null;
        imgObj=new Image();
        imgObj.src=theURL;
        if((imgObj.width!=0))
        {
            if(imgObj.width>imgWidth)
            {
                sImage.width = imgWidth;
            }
            else
            {
                sImage.width=imgObj.width;
            }
        }
        else
        {
            sImage.width=imgWidth;
        }
    }
    function initStatics(user_id)
    {
	$.ajax({
		type:"GET",
		url:"/common/ajax/statics",
		data:{user_id:user_id},
		success:function(response)
		{
			
		}
	});
    }
    
