function getCSSURL(EcomURL) {
	var EcomList = new Array();
	var CSSList = new Array();
	var i;

	EcomList[0] = "en/index.asp";
	CSSList[0] = "en/home.do";
	EcomList[1] = "tc/index.asp";
	CSSList[1] = "tc/home.do";
	EcomList[2] = "en/d_b04g1c_ebill.asp";
	EcomList[3] = "tc/d_b04g1c_ebill.asp";
	CSSList[2] = "en/viewBill/summary/entry.do";
	CSSList[3] = "tc/viewBill/summary/entry.do";
	EcomList[4] = "en/acctinfo.asp";
	EcomList[5] = "tc/acctinfo.asp";
	CSSList[4] = "en/accountInfo/entry.do";
	CSSList[5] = "tc/accountInfo/entry.do";
	EcomList[6] = "en/RegWS.asp"
	EcomList[7] = "tc/RegWS.asp"
	CSSList[6] = "en/wsRegister/entry.do";
	CSSList[7] = "tc/wsRegister/entry.do";
	EcomList[8] = "en/RegEBC2.asp";
	EcomList[9] = "tc/RegEBC2.asp";
	CSSList[8] = "en/wsRegister/entry.do";
	CSSList[9] = "tc/wsRegister/entry.do";
	EcomList[10] = "en/ApplyDTAcctForm.asp";
	EcomList[11] = "tc/ApplyDTAcctForm.asp";
	CSSList[10] = "en/supplyApplication/DT/entry.do";
	CSSList[11] = "tc/supplyApplication/DT/entry.do";
	EcomList[12] = "en/ApplyGSAcctForm.asp";
	EcomList[13] = "tc/ApplyGSAcctForm.asp";
	CSSList[12] = "en/supplyApplication/GST/entry.do";
	CSSList[13] = "tc/supplyApplication/GST/entry.do";
	EcomList[14] = "en/GrpBillApplyForm.asp";
	EcomList[15] = "tc/GrpBillApplyForm.asp";
	CSSList[14] = "en/groupBill/application/entry.do";
	CSSList[15] = "tc/groupBill/application/entry.do";
	EcomList[16] = "en/ChgEMail.asp";
	EcomList[17] = "tc/ChgEMail.asp";
	CSSList[16] = "en/changeEbillEmail/entry.do";
	CSSList[17] = "tc/changeEbillEmail/entry.do";
	EcomList[18] = "en/ChgCeil.asp";
	EcomList[19] = "tc/ChgCeil.asp";
	CSSList[18] = "en/autopayCeiling/entry.do";
	CSSList[19] = "tc/autopayCeiling/entry.do";
	EcomList[20] = "en/ChgLoadForm.asp";
	EcomList[21] = "tc/ChgLoadForm.asp";
	CSSList[20] = "en/changeLoad/entry.do";
	CSSList[21] = "tc/changeLoad/entry.do";
	EcomList[22] = "en/ChgNameForm.asp";
	EcomList[23] = "tc/ChgNameForm.asp";
	CSSList[22] = "en/changeName/entry.do";
	CSSList[23] = "tc/changeName/entry.do";
	EcomList[24] = "en/ChgPostAddr.asp";
	EcomList[25] = "tc/ChgPostAddr.asp";
	CSSList[24] = "en/changePostalAddress/entry.do";
	CSSList[25] = "tc/changePostalAddress/entry.do";
	EcomList[26] = "en/ChgPwd.asp";
	EcomList[27] = "tc/ChgPwd.asp";
	CSSList[26] = "en/changePwd/entry.do";
	CSSList[27] = "tc/changePwd/entry.do";
	EcomList[28] = "en/Consum.asp";
	EcomList[29] = "tc/Consum.asp";
	CSSList[28] = "en/consumption/entry.do";
	CSSList[29] = "tc/consumption/entry.do";
	EcomList[30] = "en/FeedBackForm.asp";
	EcomList[31] = "tc/FeedBackForm.asp";
	CSSList[30] = "en/feedback/entry.do";
	CSSList[31] = "tc/feedback/entry.do";
	EcomList[32] = "en/ForgotPwdForm.asp";
	EcomList[33] = "tc/ForgotPwdForm.asp";
	CSSList[32] = "en/forgotPassword/entry.do";
	CSSList[33] = "tc/forgotPassword/entry.do";
	EcomList[34] = "en/GrpBillAddForm.asp";
	EcomList[35] = "tc/GrpBillAddForm.asp";
	CSSList[34] = "en/groupBill/addAccount/entry.do";
	CSSList[35] = "tc/groupBill/addAccount/entry.do";
	EcomList[36] = "en/GrpBillDelForm.asp";
	EcomList[37] = "tc/GrpBillDelForm.asp";
	CSSList[36] = "en/groupBill/removeAccount/entry.do";
	CSSList[37] = "tc/groupBill/removeAccount/entry.do";
	EcomList[38] = "en/GBFile.asp";
	EcomList[39] = "tc/GBFile.asp";
	CSSList[38] = "en/groupBill/fileDownload/entry.do";
	CSSList[39] = "tc/groupBill/fileDownload/entry.do";
	EcomList[40] = "en/SubAcctList.asp";
	EcomList[41] = "tc/SubAcctList.asp";
	CSSList[40] = "en/subAccounts/entry.do";
	CSSList[41] = "tc/subAccounts/entry.do";			
	EcomList[42] = "en/AppInspForm.asp";
	EcomList[43] = "tc/AppInspForm.asp";
	CSSList[42] = "en/installationInspection/entry.do";
	CSSList[43] = "tc/installationInspection/entry.do";
	EcomList[44] = "en/OtherReqForm.asp";
	EcomList[45] = "tc/OtherReqForm.asp";
	CSSList[44] = "en/otherSvcReq/entry.do";
	CSSList[45] = "tc/otherSvcReq/entry.do";			
	EcomList[46] = "en/RptMeter.asp";
	EcomList[47] = "tc/RptMeter.asp";
	CSSList[46] = "en/mtrRead/entry.do";
	CSSList[47] = "tc/mtrRead/entry.do";			
	EcomList[48] = "en/login.asp";
	EcomList[49] = "tc/login.asp";
	CSSList[48] = "en/loginpage.do";
	CSSList[49] = "tc/loginpage.do";			
	EcomList[50] = "en/logout.asp";
	EcomList[51] = "tc/logout.asp";
	CSSList[50] = "en/logout.do";
	CSSList[51] = "tc/logout.do";			
	EcomList[52] = "en/TariffCalcBT.asp";
	EcomList[53] = "tc/TariffCalcBT.asp";
	CSSList[52] = "en/tariffCalculation/BT/entry.do";
	CSSList[53] = "tc/tariffCalculation/BT/entry.do";
	EcomList[54] = "en/TariffCalcDT.asp";
	EcomList[55] = "tc/TariffCalcDT.asp";
	CSSList[54] = "en/tariffCalculation/DT/entry.do";
	CSSList[55] = "tc/tariffCalculation/DT/entry.do";
	EcomList[56] = "en/TariffCalcGST.asp";
	EcomList[57] = "tc/TariffCalcGST.asp";
	CSSList[56] = "en/tariffCalculation/GST/entry.do";
	CSSList[57] = "tc/tariffCalculation/GST/entry.do";
	EcomList[58] = "en/TariffCalcLPT.asp";
	EcomList[59] = "tc/TariffCalcLPT.asp";
	CSSList[58] = "en/tariffCalculation/LPT/entry.do";
	CSSList[59] = "tc/tariffCalculation/LPT/entry.do";
	EcomList[60] = "en/TermAcctForm.asp";
	EcomList[61] = "tc/TermAcctForm.asp";
	CSSList[60] = "en/supplyTermination/entry.do";
	CSSList[61] = "tc/supplyTermination/entry.do";
	EcomList[62] = "en/GrpBillTermForm.asp";
	EcomList[63] = "tc/GrpBillTermForm.asp";
	CSSList[62] = "en/groupBill/termination/entry.do";
	CSSList[63] = "tc/groupBill/termination/entry.do";
	EcomList[64] = "en/SRIndex.asp";
	EcomList[65] = "tc/SRIndex.asp";
	CSSList[64] = "en/svcReqMenu.do";
	CSSList[65] = "tc/svcReqMenu.do";

	for (i=0; i < EcomList.length; i++) {
		if (EcomURL.toLowerCase() == EcomList[i].toLowerCase()) {
			return CSSList[i];
		}
	}	
	return "";
}

