// Non-general funtion section
var intLastRandom = 0;
var HeadTitle = false;
var HeadTitle1 = false;
var HeadTitle2 = false;
var intTotalImgNum = 0;
/*
	use filename to determine the image number e.g. pic_the_company.gif

*/
function HKMC_MS_Switch(objDiv,cmd){
	switch(cmd){
		case 0:
			if (!objDiv || !objDiv.style) return;
			//objDiv = MM_findObj('par1');
			objDiv.style.position = "absolute";
			objDiv.style.visibility = "hidden";
			break;
		case 1:
			if (!objDiv || !objDiv.style) return;
			//objDiv = MM_findObj('par1');
			objDiv.style.position = "relative";
			objDiv.style.visibility = "visible";
			break;
		case 2:
			for (i = 1 ; i < 20 ; i++){
				objDiv = MM_findObj('par'+i);
				if(objDiv == null)continue;
				objDiv.style.position = "absolute";
				objDiv.style.visibility = "hidden";
			}
			break;
	}
}
function HKMC_MS_DIVSwitch(DivName){
	alert('s');
	objDiv = MM_findObj(DivName);
	alert(objDiv.style.visibility.value);
	//if(objDiv.style.visibility == "hidden"){}
}

function HKMC_RndImage(objImg,strImgFile){

	intTotalImgNum = 3;
	FirstPath = objImg.src.substring(0,objImg.src.lastIndexOf('/'))+'/';
	strImgFile = objImg.src.substring(objImg.src.lastIndexOf('/')+1,objImg.src.length);

	if('HeadTitle' == objImg.name && HeadTitle == true){
		return;
	}
	if('HeadTitle1' == objImg.name && HeadTitle1 == true){
		return;
	}
	if('HeadTitle2' == objImg.name && HeadTitle2 == true){
		alert('sad');
		return;
	}
	//
	if(strImgFile == 'pic_the_company.gif'){
		intTotalImgNum = 7;
	}

	if(strImgFile == 'pic_our_buz.gif'){
		intTotalImgNum = 9;
	}
	if(strImgFile == 'pic_mortgage_calc.gif'){
		intTotalImgNum = 9;
	}
	if(strImgFile == 'pic_guide_refer.gif'){
		intTotalImgNum = 9;
	}
	if(strImgFile == 'pic_preliminary.gif'){
		intTotalImgNum = 9;
	}

	if(strImgFile == 'pic_contact_us.gif'){
		intTotalImgNum = 3;
	}
	if(strImgFile == 'pic_legal.gif'){
		intTotalImgNum = 3;
	}
	if(strImgFile == 'pic_privacy.gif'){
		intTotalImgNum = 3;
	}

	if(strImgFile == 'pic_buz_partner.gif'){
		intTotalImgNum = 6;
	}

	if(strImgFile == 'pic_press.gif'){
		intTotalImgNum = 7;
	}
	if(strImgFile == 'pic_publication.gif'){
		intTotalImgNum = 7;
	}
	if(strImgFile == 'mission.gif'){
		intTotalImgNum = 7;
	}

	var strArImgFile = new Array(9);
	for(var i = 1 ; i <= 9 ; i++){
		strArImgFile[i] = strImgFile.substring(FirstPath,strImgFile.lastIndexOf('.')) + '_'+ i + strImgFile.substring(strImgFile.lastIndexOf('.'),strImgFile.length);
	}
		strArImgFile[0] = strImgFile.substring(FirstPath,strImgFile.lastIndexOf('.')) + strImgFile.substring(strImgFile.lastIndexOf('.'),strImgFile.length);
	strPath = objImg.src.substring(0,objImg.src.lastIndexOf('/'))+'/';

	if(objImg.name == 'HeadTitle2'){
		var ret = new Image();
		ret.src = strPath + strArImgFile[intLastRandom];
		if (ret.width > 0 && ret.height > 0)
			objImg.src = strPath + strArImgFile[intLastRandom];
		// alert(objImg.src);
		return;
	}

	intRandom = Math.round((Math.random()*10))%intTotalImgNum;
	var ret = new Image();
	ret.src = strPath + strArImgFile[intRandom];
	if (ret.width > 0 && ret.height > 0)
		objImg.src = strPath + strArImgFile[intRandom];

	if('HeadTitle2' == objImg.name){
		HeadTitle2 = true;
	}
	if('HeadTitle1' == objImg.name){
		HeadTitle1 = true;
	}
	if('HeadTitle' == objImg.name){
		HeadTitle = true;
	}
		intLastRandom = intRandom;

};

// General funtion section

/* ## function RndImage(objImg,strPath,strImgFile
Desc: Random image
Par :
	1.String-Image Object,

	2.String-General path
	   *if null, get the ImageObject path automatically.

	3.String Array- file name

   Example()
*/

