/* -----------------------------------------------------------------------------
** Filename: utils.js
** Description:
** Javascript utility functions.
**
** Author: J.J.Gallagher
** Creation date: 17 Nov 2004   
** Version: 2.0   
** SpringOrchard Technology Ltd. Tel. +44(0)1628-631-054  
**
** History:
** 17.11.2004 Created  
** 17.06.2005 Renamed functions with 'UTIL_' prefix. Major version bumped up.
** -------------------------------------------------------------------------- */

/* -----------------------------------------------------------------------------
** Description:
** Commonly used object manipulation functions.
** History:
** -------------------------------------------------------------------------- */
function UTIL_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function UTIL_swapImgRestore() { //v3.0
  var i,x,a=document.UTIL_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function UTIL_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.UTIL_p) d.UTIL_p=new Array();
    var i,j=d.UTIL_p.length,a=UTIL_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.UTIL_p[j]=new Image; d.UTIL_p[j++].src=a[i];}}
}

function UTIL_findObj(n, d) { //v4.0
  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=UTIL_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function UTIL_swapImage() { //v3.0
  var i,j=0,x,a=UTIL_swapImage.arguments; document.UTIL_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=UTIL_findObj(a[i]))!=null){document.UTIL_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


/* -----------------------------------------------------------------------------
** Description:
** Get user's preferred language
** History:
** Browser Language Redirect script- By JavaScript Kit
** For this and over 400+ free scripts, visit http://www.javascriptkit.com
** This notice must stay intact.
** -------------------------------------------------------------------------- */

//Enter ISO 639-2 letter Language codes to detect (see: http://www.w3.org/WAI/ER/IG/ert/iso639.htm):
var langcodes=new Array("en", "en-gb","en-uk", "en-us", "zh", "zh-cn","zh-sg","zh-hans", "default") 

//Enter corresponding redirect URLs (last one is for default URL):
var langredirects=new Array("indexEn.html", "indexEn.html", "indexEn.html", "indexEn.html", "index.html","index.html", "index.html", "index.html", "indexEn.html")

var languageinfo=navigator.language? navigator.language : navigator.userLanguage
var gotodefault=1

function UTIL_redirectpage(dest)
{
	if (window.location.replace)
		window.location.replace(dest)
	else
		window.location=dest
} // UTIL_redirectpage()

function UTIL_setLanguage()
{
	for (i=0;i<langcodes.length-1;i++)
	{
		if (languageinfo.substr(0,2)==langcodes[i])
		{
// TEMP DISABLED JJG 19.10.04 UTIL_redirectpage(langredirects[i])
			gotodefault=0
			break
		}
	}
} // UTIL_setLanguage()

function UTIL_checkDefault()
{
	if (gotodefault)
	{
		UTIL_redirectpage(langredirects[langcodes.length-1])
	}
} // UTIL_checkDefault

// End browser language re-direct 


/* -----------------------------------------------------------------------------
** Description:
** Get current date as yyyy,mm,dd.
** History:
** -------------------------------------------------------------------------- */
//var months=new Array(13);
//months[1]="January";
//months[2]="February";
//months[3]="March";
//months[4]="April";
//months[5]="May";
//months[6]="June";
//months[7]="July";
//months[8]="August";
//months[9]="September";
//months[10]="October";
//months[11]="November";
//months[12]="December";

//var months=new Array(13);
//months[1]="1月";
//months[2]="2月";
//months[3]="3月";
//months[4]="4月";
//months[5]="5月";
//months[6]="6月";
//months[7]="7月";
//months[8]="8月";
//months[9]="9月";
//months[10]="10月";
//months[11]="11月";
//months[12]="12月";

//var time=new Date();
//var lmonth=months[time.getMonth() + 1];
//var date=time.getDate();
//var year=time.getYear();
//if (year < 2000)    
//	year = year + 1900;


/* -----------------------------------------------------------------------------
** Description:
** Friend mailer.
** History:
** Script by Trånn: http://come.to/tronds
** Submitted to JavaScript Kit (http://javascriptkit.com)
** Visit http://javascriptkit.com for this script
** -------------------------------------------------------------------------- */
var initialsubj="Have a look at this website"
var initialmsg="Hello:\n you may find this website interesting: "+window.location

//var initialsubj="请浏览这个网站"
//var initialmsg="你好:\n 你会认为这个网站不错: "+window.location
var good;

function UTIL_checkEmailAddress(field) 
{
	var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.info)|(\.biz)|(\.aero)|(\.coop)|(\.museum)|(\.name)|(\.pro)|(\..{2,2}))$)\b/gi);
	if (goodEmail) 
	{
		good = true;
	}
	else 
	{
		alert('Please enter a valid address.');

		//alert('朋友的电邮地址');
		field.focus();
		field.select();
		good = false;
   	}
} // UTIL_checkEmailAddress

u = window.location;
function UTIL_mailThisUrl() 
{
	good = false
	UTIL_checkEmailAddress(document.eMailer.email);
	if (good) 
	{
		//window.location = "mailto:"+document.eMailer.email.value+"?subject="+initialsubj+"&body="+document.title+" "+u;
		window.location = "mailto:"+document.eMailer.email.value+"?subject="+initialsubj+"&body="+initialmsg
   	}
} // UTIL_mailThisUrl()

//  End of friend mailer
		

