setCookie("user_width",document.body.clientWidth);


//////////////////////////////////////////////////////////////////////////////////// quick list

var quick_list_a=new Array();

if(typeof(getCookie("quick_list"))=="string" && getCookie("quick_list").search("|")!= -1){
	var quick_list_a=cookiestr2array(getCookie("quick_list"));
}
else{
	if(typeof(getCookie("quick_list"))=="string" && getCookie("quick_list").search("html")!= -1){
		quick_list_a[0]=getCookie("quick_list").split(",");
	}
}
if (document.location.toString().indexOf("quick_list.php") != -1) {
	disp_quick_list();
	}

function disp_quick_list () {
	if(typeof(document.getElementById("quick_list_page_box")) != "undefined") {
		var quick_list_t = "";
		if (quick_list_a.length > 0) {
			for (s in quick_list_a) {
				if(quick_list_a[s][2].indexOf("jpg") != -1 ) {
					quick_list_t+="<div class='quick_list_page_u'><div><a href='"+quick_list_a[s][1]+"'><img src='"+quick_list_a[s][2]+"' alt='"+quick_list_a[s][0]+"' /></a></div>"+quick_list_a[s][0]+"<br /><span onClick=\"del_quick_list('"+quick_list_a[s][0]+"')\">Delete this manga</span></div>";
				}
				else {
					quick_list_a.splice(s,1)
					setCookie("quick_list",array2cookiestr(quick_list_a),getExpDate(100,1,1));
				}
			}
		}
		else {
			quick_list_t="<div style='margin-top:200px; font-size:18px; text-align:center;'>Your Quick list is blank!</div>";
		}
		document.getElementById("quick_list_page_box").innerHTML=quick_list_t;
	}
}

function del_quick_list(name){
	if(confirm("Are you sure?")){
		var qt_id;
		for (i=0;i<quick_list_a.length;i++) {
			if (quick_list_a[i][0] == name) {
				qt_id = i;
				break;
			}
		}
		if (isNaN(qt_id)) {
			alert("This work is not in your QuickList!");
			return;
		}
		quick_list_a.splice(qt_id,1)
		setCookie("quick_list",array2cookiestr(quick_list_a),getExpDate(100,1,1));
		alert("Manga deleted!");
		disp_quick_list();
		//document.getElementById("xxx").innerHTML = quick_list_a;//////////////
	}
}


function add_quick_list(name,url,thb){
	if(quick_list_a.length>30){
		alert("Quick list is full!Please delete some items first.");
		return;
	}
	for (i=0;i<quick_list_a.length;i++) {
		if (quick_list_a[i][0] == name) {
			alert("This work is already in your QuickList!");
			return;
			break;
		}
	}

	var add_val=new Array(name,url,thb)
	quick_list_a.push(add_val);
	setCookie("quick_list",array2cookiestr(quick_list_a),getExpDate(100,1,1));
	alert("Manga added!");
	//document.getElementById("xxx").innerHTML = quick_list_a;//////////////
}



//////////////////////////////////////////////////////////////////////////////////// check

function check_login(login_s){
	//return false;
	if (login_s == 1) {
		return true;
	}
	else {
		return false;
	}
}

function isnumeric(p)
{
	if (p == "")
	return false;
	var l = p.length;
	var count=0;
	for(var i=0; i<l; i++)
	{
		var digit = p.charAt(i);
		if(digit == "." )
		{
			++count;
			if(count>1) return false;
		}
		else if(digit < "0" || digit > "9")
		return false;
	}
	return true;
}
function isalpha(s)
{
	for (var i=0; i<s.length; i++)
	{
		var Char = s.charAt(i);
		if ((Char < "a" || Char > "z") && (Char < "A" || Char > "Z")
		)
		return false;
	}
	return true;
}

//////////////////////////////////////////////////////////////////////// cookie

function cookiestr2array(in_str){
	if(typeof(in_str)=="string" && in_str.search("|")!= -1){
		var out_arr=in_str.split("|");
		for(i=0;i<out_arr.length;i++){
			if(out_arr[i].search(","!=-1)){
				out_arr[i]=out_arr[i].split(",");
			}
		}
		return out_arr;
	}
}

function array2cookiestr(in_array){
	var out_str="";
	for (i=0;i<in_array.length;i++){
		if(typeof(in_array[i])=='object'){
			if(i<in_array.length-1){
				out_str+=in_array[i].toString()+"|";
			}
			else{
				out_str+=in_array[i].toString();
			}
		}
		else{
			if(i<in_array.length-1){
				out_str+=in_array[i]+"|";
			}
			else{
				out_str+=in_array[i];
			}
		}
	}
	return out_str;
}

function getExpDate(days, hours, minutes)
{
	var expDate = new Date();
	if(typeof(days) == "number" && typeof(hours) == "number" && typeof(hours) == "number")
	{
		expDate.setDate(expDate.getDate() + parseInt(days));
		expDate.setHours(expDate.getHours() + parseInt(hours));
		expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));
		return expDate.toGMTString();
	}
}

//utility function called by getCookie()
function getCookieVal(offset)
{
	var endstr = document.cookie.indexOf(";", offset);
	if(endstr == -1)
	{
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}

// primary function to retrieve cookie by name
function getCookie(name)
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while(i < clen)
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		{
			return getCookieVal(j);
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if(i == 0) break;
	}
	return;
}

// store cookie value with optional details as needed
function setCookie(name,value,expires,path,domain,secure)
{
	document.cookie = name + "=" + escape(value) +
	((expires) ? "; expires=" + expires : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
}

// remove the cookie by setting ancient expiration date
function deleteCookie(name,path,domain)
{
	if(getCookie(name))
	{
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

/////////////////////////////////////////////////////////////////////////////////////////////// change disp
function change_disp (id_in,arr_in) {
	if (document.getElementById(id_in).style.display == "block") {
		document.getElementById(id_in).style.display = "none";
		document.getElementById(arr_in).className = "arr_close";
	}
	else {
		document.getElementById(id_in).style.display = "block";
		document.getElementById(arr_in).className = "arr_open";
	}
}




////////////////////////////////////////////////////////////////////////////////////////////////////
//if(document.getElementById('quick_list_text')){
//	var quick_list_a=new Array();
//    if(typeof(getCookie("quick_list"))=="string" && getCookie("quick_list").search("|")!= -1){
//    var quick_list_a=cookiestr2array(getCookie("quick_list"));
//    }
//      else{
//      if(typeof(getCookie("quick_list"))=="string" && getCookie("quick_list").search("html")!= -1){
//      quick_list_a[0]=getCookie("quick_list").split(",");
//      }
//    }
//    document.getElementById('quick_list_text').innerHTML=get_quick_list(quick_list_a);
//}
/////////////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////login function\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
function LogOut(){
	document.login_form.url.value=window.location.href;
	alert(document.login_form.url.value);
	return true;
}


function CheckLogin(){
	var err='';
	if(!isnumeric(document.login_form.uid.value) || document.login_form.uid.value.length<4){
		err='Wrong user id!';
	}
	if(!isalpha(document.login_form.password.value) || document.login_form.password.value.length<4){
		err=err+'Wrong password!';
	}


	if(err!=''){
		alert(err);
		return false;
	}
	else{
		document.login_form.url.value=window.location.href;
		//alert(document.login_form.url.value);
		return true;
	}

}

