
function NewWindow(mypage, myname, w, h, scroll) 
{ 	
	var winl = (screen.width - w) / 2; 
	var wint = (screen.height - h) / 2; 
	
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable' 
	
	win = window.open(mypage, myname, winprops) 
	
	if (parseInt(navigator.appVersion) >= 4) { 
		win.window.focus(); 
	} 
} 


function NewWindow2(mypage, myname, w, h, scroll) 
{ 	
	var winl = (screen.width - w) / 2; 
	var wint = (screen.height - h) / 2; 
	
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable,status=yes' 
	
	win = window.open(mypage, myname, winprops) 
	
	if (parseInt(navigator.appVersion) >= 4) { 
		win.window.focus(); 
	} 
} 

function Trim(orgString){
  return LTrim(RTrim(orgString))
}

function LTrim(orgString){
  return orgString.replace(/^\s+/,'')
}

function RTrim(orgString){
  return orgString.replace(/\s+$/,'')
}

function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0); 
}

//Same function to check email address
function isValidEmail2(checkThisEmail)
{
var myEMailIsValid = true;
var myAtSymbolAt = checkThisEmail.indexOf('@');
var myLastDotAt = checkThisEmail.lastIndexOf('.');
var mySpaceAt = checkThisEmail.indexOf(' ');
var myLength = checkThisEmail.length;


// at least one @ must be present and not before position 2
// @yellow.com : NOT valid
// x@yellow.com : VALID

if (myAtSymbolAt < 1 ) 
 {myEMailIsValid = false}


// at least one . (dot) afer the @ is required
// x@yellow : NOT valid
// x.y@yellow : NOT valid
// x@yellow.org : VALID

if (myLastDotAt < myAtSymbolAt) 
 {myEMailIsValid = false}

// at least two characters [com, uk, fr, ...] must occur after the last . (dot)
// x.y@yellow. : NOT valid
// x.y@yellow.a : NOT valid
// x.y@yellow.ca : VALID

if (myLength - myLastDotAt <= 2) 
 {myEMailIsValid = false}


// no empty space " " is permitted (one may trim the email)
// x.y@yell ow.com : NOT valid

if (mySpaceAt != -1) 
 {myEMailIsValid = false}

return myEMailIsValid;
}

function InitShared(form)
{
	var shared_value = form.shared.value;
	
	if ( shared_value != null && shared_value != "")  {
		//set the radio button
		for (i = 0; i < form.shared_btn.length; i++)
		{
			if ( form.shared_btn[i].value == shared_value )
				form.shared_btn[i].checked=true;
			else
				form.shared_btn[i].checked=false;
		}
	}
	else	//default value: public
		form.shared_btn[0].checked=true;
}

function CheckShared(form)
{
	var share_value = "Y";
	
	for (i = 0; i < form.shared_btn.length; i++)
	{
		if (form.shared_btn[i].checked)
		share_value = form.shared_btn[i].value; 
	}

	form.shared.value = share_value;
}

function isValidURL(_url) 
{ 
	var re;
	if(_url.indexOf('\"') != -1) {
		return false;
	}
	
	if(_url.indexOf('\'') != -1) {
		return false;
	}
	/*
	re = /(http|ftp|https):\/\/[\w]+(.[\w]+)([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/;
	
	
	return re.test(_url);
	*/
	
	return true;
}

var validChars = "abcdefghijklmnopqrstuvwxyz0123456789-";

/**********
* Domain name rules:
*    Use only letters, numbers, or hyphen ("-") 
*    Cannot begin or end with a hyphen 
*    Must have less than 63* characters, not including .COM, .NET and .ORG *
*
**************/

function isValidHostname(username)
{

	var len = username.length;
	
	if ( len == 0 || len > 63)
		return false;

	username = username.toLowerCase();	
						
    for (i = 0; i < len; i++)
    {   
        var c = username.charAt(i);

        if ( i == 0 || i == len-1 )    {
	        if ( c == "-" )			//if the name begins or ends with a hyphen ("-")	        	
    	    	return false; 
    	}       

        if (validChars.indexOf(c) < 0)			//if there is any invalid char
        	return false; 
    }
    
    return true;
}

function replaceButtonText(buttonId, text)
{
	if (document.getElementById)
	{
		var button=document.getElementById(buttonId);
		if (button)
		{
			if (button.childNodes[0])
			{
				//alert("ch");		
				button.childNodes[0].nodeValue=text;
			}
			else if (button.value)
			{
				//alert("val");		
				button.value=text;
			}
			else //if (button.innerHTML)
			{
				//alert("inner");
				button.innerHTML=text;
			}		
		}
	}
}

function SelectAll(frm, checkboxId)
{  
	for (var i=0;i<frm.elements.length;i++) {
		var e = frm.elements[i];
		if (e.name == checkboxId ) {
			e.checked = true;
		}
	}
	
}

function DeselectAll(frm, checkboxId)
{  
	for (var i=0;i<frm.elements.length;i++) {
		var e = frm.elements[i];
		if (e.name == checkboxId ) {
			e.checked = false;
		}
	}
}

function disableRadiobutton(radiobutton) 
{  
	for (i=0; i < radiobutton.length; i++)
	{
		if (!radiobutton[i].disabled)
		{
			radiobutton[i].disabled = true;
			if (!document.all && !document.getElementById) 
			{
				radiobutton[i].oldOnFocus = radiobutton[i].onfocus ? radiobutton[i].onfocus : null;
				radiobutton[i].onfocus = skip;
			}    
		}
	}
}

function _cancel()
{
	window.close();	
}

function SetAnonymous(form, username)
{
	var logined = form.logined.value;
	
	form.isanonymous.value = "N";
	
	if (form.anonymous.checked)    {		//set anonymous
		form.guestname.value = "´Ò´Ò¹ý¿Í";
		form.guestname.disabled = true;
		form.isanonymous.value = "Y";
		/*
		form.nickname.value = "´Ò´Ò¹ý¿Í";
		form.nickname.disabled = true;
		*/
		
		form.password.style.backgroundColor="#cccccc";
		form.password.disabled = true;
				
	}
	else if ( logined == "1" )    {		//already login, show logined name
		form.guestname.value = username;
		form.guestname.disabled = true;

		/*
		form.nickname.value = username;
		form.nickname.disabled = true;
		*/
		
		form.password.style.backgroundColor="#cccccc";
		form.password.disabled = true;
	}
	else    {    //need to login with password
		form.guestname.value = "";
		form.guestname.disabled = false;
		/*
		form.nickname.disabled = false;
		*/
		form.password.style.backgroundColor="#ffffff";
		form.password.disabled = false;
	}

}


function hov(loc,cls)
{
   if(loc.className)
      loc.className=cls;
}