var url = "/ajax.php";

function load(page) {
var load = window.open(page,'','scrollbars=no,menubar=no,height=400,width=500,resizable=no,toolbar=no,location=no,status=no');
}

function showPage(page,scrollbars,width,height){
var load = window.open(page,'','scrollbars=' + scrollbars + ',menubar=no,height=' + height + ',width=' + width + ',resizable=no,toolbar=no,location=no,status=no');
}


function showSecondTopFloater(){
	me = document.getElementById("second_top_floater");
	if (!(me != null)){
		me = document.all.second_top_floater;
	}
		if (me != null && me.style.display=="block"){
			me.style.display="none";
		    //link.innerHTML="絵文字表示";
			}
		else {
			if (me != null && me.style.display=="none"){
				me.style.display="block";
			    //link.innerHTML="絵文字非表示";
			} else {
			    me.style.display="block";
			}
		}
}


function showSecondTopFloaterRight(){
	me = document.getElementById("second_top_floater_right");
	if (!(me != null)){
		me = document.all.second_top_floater_right;
	}
		if (me != null && me.style.display=="block"){
			me.style.display="none";
		    //link.innerHTML="絵文字表示";
			}
		else {
			if (me != null && me.style.display=="none"){
				me.style.display="block";
			    //link.innerHTML="絵文字非表示";
			} else {
			    me.style.display="block";
			}
		}
}



function uniqueClientUsername(username,lang){
	if (username.length < 1){
		return true;
	}
	var data="function=isUniqueUsername";
	data += "&username=" + username;
	data += "&lang=" + lang;
	httpRequest("POST",url,true,handleUniqueUsernameUpdate,data);
	//$.post(url, { "function":"isUniqueUsername","username":username,"lang":lang},handleUniqueUsernameUpdate);
}


function handleUniqueUsernameUpdate(response){
if(request.readyState == 4){
if (request.status == 200){
			var response = request.responseText;
			if (response.length > 0){
				alert(response);
				document.getElementById("username").value="";
			}
   } else {
       alert("A problem occurred. Request.status was " + request.status);
   }

	} 
}




function uniqueClientPassword(password,lang)
{
	if (password.length < 1){
		return true;
	}
	var data="function=isUniquePassword";
	data += "&password=" + escape(password);
	data += "&lang=" + lang;
	httpRequest("POST",url,true,handleUniquePasswordUpdate,data);
}


function handleUniquePasswordUpdate(){
if(request.readyState == 4){
if (request.status == 200){
			var response = request.responseText;
			if (response.length > 0){
				alert(response);
				document.getElementById("password").value="";
			}
   } else {
       alert("A problem occurred. Request.status was " + request.status);
   }

	} 
}


function flashFix(o){document.write(o)}


function addLoadEvent(func) { 
	  var oldonload = window.onload; 
	  if (typeof window.onload != 'function') { 
	    window.onload = func; 
	  } else { 
	    window.onload = function() { 
	      if (oldonload) { 
	        oldonload(); 
	      } 
	      func(); 
	    } 
	  } 
	} 

function openWindow(page) {
var load = window.open(page,'','scrollbars=no,menubar=no,height=400,width=500,resizable=no,toolbar=no,location=no,status=no');
}

//	addLoadEvent(nameOfSomeFunctionToRunOnPageLoad); 



function addCenterElement(code) {
  var ni = document.getElementById('messageDiv');
  var numi = document.getElementById('theValue');
  var num = (document.getElementById('theValue').value -1)+ 2;
  numi.value = num;
  var newdiv = document.createElement('div');
  var divIdName = 'my'+num+'Div';
  newdiv.setAttribute('id',divIdName);
  newdiv.innerHTML = code + '<br><a href=\'#\' onclick=\'removeCenterElement('+divIdName+')\'>Close</a>';
  ni.appendChild(newdiv);
}



function removeCenterElement(divNum) {
  var d = document.getElementById('messageDiv');
  var olddiv = document.getElementById(divNum);
  d.removeChild(olddiv);
}


// for iphone
function updateLayout(){
	switch(window.orientation){
	case 0: case 180:
		var orient = "portrait";
		break;
	case 90: case -90:
		var orient = "landscape";
		break;
	}
	document.body.setAttribute("orient",orient);
	setTimeout(function() { window.scrollTo(0,1);},0);
}


function setAdvice(content){
if (document.getElementById("advice") != null){
document.getElementById("advice").value=content;
}
}


var request = null;

/* import this into any file to use Ajax XMLHttpRequests
   params:
   reqType - GET or POST
   url - of servlet that will return data
   asynch - true or false
   respHandle - function that will handle the response
   5th param is optional and should contain the data a POST request is supposed to send
*/
function httpRequest(reqType,url,asynch,respHandle){
   try {
     request = new XMLHttpRequest();
   } catch (trymicrosoft) {
     try {
       request = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (othermicrosoft) {
       try {
         request = new ActiveXObject("Microsoft.XMLHTTP");
       } catch (failed) {
         request = false;
       }
     }
   }

	if (request){
		if(reqType.toLowerCase() != "post"){
			initReq(reqType,url,asynch,respHandle);
		} else {
			var args = arguments[4];
			if (args != null && args.length > 0){
				initReq(reqType,url,asynch,respHandle,args);
			}
		}
		
	} else {
        alert("Error initializing XMLHttpRequest!");
	}
	
}




