function initAjax()	{
	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 set_class() {
	var c = set_class.arguments[0];
	for(i = 1; i < set_class.arguments.length; i++) {
		document.getElementById(set_class.arguments[i]).className = c;
	}
}

function exposeKeywordDef(element, newClass) {
	element.lastChild.className = newClass;
}
function hideKeywordDef(element) {
	element.lastChild.className = 'keyword_definition_hide';

}

function mailCheck(mailForm) {
	if(mailForm.name.value.length < 1) {
		alert("Please enter your name.");
		return false;
	}
	if(mailForm.mail.value != mailForm.mailconf.value) {
		alert("The email addresses you entered do not match!");
		return false;
	}
	if(mailForm.comments.value.length < 1) {
		alert("Please enter a comment.");
		return false;
	}
}
function submissionCheck(mailForm) {
	if(mailForm.name.value.length < 1) {
		alert("Please enter your name.");
		return false;
	}
	if(mailForm.mail.value != mailForm.mailconf.value) {
		alert("The email addresses you entered do not match!");
		return false;
	}
	if(mailForm.title.value.length < 1) {
		alert("Please give your article a title.");
		return false;
	}
	if(mailForm.article.value.length < 300) {
		alert("Please write a little more. Articles should be at least 300 words.");
		return false;
	}
}


function switchContents(a, b) {
	obj_a = document.getElementById(a);
	obj_b = document.getElementById(b);
	c = obj_a.innerHTML;
	obj_a.innerHTML = obj_b.innerHTML;
	obj_b.innerHTML = c;
}

function getCookie(c_name)	{
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) { 
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end == -1) {				
				c_end=document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return false;
}

function confirm_delete(url,title) {
	input = confirm("Are you sure you want to delete the article, \"" + title + "\"?");
	if(input) {
		window.location = url;
	}else {
	}
}

function loginBox() {
	var out = "<div id=\"smlogin_form\">";
	out += "<div class=\"top\"><\/div>";
	out += "<div class=\"mid\">";
	
	out += "<form action=\"http://in-japan.jp/login/index.php\" menthod=\"post\">";
	out += "<div class=\"username\"><label for=\"login\">Username:<\/label><br /><input type=\"text\" name=\"login\" size=\"22\" /><\/div>";
	out += "<div class=\"password\"><label for=\"password\">Password:<\/label><br /><input type=\"password\" name=\"password\" size=\"22\" /><\/div>";
	out += "<div class=\"rememberme\"><input type=\"checkbox\" name=\"rememberme\"> <label for=\"rememberme\">Remember Me!<\/label><\/div>";
	out += "<div class=\"submit\"><input type=\"submit\" value=\"Log In!\"><\/div>";
	out += "<\/form>";
	
	out += "<a href=\"http://in-japan.jp/login/?action=forgot_password\">Password Recovery<\/a>";
	out += "<br />";
	out += "<a href=\"http://in-japan.jp/login/?action=account_create\">Create Account<\/a>";

	out += "<\/div>";
	out += "<div class=\"btm\"><\/div>";
	out += "<\/div>";
	
	return(out);
}
function welcomeBack($username) {
	var out = "<div style=\"padding: 10px 10px 0px 10px; font-size: 14px; font-weight: bold;\">";
	out += "Welcome back, " + $username + "!";
	out += "<\/div>";
	
	return(out);
}

function rating_rollover(r) {
	for(var i = 1; i <= r; i++) {
		document.getElementById('star_' + i).className = "star_rating_on";
	}
	document.getElementById('rating_text').innerHTML = "Click to rate.";
}
function rating_rollout() {
	document.getElementById('star_1').className = "star_rating_off";
	document.getElementById('star_2').className = "star_rating_off";
	document.getElementById('star_3').className = "star_rating_off";
	document.getElementById('star_4').className = "star_rating_off";
	document.getElementById('star_5').className = "star_rating_off";
	document.getElementById('rating_text').innerHTML = "";
}
function rating_click(r, a, destId) {
	destObj = document.getElementById(destId);
	
	xmlHttp = initAjax();
	
	if(!xmlHttp) {
		destObj.innerHTML = "Your browser does not support this function.";
	}
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.responseText == "login") {
				window.location = "http://in-japan.jp/login/?action=quicklogin&mode=rate_article&r="+r+"&a="+a+"&re="+encodeURI(window.location);
			}else {
				destObj.innerHTML = xmlHttp.responseText;
			}
		}
	}
	
	destObj.innerHTML = "Processing. Please wait... ";

	xmlHttp.open("GET","/rating/?action=rate&r=" + r + "&a=" + a, true);
    xmlHttp.send(null);
}
function rating_get(a, destId) {
	destObj = document.getElementById(destId);
	
	xmlHttp = initAjax();
	
	if(!xmlHttp) {
		destObj.innerHTML = "Your browser does not support this function.";
	}
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			destObj.innerHTML = xmlHttp.responseText;
		}
	}
	
	destObj.innerHTML = "Processing. Please wait... ";

	xmlHttp.open("GET","/rating/?action=get&a=" + a, true);
    xmlHttp.send(null);
}
function rating_check(u, a) {
	xmlHttp = initAjax();
	
	xmlHttp.open("GET","/rating/?action=check&u=" + u + "&a=" + a, false);
    xmlHttp.send(null);
    
    return xmlHttp.responseText;
}