﻿    //prototype_ProajaxPro访问代理
    // opt: url 访问地址 string,
    //		ajaxProMethod ajaxpro对应的方法 string
    //		params 请求方法使用的参数 object
    //		success 成功回调方法 将返回function(backinfo,params)
    //				backinfo:服务器返回的对象 object
    //				params 请求方法使用的参数 object
    //		failure 请求失败的回调方法 function()
    function myAjax(options){
	    var opt=options||{};
	    var params=opt.params||{};
	    var AjaxPro=new Ajax.Request(opt.url, {
		    method: 'post',
		    requestHeaders : ['X-AjaxPro-Method' , opt.ajaxProMethod],
		    postBody : Object.toJSON(params),
		    onSuccess: function(response) {
			    if(response){
				    var tmp;
				    eval("tmp="+response.responseText+";");
				    if(tmp.value && opt.success){
					    opt.success(tmp.value,params);
				    } else if(tmp.error &&　opt.failure){
					    opt.failure(tmp.error,params);
				    } else if(opt.failure){
					    opt.failure('返回数据错误:'+response.responseText,params);
				    }
			    } else {
				    if(opt.failure) opt.failure('没有得到返回数据',params);
			    }
		    },
		    onFailure : function(){
			    if(opt.failure) opt.failure('通讯失败',params);
		    }
	    });
    }
    
   //自适应显示图片
   function    DrawImage(ImgD,iwidth,iheight){   
        var       flag=false; 
        var       image=new       Image();   
        if(iwidth==null)iwidth=240;           //定义允许图片宽度   
        if(iheight==null)iheight=320;           //定义允许图片高度   
        image.src=ImgD.src;   
        if(image.width>0       &&       image.height>0){   
        flag=true;   
        if(image.width/image.height>=       iwidth/iheight){   
            if(image.width>iwidth){             
                ImgD.width=iwidth;   
                ImgD.height=(image.height*iwidth)/image.width;   
            }
            else{   
                ImgD.width=image.width;             
                ImgD.height=image.height;   
            }   
            ImgD.alt=image.width+"×"+image.height;   
        }   
        else
        {   
            if(image.height>iheight)
            {             
                ImgD.height=iheight;   
                ImgD.width=(image.width*iheight)/image.height;     
            }
            else
            {   
                ImgD.width=image.width;             
                ImgD.height=image.height;   
            }   
            ImgD.alt=image.width+"×"+image.height;   
            }   
        } 
        ImgD.style.display = "";    
    }  
 
    var  interval=1; 
    function changeBoxMarginLeft(v,val){ 
        if(v.style.marginLeft == ""){ 
            v.style.marginLeft = "0px"; 
        } 
        var current = Number(v.style.marginLeft.substr(0,v.style.marginLeft.indexOf("p"))); 
        v.style.marginLeft = Number(current + val) + "px"; 
    } 

    function changeBoxMarginTop(v,val){ 
        if(v.style.marginTop == ""){ 
            v.style.marginTop = "0px"; 
        } 
        var current = Number(v.style.marginTop.substr(0,v.style.marginTop.indexOf("p"))); 
        v.style.marginTop = Number(current + val) + "px"; 
    } 
    function over(v){ 
        var maxWidth = v.width * 2; 
        if(v.interval != undefined){ 
            clearInterval(v.interval); 
        } 
        v.intervalID = setInterval(function(){ 
            if(v.width < maxWidth) { 
                v.width = v.width + 10; 
                topchange = v.width * 1/2 - v.height; 
                v.height = v.width * 1/2; 
                changeBoxMarginLeft(v,-5); 
                changeBoxMarginTop(v,-topchange/2); 
            } 
            else{ 
                clearInterval(v.intervalID);  
            } 
        },interval); 
    } 
    function out(v){  
        var minWidth = v.width / 2; 
        clearInterval(v.intervalID); 
        v.interval = setInterval(function(){ 
            if(v.width > minWidth) { 
                v.width = v.width - 10 ; 
                v.height = v.width * 1/2; 
                changeBoxMarginLeft(v,5); 
                changeBoxMarginTop(v,topchange/2) 
            } 
            else{ 
                clearInterval(v.interval);  
            } 
        },interval); 
    } 
    
    //字符串字符个数
    function lenStr(s) { 
        var l = 0; 
        var a = s.split(""); 
        for (var i=0;i<a.length;i++) { 
            if (a[i].charCodeAt(0)<299) { 
                l++; 
            } else { 
                l+=2; 
            } 
        } 
        return l; 
    }
    
    /*cookie的操作  begin*/
    //添加cookie
    function addCookie(objName,objValue,objHours){
        var str = objName + "=" + escape(objValue);
        //为0时不设定过期时间，浏览器关闭时cookie自动消失
        if(objHours > 0){
             var date = new Date();
             var ms = objHours*3600*1000;
             date.setTime(date.getTime() + ms);
             str += "; expires=" + date.toGMTString();
        }
        document.cookie = str;
   }
  
  //获取指定名称的cookie的值
   function getCookie(objName){
        var arrStr = document.cookie.split("; ");
        for(var i = 0;i < arrStr.length;i ++){
             var temp = arrStr[i].split("=");
             if(temp[0] == objName) return unescape(temp[1]);
        } 
   }
  
  //为了删除指定名称的cookie，可以将其过期时间设定为一个过去的时间
   function delCookie(name){
        var date = new Date();
        date.setTime(date.getTime() - 10000);
        document.cookie = name + "=a; expires=" + date.toGMTString();
   }
  
  //读取所有保存的cookie字符串
   function allCookie(){
        var str = document.cookie;
        if(str == ""){
            str = "没有保存任何cookie";
        }
        return str;
   }
   /*cookie的操作  end*/
