//AJAX 函式庫
function getRandomInt(max) {
  return Math.round((Math.random() * (max-1) ))+1;
}

function getUncacheUrl(url){
  if( url.indexOf('?') == -1 )
	return url +"?" + getRandomInt(1000) + 'd=' + new Date().getTime();
  else
	return url +"&" + getRandomInt(1000) + 'd=' + new Date().getTime();
}

function calnum(src) {
  url = getUncacheUrl(src);
  new Ajax.Request(url, {
    method: 'get',
    onComplete: function(transport) {}
  });          	
}

function changeContent(dstObj,url,id){
  new Ajax.Request(url, {
    method: 'get',
    onComplete: function(transport) {
      var obj = document.getElementById(dstObj);
	  obj.innerHTML = transport.responseText;
	  if(obj.childNodes[0].tagName.toUpperCase() == 'SPAN')
		 document.getElementById(id).style.display = '';
    }
  });          	
}

function changeContent2(dstObj,url,id) {
  new Ajax.Request(url, {
    method: 'get',
    onComplete: function(transport) {
      var obj = document.getElementById(dstObj);
	  obj.innerHTML = transport.responseText;
	  if(obj.childNodes[0].tagName.toUpperCase() == 'SPAN') {
		 var obj2 = document.getElementById(id).innerHTML;
		 while (obj2.indexOf('&gt;')!=-1) obj2 = obj2.replace('&gt;','>');
		 while (obj2.indexOf('&lt;')!=-1) obj2 = obj2.replace('&lt;','<');
		 while (obj2.indexOf('&quot;')!=-1) obj2 = obj2.replace("&quot;","\"");
		 eval(obj2);
	  }
    }
  });          	
}

function ajax_download1(cid1,cid2,id) {
  changeContent2('download_area','/ajax/download1.php?cid1='+cid1+'&cid2='+cid2+'&id='+id,'download_ajax');
}
function ajax_download2(cid1,cid2,id) {
  changeContent2('download_area','/ajax/download2.php?cid1='+cid1+'&cid2='+cid2+'&id='+id,'download_ajax');
}
