var pop1_opened = false;
var pop1;
function popup(text,title)
{
	if(pop1_opened)
	{
		pop1.close();
	}
	pop1=window.open('','pop','width=250,height=250,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes');
	pop1_opened=true;
	html ='<html>';
	html+='	<header>';
	html+='		<title>'+title+'</title>';
	html+='	</header>';
	html+='	<body>';
	html+='		<div>'+text+'</div>';
	html+='<br/>';
	html+='		<div align="center"><a href="javascript:;" onClick="opener.pop1_opened=false;window.close()">close</a></div>';
	html+='	</body>';
	html+='</html>';
	pop1.document.write(html);
}

function popupPic(picURL)
{ 
	window.open( "scripts/pop.htm?"+picURL, "","scrollbars=yes, resizable=0, status=0,left=0, top=0,HEIGHT=200,WIDTH=200"); 				
}

function searchSwitch(obj, e, title)
{
	if(e=='focus')
	{
		if(obj.value == title)
		{
			obj.value = '';								
		}
	}
	else
	{
		if(obj.value == '')
		{
			obj.value = title;								
		}		
	}		
}	

function do_search()
{	
	var f=document.forms['search'];
	var t=document.getElementById('key');
	var val = t.value;
	val = encode(val, 'utf8');
	val = escape(val);
	var url=f.action+val+'/';
	
	window.location=url;
	return false;
}

var unreserved = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.~";
var reserved = "!*'();:@&=+$,/?%#[]";
var allowed = unreserved + reserved;
var hexchars = "0123456789ABCDEFabcdef";


function gethex(decimal) {
  return "%" + hexchars.charAt(decimal >> 4) + hexchars.charAt(decimal & 0xF);
  }

function encode(for_decode,charset) {

  var decoded = for_decode;
  var encoded = "";


  if (charset == "ascii") {

    var notascii = "";

    for (var i = 0; i < decoded.length; i++ ) {
      var ch = decoded.charAt(i);
      if (unreserved.indexOf(ch) != -1) {
        encoded = encoded + ch;
      } else {
        var charcode = decoded.charCodeAt(i);
        if (charcode < 128) {
          encoded = encoded + gethex(charcode);
        } else {
          encoded = encoded + ch;
          notascii = notascii + ch + " ";
        }
      }
    }
	return encoded;
    if (notascii != "") alert("Warning: Non-ASCII characters in decoded text!\n\nThus, these characters have not been encoded:\n" + notascii);
  }


  if (charset == "utf8") {
    for (var i = 0; i < decoded.length; i++ ) {
      var ch = decoded.charAt(i);
      if (unreserved.indexOf(ch) != -1) {
        encoded = encoded + ch;
      } else {

        var charcode = decoded.charCodeAt(i);

        if (charcode < 128) {
          encoded = encoded + gethex(charcode);
        }

        if (charcode > 127 && charcode < 2048) {
          encoded = encoded + gethex((charcode >> 6) | 0xC0);
          encoded = encoded + gethex((charcode & 0x3F) | 0x80);
        }

        if (charcode > 2047 && charcode < 65536) {
          encoded = encoded + gethex((charcode >> 12) | 0xE0);
          encoded = encoded + gethex(((charcode >> 6) & 0x3F) | 0x80);
          encoded = encoded + gethex((charcode & 0x3F) | 0x80);
        }

        if (charcode > 65535) {
          encoded = encoded + gethex((charcode >> 18) | 0xF0);
          encoded = encoded + gethex(((charcode >> 12) & 0x3F) | 0x80);
          encoded = encoded + gethex(((charcode >> 6) & 0x3F) | 0x80);
          encoded = encoded + gethex((charcode & 0x3F) | 0x80);
        }

      }

    }  // end of for ...
    return encoded;
  }
}