function readCookie(name) {
   arg=name+"=";
   alen=arg.length;
   clen=document.cookie.length;
   i=0;
   while (i<clen) {
      j=i+alen;
      if (document.cookie.substring(i,j) == arg) {
          return readCookieVal(j);
          }
      i=document.cookie.indexOf(" ",i) + 1;
      if (i === 0) {break;}
   }
}

function readCookieVal(offset) {
   endstr=document.cookie.indexOf(";",offset);
   if (endstr == -1) {endstr=document.cookie.length;}
   return unescape(document.cookie.substring(offset,endstr));
}

function writeCookie(name, value) {
   argv=arguments;
   argc=arguments.length;
   expires=(argc>2) ? argv[2] : null;
   path=(argc>3) ? argv[3] : null;
   domain=(argc>4) ? argv[4] : null;
   secure=(argc>5) ? argv[5] : false;
   document.cookie=name+"="+escape(value) +
     ((expires === null) ? "" : ("; expires="+expires.toUTCString())) +
     ((path === null) ? "" : ("; path="+path)) +
     ((domain === null) ? "" : ("; domain="+domain)) +
     ((secure === true) ? "; secure" : "");
}

function removeCookie(name) {
   threeDays=3*24*60*60*1000; //in millisecounds
   expDate=new Date();
   expDate.setTime(expDate.getTime()-threeDays);
   document.cookie=name+'=foobar; expires='+expDate.toGMTString();
}

function load_page()
{
	country = $('navi').options[$('navi').selectedIndex].value;
	if (country != '') {
		if ($('remember_location').checked) {
			writeCookie('country', country);
		}
		load_page_by_country(country);
	}
}

function load_page_by_country(country) {
	if (country != 'CYM') {
		window.open('/main','_top');
	} else {
		window.open('/other','_top');
	}
}
