//
// Author: Y. Zhang
//


function RefreshWin()
{
	history.go(0);
}



function browserInfo()
{
   if (   navigator.platform.indexOf("Win")>=0 
       && navigator.appVersion.indexOf("MSIE")>=0
      ) return "WinIE";


   if (   navigator.platform.indexOf("Mac")>=0 
       && navigator.appVersion.indexOf("MSIE")>=0
      ) return "MacIE";


   return "Other";
}



function openInfoWin_Basic(url,widthSize,heightSize,topPos,leftPos,
							resizableBoolean,menubarBoolean,toolbarBoolean)
{
	attr="width="+widthSize+",height="+heightSize+",";
	attr=attr+"top="+topPos+",left="+leftPos+",";
	tStr="no";
	if (resizableBoolean) tStr="yes";
	attr=attr+"resizable="+tStr+",";
	tStr="no";
	if (menubarBoolean) tStr="yes";
	attr=attr+"menubar="+tStr+",";
	tStr="no";
	if (toolbarBoolean) tStr="yes";
	attr=attr+"toolbar="+tStr+",scrollbars=yes";	
	
	InfoWin=open(url,"InfoWin",attr);
	InfoWin.focus();
    
}


function openInfoWin_FlashBasic(url,widthSize,heightSize,topPos,leftPos,
							resizableBoolean,menubarBoolean,toolbarBoolean)
{
	attr="width="+widthSize+",height="+heightSize+",";
	attr=attr+"top="+topPos+",left="+leftPos+",";
	tStr="no";
	if (resizableBoolean) tStr="yes";
	attr=attr+"resizable="+tStr+",";
	tStr="no";
	if (menubarBoolean) tStr="yes";
	attr=attr+"menubar="+tStr+",";
	tStr="no";
	if (toolbarBoolean) tStr="yes";
	attr=attr+"toolbar="+tStr+",scrollbars=yes";	
	
	FlashInfoWin=open(url,"FlashInfoWin",attr);
	FlashInfoWin.focus();
    
}



function openInfoWin_Basic2(url,widthSize,heightSize,topPos,leftPos,
							resizableBoolean,menubarBoolean,toolbarBoolean)
{
	attr="width="+widthSize+",height="+heightSize+",";
	attr=attr+"top="+topPos+",left="+leftPos+",";
	tStr="no";
	if (resizableBoolean) tStr="yes";
	attr=attr+"resizable="+tStr+",";
	tStr="no";
	if (menubarBoolean) tStr="yes";
	attr=attr+"menubar="+tStr+",";
	tStr="no";
	if (toolbarBoolean) tStr="yes";
	attr=attr+"toolbar="+tStr+",scrollbars=yes";	
	
	InfoWin2=open(url,"InfoWin2",attr);
	InfoWin2.focus();
    
}


function openFlashWin(url)
{
	return openInfoWin_FlashBasic(url,800,550,70,80,true,false,false);
}


function openFlashFullWin(url)
{
	FullInfoWin=open(url,"FullInfoWin","fullscreen=yes, scrollbars=no");
	FullInfoWin.focus();
}

function openScrollFullWin(url)
{
	FullInfoWin=open(url,"FullInfoWin","fullscreen=yes, scrollbars=yes");
	FullInfoWin.focus();
}

function openInfoWinWide(url)
{
	return openInfoWin_Basic(url,770,550,20,74,true,false,false);
}

function openInfoWinWideMenu(url)
{
	return openInfoWin_Basic(url,770,550,30,76,true,true,false);
}

function openInfoWinWide2(url)
{
	return openInfoWin_Basic2(url,770,550,25,50,true,false,false);
}


function openInfoWinBig(url)
{
	return openInfoWin_Basic(url,500,500,17,61,true,false,false);
}

function openInfoWinMiddle(url)
{
	return openInfoWin_Basic(url,650,450,33,63,true,false,false);
}

function openInfoWinMiddleMenu(url)
{
	return openInfoWin_Basic(url,650,450,45,65,true,true,false);
}