function showEcom( theURL ) 
{
	var newpath;
	var newwindow;
	var newURL;
	//var context = "ec/";
	var context = "clponline/";

	//newURL = getCSSURL(theURL);
	newURL = theURL;
	newpath = 'https://www1.clpgroup.com/' + context + newURL;
	newwindow = window.open( newpath, 'CLPWS' , 'scrollbars=yes,resizable=yes,toolbar=no,titlebar=no,location=no,menubar=yes,width=800,height=560,top=0,left=0');
	if (newwindow != null) {
		newwindow.focus();
	}
}

function CMSNewWindow(mypage,myname)
{
	settings='scrollbars=yes,location=no,directories=no,status=yes,menubar=no,toolbar=no,resizable=yes';
	var win=window.open(mypage,myname,settings);
}

function popMenuWindow(mypage,myname,mywidth,myheight)
{
	var settings='scrollbars=yes,location=yes,directories=no,status=yes,menubar=yes,toolbar=yes,resizable=yes' + ',width=' + mywidth + ',height=' + myheight + ',top=50,left=10';

	var win=window.open(mypage,myname,settings);
}

function redirect(item) {
	var sUrl = new String(item.options[item.selectedIndex].value);
	
	if (sUrl.indexOf("hknuclear") > 0) {
		popWindow(sUrl, "popup", "800", "600");
	} else{
		window.location.href = item.options[item.selectedIndex].value;
	};
}

