//get cookie value
readCookie = function(name){
    var cookieValue = '';
    var search = name + '=';
    if(document.cookie.length > 0){ 
        offset = document.cookie.indexOf(search);
        if (offset != -1){
            offset += search.length;
            end = document.cookie.indexOf(';', offset);
            if (end == -1) end = document.cookie.length;
            cookieValue = unescape(document.cookie.substring(offset, end))
        }
    }
    return cookieValue;
}
/*
function readCookie(varname){
	var tmp_ary = new Array();
	if (varname){
		a = document.cookie.indexOf(varname+"=");
		if (a != -1){
			b = document.cookie.substring((a+varname.length+1),document.cookie.length);
			c = b.split(";");
			d = c[0];
			return unescape(d);
		}
	}
}
*/
//set cookie
writeCookieDomain = function(name,value,hours){
    var expire = '';
    if(hours != null){
        expire = new Date((new Date()).getTime() + hours * 3600000);
        expire = '; expires=' + expire.toGMTString();
    }
    document.cookie = name + '=' + escape(value) + expire + ' ; path=/; domain = abab.com';
}


onFocusClear = function () {
    if ('请输入游戏名'==document.getElementById('keyword').value) {
        document.getElementById('keyword').value = '';
    }
}

//创建对象
function create_obj(){
    var http_request = false;

    //开始初始化XMLHttpRequest对象
    if(window.XMLHttpRequest) { //Mozilla 浏览器
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {//设置MiME类别
            http_request.overrideMimeType("text/xml");
        }
    }
    else if (window.ActiveXObject) { // IE浏览器
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!http_request) { // 异常，创建对象实例失败
        return false;
    }

    return http_request;
}

//初始化、指定处理函数、发送请求的函数
//var postStr = "ACT=reply&bookid="+bookid+"&book_content="+ book_content;
//type:post or get
function send_request(http_request,url,postStr) {
    // 确定发送请求的方式和URL以及是否同步执行下段代码
    http_request.open("POST", url, true);
    http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
    http_request.send(postStr);
}

function heji_ajax_page(urlstr)
{
    document.getElementById('heji_ajax_str').innerHTML = '查询中...';
    var http_request = create_obj();
    http_request.onreadystatechange = function(){
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
                if (!http_request.responseText) {
                    document.getElementById('heji_ajax_str').innerHTML = "查询失败";
                } else {
				    document.getElementById('heji_ajax_str').innerHTML = http_request.responseText;
                }
            }
        }
    }

    var postStr = '';
    var urlstrnew = 'http://www.abab.com/app/'+urlstr;
    send_request(http_request,urlstrnew,postStr);
}
//图片自适应
function AutoResizeImage(maxWidth,maxHeight,objImg){
	var img = new Image();
	img.src = objImg.src;
	var hRatio;
	var wRatio;
	var Ratio = 1;
	var w = img.width;
	var h = img.height;
	wRatio = maxWidth / w;
	hRatio = maxHeight / h;
	if (maxWidth ==0 && maxHeight==0){
		Ratio = 1;
	}else if (maxWidth==0){ //
	if (hRatio<1) Ratio = hRatio; 
	}else if (maxHeight==0){
	if (wRatio<1) Ratio = wRatio;
	}else if (wRatio<1 || hRatio<1){
	Ratio = (wRatio<=hRatio?wRatio:hRatio);
	}
	if (Ratio<1){
		w = w * Ratio;
		h = h * Ratio;
	}
	objImg.height = h;
	objImg.width = w;
}