/*
PULL_DOWN_MENU.prototype.HKMC_AddSubTitleDesc = function(strItem){
	if(this.Started==true){
		this.displayTable();
	}else{
		this.Started=true;
	}

	this.strItem= '';
	this.strItemArr = '';
	this.strItemTextStyle = '';
	this.strItem2= '';
	this.strSubItem= '';
	this.counter++;


	this.addItem(strItem);
	this.addItemAtt('style="background-color:white; background-image:url(../../../image/common/dots-full.gif)"');
	this.addItemTextStyle('style="background-color:white"');
	this.addItem2('<img onclick=\'javascript:HKMC_MS_Switch(document.all.par'+this.counter+',1);\' border="0" src="../../../image/common/i_view.gif" />');
}

PULL_DOWN_MENU.prototype.TableEnd = function(){
	this.displayTable();
	this.strSubItem = '';
	this.End = false;
}

PULL_DOWN_MENU.prototype.AddSubtitle = function(strSubItem){
	//this.strSubItem += "<br><span style='color:white'>__</span>" + strSubItem+"<br>";
	this.addSubItem(this.strSubItem);
}

PULL_DOWN_MENU.prototype.HKMC_AddSubTitleDesc = function(strSubItem){
	this.strSubItem += "<br><span style='color:white'>__</span>" + strSubItem+"<br>";
	this.addSubItem(this.strSubItem);
}

PULL_DOWN_MENU.prototype.HKMC_HKMC_AddContent = function(strSubItem){
	this.strSubItem += "<br><span style='color:white'>__</span>" + strSubItem+"<br>";
	this.addSubItem(this.strSubItem);
}

PULL_DOWN_MENU.prototype.addItemAtt = function(strItemArr){
	this.strItemArr = strItemArr;
}

PULL_DOWN_MENU.prototype.addItemTextStyle = function(strItemTextStyle){
	this.strItemTextStyle = strItemTextStyle;
}

PULL_DOWN_MENU.prototype.addItem = function(strItem){
	this.strItem = strItem;
}

PULL_DOWN_MENU.prototype.addItem2 = function(strItem){
	this.strItem2 = strItem;
}


PULL_DOWN_MENU.prototype.addSubItem = function(strSubItem){
	this.strSubItem = strSubItem;
}

PULL_DOWN_MENU.prototype.HKMC_AddTitle = function(Title){
	this.Title += '<tr><td>'+Title+'</td><td></td><td></td></tr>';
}

PULL_DOWN_MENU.prototype.HKMC_AddSubTitle = function(SubTitle){
	this.SubTitle = SubTitle;
}

PULL_DOWN_MENU.prototype.displayTable = function(){
	document.writeln('<table width="480" border="0" cellspacing="10" cellpadding="0" height="0">');
	document.writeln(this.Title);
	document.writeln('<tr><td valign="top">'+this.SubTitle+'.&nbsp;</td>');
	document.writeln('<td width="96%" valign="top" '+this.strItemArr+' ><span '+this.strItemTextStyle+' >'+this.strItem+'</span></td>');
	document.writeln('<td width="4%" valign="top">'+this.strItem2+'</td>');
	document.writeln('</tr>');
	document.writeln('<tr width="10" valign="top"><td></td>');
	this.strSubItem += '<br><div align=\"right\" onClick=\'javascript:HKMC_MS_Switch(document.all.par'+this.counter+',0)\'><font color=\"#C0C0C0\"><b>close</b></font></div><p>&nbsp;</p>';
	document.writeln('<td valign="top"><div id="par'+this.counter+'">'+this.strSubItem+'</div></td>');
	document.writeln('</tr>');
	document.writeln('</table>');
}
*/



function NumRoundUp(intNum,intPlace){
	intNum = intNum * Math.pow(10, intPlace);
	intNum = Math.ceil(intNum);
	intNum = intNum / Math.pow(10, intPlace);
	return intNum;
}

function NumObjRoundUp(ObjNum,intPlace){
	var intNum = ObjNum.value;
	if (intNum == 0 )return;
	if( getNumeric(ObjNum.value) > 0){
		intNum = getNumeric(ObjNum.value);
	}
	intNum = intNum * Math.pow(10, intPlace);
	intNum = Math.ceil(intNum);
	intNum = intNum / Math.pow(10, intPlace);
	if (isNaN(intNum)){
		//alert('Only accept number.');
		ObjNum.value = ''
		return false;
	}
	ObjNum.value = intNum;
}

function getNumeric(aval) {
	return str_replace(',', '', aval);
}

function NumRangeCheck(objNum,intMin,intMax,strMsg){
	if	(intMax == 0){
		if	(objNum.value <= 0){
			alert(strMsg);
			objNum.value ='';
			return false;
		}
	}

	if	(intMax == 0){return false;}

	if	(objNum.value <= intMin || objNum.value > intMax){
		alert(strMsg);
		objNum.value ='';
		return false;
	}
	return true;
}

function EqlNumRangeCheck(objNum,intMin,intMax,strMsg){
	if	(intMax == 0){
		if	(objNum.value <= 0){
			alert(strMsg);
			objNum.value ='';
			return false;
		}
	}

	if	(intMax == 0){return false;}

	if	(objNum.value < intMin || objNum.value > intMax){
		alert(strMsg);
		objNum.value ='';
		return false;
	}
	return true;
}

function RndImage(objImg,strPath,strImgFile){
	if(strPath=='')
		strPath = objImg.src.substring(0,objImg.src.lastIndexOf('/'))+'/';
	objImg.src = strPath + strImgFile[Math.round((Math.random()*10))%strImgFile.length];
};

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