function searchSite(){
	document.frmSearch.submit();
}

function searchMedia(){
	document.frmMediaSearch.submit();
}

function searchAdv(){
	document.frmAdvSearch.submit();
}

// the following part are used by the stock price
/* ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
 * Validates integer strings.
 *
 * Parameter: sInteger - a string to validate as an integer
 * Returns:   true (is integer) or false (is not) boolean
 ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-*/
function isInteger(sInteger) {

    var isInt = true;
    inputStr = sInteger.toString(); // in case not a string already
    for (var i = 0; i < inputStr.length; i++) {
        var oneChar = inputStr.charAt(i);
        if (oneChar < "0" || oneChar > "9") {
            isInt = false;
            break; // break out of loop when bad char found
        }
    }
    return isInt;
}


function isDate(str) {

    var valid = true;
    var sDate = str;

    var yyyy = sDate.substring( 0, 4 );
    var mm = sDate.substring( 4, 6 );
    var dd = sDate.substring( 6, 8 );

    // Validate date
    if (sDate.length != 8)
        valid = false;

    if (isInteger(mm) == false || isInteger(dd) == false || isInteger(yyyy) == false)
        valid = false;

    if (yyyy.length != 4)
        valid = false;
    else if (mm < 1 || mm > 12)
        valid = false;
    else if (dd < 1 || dd > 31)
        valid = false;
    else if (mm == 2) {
        if (dd > 29)
            valid = false ;
        else if (dd == 29) {
            if (yyyy % 100 == 0 && yyyy % 400 != 0)
                valid = false;
            else if (yyyy % 4 != 0)
                valid = false;
        }
    } else if (mm == 4 || mm == 6 || mm == 9 || mm == 11) {
        if (dd > 30)
            valid = false;
    }
	
    return valid;
}


function ValidateDate(from, to)
{

	if ((from != "") || (from != null))
		{
		if (!isDate(from)) {
			alert("Invalid From Date!");
			return false;
			}
		}
	if ((to != "") || (to != null))
		{
		if (!isDate(to)) {
			alert("Invalid To Date!");
			return false;
			}
		}
	
	if ((to - from) < 0)
		{
		alert("From Date is greater than To Date!");
		return false;
		}
	
	return true;
}

function submitForm(form)
{
	var sFrom;
	var sTo;
	var urlStr;

	sFrom = form.fromYYYY.value + form.fromMM.value + form.fromDD.value;
	sTo = form.toYYYY.value + form.toMM.value + form.toDD.value;

    if (ValidateDate(sFrom, sTo))
    {
    urlStr = "http://www.chinalightandpower.com.hk/NR/clp/common/asp/Layouts/StockPrice.csv?fromDate=" + form.fromYYYY.value + "-" + form.fromMM.value + "-" + form.fromDD.value + "&toDate="  + form.toYYYY.value + "-" + form.toMM.value + "-" + form.toDD.value + "&lang=" + form.lang.value
	window.open(urlStr,'DnloadPage','menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=0,scrollbars=0,width=300,height=120');
	//window.open(urlStr,'DnloadPage');
	}
	return false;
}
