function G_OpenNewWindow( url , name , xs, ys , scr )
{
    var ff = 'location=no,left=0,top=0, directories=no,resizable=no, status=no, toolbar=no, menubar=no, width='+xs+' , height='+ys+', scrollbars=' +scr ;
    var ax = window.open(url ,name,ff);
    
    if(ax != null ) {  
    
		if (document.layers) {
		   var sinist = screen.width / 2 - outerWidth / 2;
		   var toppo = screen.height / 2 - outerHeight / 2;
		} else {
		   var sinist = screen.width / 2 - xs / 2;
		   var toppo = -75 + screen.height / 2 - ys / 2;
		}

		try{  ax.moveTo(sinist, toppo); } catch(err){}
		try{  ax.focus(); } catch(err){}
	}
}

function G_FlashMovieOpen ( playerAddr, state , selectedCode )
{
	if ( selectedCode != '' ) {
		
		url = "http://" + playerAddr + '/player/flashplayer.html?mCode='+selectedCode+'&state='+state;
		bfree = 0;
		fullwhereurl = window.location.href;
		ifreePage = fullwhereurl.indexOf("free_list.html");
		if(ifreePage >= 0)
		{
			bfree = 1;
		}
		url = url + "&bfree=" + bfree;
		G_OpenNewWindow(url, 'mplayer', '900', '615' , 'no');
	}
	else { alert("Select Flash Movie"); }
}

function G_MovieOpen ( playerAddr, state , selectedCode )
{	
	if ( selectedCode != '' ) {
		
		url = "http://" + playerAddr + '/player/movieplayer.html?mCode='+selectedCode+'&state='+state;
		bfree = 0;
		fullwhereurl = window.location.href;
		ifreePage = fullwhereurl.indexOf("free_list.html");
		if(ifreePage >= 0)
		{
			bfree = 1;
		}
		url = url + "&bfree=" + bfree;
		G_OpenNewWindow(url, 'mplayer', '900', '615' , 'no');
	}
	else { alert("Select Movie"); }
}

function G_StudyOpen ( playerAddr, lstate, selectedCode , cCode , sCode ,scene, csIdx )
{
	myWinVersion = window.navigator.userAgent + ' ' + window.navigator.appMinorVersion ; 
	
	screen_width = 1024 - 10;
	screen_height = 768 - 30;
	
   features = "toolbar=0,width="+screen_width+",height="+screen_height+",location=0,directories=no,status=0,menubar=0,scrollbars=no,resizable=0,fullscreen=1,center:1,help:0";
	
	if ( selectedCode != '' ) {
		url = "http://" + playerAddr + "/player/study.html?mCode="+selectedCode+"&cCode="+cCode+"&sCode="+sCode+"&state="+lstate+"&scene="+scene+"&csIdx="+csIdx ;
		
		bfree = 0;
		fullwhereurl = window.location.href;
		ifreePage = fullwhereurl.indexOf("free_list.html");
		if(ifreePage >= 0)
		{
			bfree = 1;
		}
		url = url + "&bfree=" + bfree;
		windowname=window.open( url ,"windowname",features);
		if(windowname != null ) { 
			windowname.focus();
		}
	}
	else { alert("Choice Study Item"); }
}

function G_GetCookie( name ) 
{ 
	var nameOfCookie = name + "="; 
	var x = 0; 
	while ( x <= document.cookie.length ) 
	{ 
			var y = (x+nameOfCookie.length); 
			if ( document.cookie.substring( x, y ) == nameOfCookie ) { 
					if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 ) 
							endOfCookie = document.cookie.length; 
					return unescape( document.cookie.substring( y, endOfCookie ) ); 
			} 
			x = document.cookie.indexOf( " ", x ) + 1; 
			if ( x == 0 ) 
					break; 
	} 
	return ""; 
} 
function G_FullScreen()
{
	var hdiff;
	window.moveTo(-4,-4);
	window.resizeTo(screen.width,screen.height);
	hdiff=window.screenTop;
	window.moveTo(-6,-hdiff-7);
	window.resizeTo(screen.width+13,screen.height+hdiff+35);
}

function G_URLEncode(plaintext)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
};
function G_URLDecode(encoded)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
	
   return plaintext;
};


function G_DoBlink() {
	var blink = document.all.tags("BLINK")
	for (var i=0; i<blink.length; i++)
		blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : "" 
}
function G_StartBlink(TimeSpan) {
	if (document.all)
		setInterval("G_DoBlink()",TimeSpan)
}
// old script -----------------------------------------------------
function openAny( url , name , xs, ys , scr)
{
	if(name == "mbox") {
		name = "iistudymybox";
	}
    G_OpenNewWindow( url , name , xs, ys , scr); 
}
function payOpen( url ) {
   
   window.location.replace('/payment/pay.html');
}