function openInfoWinMiddleMenu2(url)
{
	return openInfoWin_Basic2(url,650,450,31,82,true,true,false);
}

function openInfoWinMiddle2(url)
{
	return openInfoWin_Basic2(url,650,450,24,50,true,false,false);
}


function openInfoWinSmall(url)
{
	return openInfoWin_Basic(url,450,350,10,56,true,false,false);
}

function openInfoWinSmall2(url)
{
	return openInfoWin_Basic2(url,450,350,10,78,true,false,false);
}

function openInfoWinSmallMenu(url)
{
	return openInfoWin_Basic(url,350,350,10,98,true,true,false);
}


function openLanguageWin(url)
{
	return openInfoWin_Basic(url,690,520,10,72,true,false,false);
}








function setCookie(name,value)
{
  var td = new Date();
  var d = new Date();
  d.setTime(td.getTime()+1000*60*60*24*30); //One month
  document.cookie = name + "=" + escape(value) + "; expires=" + d.toGMTString();
}


function getCookie(name)
{
  search = name+"=";
  if (document.cookie.length>0)
  {
    offset = document.cookie.indexOf(search);
    if (offset == -1) return "";
    offset += search.length;
    end = document.cookie.indexOf(";",offset);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(offset,end));
  }
  return "";
}




function containDoubleQuote(str)
{
 if (str==null) return false;
 var n = str.length;
 for (i=0;i<n;i++)
 {
    if (str.charAt(i)=='"') return true;
 }
 return false;
}



function isAlphNum(str)
{
 n = str.length;
 for (i=0;i<n;i++)
 {
 	if (   (str.charAt(i)<='z' && str.charAt(i)>='a')
		|| (str.charAt(i)<='Z' && str.charAt(i)>='A')
		|| (str.charAt(i)<='9' && str.charAt(i)>='0') )  continue;
	else return false;
 }
 return true;
}



function isBlank(str)
{
 n = str.length;
 for (i=0;i<n;i++) if (str.charAt(i)!=' ') return false;
 return true;
}


function trimString(str)
{
   var n = str.length;
   if (n == 0) return "";
   
   var startIdx = -1;
   var lastIdx = n;
   
   for (i=0;i<n;i++)
   {
       if (str.charAt(i)!=' ')
	   {
	      startIdx = i;
		  break;
	   }
   }
   
   if (startIdx < 0) return "";
   
   for (i=n-1;i>=0;i--)
   {
       if (str.charAt(i)!=' ')
	   {
	      lastIdx = i + 1;
		  break;
	   }
   }  
   
   return str.substring(startIdx,lastIdx);
}



function leftTrimStr(str1)
{
	str=str1;
	if (str==null) return "";
	if (isBlank(str)) return "";
	while (true)
	{
		if (str.length==0) break;
		if (str.indexOf(" ")==-1) return str;
		str=str.substring(1,str.length-1);
	}
	return str;
}

function rightTrimStr(str1)
{
	str=str1;
	if (str==null) return "";
	if (isBlank(str)) return "";
	while (true)
	{
		if (str.length==0) break;
		if (str.lastIndexOf(" ")!=(str.length-1)) return str;
		str=str.substring(0,str.length-1);
	}
	return str;
}

function trimStr(str1)
{
	str=leftTrimStr(str1);
	str=rightTrimStr(str);
	return str;
}

function isEmail(str)
{
	if (isBlank(str)) return false;
	n = str.indexOf('@');
	if (n<1 || n==(str.length-1)) return false;
	np = str.lastIndexOf('.');
	if (np<(n+2) || np==(str.length-1)) return false;
	return true;
}

function isNumber(str)
{
	if (isBlank(str)) return false;
	if (isNaN(str)) return false;
	return true;
}

function isInt(str)
{
	if (!isNumber(str)) return false;
	n = str.indexOf('.');
	if (n>=0) return false;
	return true;
}



function MM_findObj(n, d) { //v4.0 getnerated by dreamweaver
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
