﻿////////Ajax使用部分
var GO = function(elemId)
{
	return document.getElementById(elemId);
}

//在指定的元素上显示返回内容
function ajax_view(url,method,param,div_id)
{
	xmlHttp = get_xmlHttp();
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			GO(div_id).innerHTML =  xmlHttp.responseText ;
		}
	}
	method = method.toUpperCase();
	if(method == 'GET')
	{
	    url = url + '?' + param;
	    xmlHttp.open(method,url,true);
		xmlHttp.send(null);
	}
	else
	{
	    xmlHttp.open(method,url,true);
	    xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		xmlHttp.send(param);
	}
}

function ajax_callmyfunction(url,method,param,myCallFunction)
{
    xmlHttp = get_xmlHttp();
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			myCallFunction(xmlHttp.responseText) ;
		}
	}
	method = method.toUpperCase();
	if(method == 'GET')
	{
	    url = url + '?' + param;
	    xmlHttp.open(method,url,true);
		xmlHttp.send(null);
	}
	else
	{
	    xmlHttp.open(method,url,true);
	    xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		xmlHttp.send(param);
	}
}

function get_xmlHttp()
{
	var xmlHttp;
	try
	{    // Firefox, Opera 8.0+, Safari    
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{    // Internet Explorer    
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	return xmlHttp;
}

function get_form_elements(form_id)
{
    var form = GO(form_id);
	str = '';
	if(form)
	{
	    for(i=0;i<form.elements.length;i++)
	    {
		    c = form.elements[i];
		    type = c.type ;
		    if((type == 'text' || type == 'password' || type == 'checkbox' || type == 'radio' || type == 'hidden' || type == 'textarea' || type == 'select-one') && c.value != '')
		    {
			    if(type == 'radio' || type == 'checkbox')
			    {
				    if(c.checked == true)
				    {
					    str += c.id + '=1&';
				    }
			    }
			    else
			    {
					    str += c.id + '=' + c.value + '&';
			    }
		    }
	    }
	}
	str = encodeURI(str.substring(0, str.length - 1));
	return str;
}