﻿/*-------------------------------------------------------------------------------
	*	FileName ; $common.js
	* Function : commmon utilies functions
	* CreatedDate : 01/02/2003
	* LastUpdate : 01/03/2003
-------------------------------------------------------------------------------*/
var arrPixFiles = new Array("jpg","jpeg","gif","png","bmp","tif","jpe");
var arrDocFiles = new Array("doc","xls","txt","xls","pdf","ppt","rtf","zip","rar","gz","bz2","tar","psd","fla");
var arrMovieFiles = new Array("div","mov","wmv","wma","avi","mpg","mpeg","qt","mp4","ram");
var arrFlashFiles = new Array("swf");
var _fileName;
var marked_row = new Array;

function stoperror(){ 
return true 
} 
window.onerror=stoperror 

//------------------------------------------------
// Function Name : LTrim 
// Actions : Remove left string.
//------------------------------------------------
function LTrim(Str) {
	return Str.replace(/^\s+/, '');
}

//------------------------------------------------
// Function Name : RTrim 
// Actions : Remove right space.
//------------------------------------------------
function RTrim(Str) {
	return Str.replace(/\s+$/, '');
}

//------------------------------------------------
// Function Name : Trim 
// Actions : Remove left&right space.
//------------------------------------------------
function Trim(Str) {
	return RTrim(LTrim(Str));
}

//------------------------------------------------
// Function Name : RemoveSpace 
// Actions : Remove left, right & all unwanted spaces inside a Str
//------------------------------------------------
function RemoveSpace(Str) {
	var str = Trim(Str).replace(/\s+/g, ' ');
	str = str.replace(/\s+[,]/g, ',');
	str = str.replace(/\s+[;]/g, ' ;');
	str = str.replace(/\s+[:]/g, ' :');
	return str.replace(/\s+[.]/g, '.');
}

//------------------------------------------------
// Function Name : AddSpace 
// Actions : Add some space to correct sentense
//------------------------------------------------
function AddSpace(Str) {
	var str = Str.replace(/\,/g, ', ');
	str = str.replace(/;/g, '; ');
	str = str.replace(/;/g, ' ;');
	str = str.replace(/\./g, '. ');
	str = str.replace(/\:/g, ' :');
	str = str.replace(/\:/g, ': ');
	str = RemoveSpace(str);
	return str;
}

//------------------------------------------------
// Function Name : TypingCheck 
// Actions : Check spell
//------------------------------------------------
function TypingCheck(Str) {
	var arrayStr = new Array();
	Str = AddSpace(Str);
	for (var i = 0; i < Str.length; i++) {
			arrayStr[i] = Str.charAt(i);
	}
	for (var i = 0; i < Str.length; i++) {
		if ( ( (isPeriod = (arrayStr[i] == '.')) || (arrayStr[i] == ',') || (arrayStr[i] == ';') )  && (i != Str.length - 1) ) {
			arrayStr[i+2] = isPeriod ? arrayStr[i+2].toUpperCase() : arrayStr[i+2].toLowerCase();
		}
	}
	arrayStr[0] = arrayStr[0].toUpperCase();
	var str = "";
	for (var i = 0; i < Str.length; i++) {
			str += arrayStr[i];
	}
	return str;
}
function CheckAll_bottom(f)
{
	if(f.allbox_up.checked) {
		for(var i=0;i<f.elements.length;i++)
		{
			var e=f.elements[i];
			if((e.name!='allbox_up')&&(e.type=='checkbox')&&(e.disabled==false)) {
				if(!e.checked) {
					e.click();
				}
			}
		}
	}else {
		for(var i=0;i<f.elements.length;i++)
		{
			var e=f.elements[i];
			if((e.name!='allbox_up')&&(e.type=='checkbox')&&(e.disabled==false)) {
				e.click();
			}
		}
	}
}
function CheckAll_bottom_v2(f)
{
	if(f.allbox_up.checked) {
		for(var i=0;i<f.elements.length;i++)
		{
			var e=f.elements[i];
			if((e.name!='allbox_up')&&(e.type=='checkbox')&&(e.disabled==false)) {
				if(!e.checked) {
					e.click();
				}
			}
		}
	}else {
		for(var i=0;i<f.elements.length;i++)
		{
			var e=f.elements[i];
			if((e.name!='allbox_up')&&(e.type=='checkbox')&&(e.disabled==false)) {
				e.click();
			}
		}
	}
}
 function pasteClass(e,classSelect,classNormal)
    {
	var r = null;
	if (e.parentNode && e.parentNode.parentNode) {
	    r = e.parentNode.parentNode;
	}
	else if (e.parentElement && e.parentElement.parentElement) {
	    r = e.parentElement.parentElement;
	}
	if (r) {
		r.className = e.checked ? classSelect : classNormal;
	}
    }

 function nothing(e,bg,row_number,mark_color)
    {
	var r = null;
	if (e.parentNode && e.parentNode.parentNode) {
	    r = e.parentNode.parentNode;
	}
	else if (e.parentElement && e.parentElement.parentElement) {
	    r = e.parentElement.parentElement;
	}
	if (r) {
		var  theCells = null;
		//r.style.backgroundColor=bg;
		if (typeof(document.getElementsByTagName) != 'undefined') {
			theCells = r.getElementsByTagName('td');
		}
		else if (typeof(r.cells) != 'undefined') {
			theCells = r.cells;
		}
		else {
			return false;
		}
		 var rowCellsCnt  = theCells.length;
         for (var c = 0; c < rowCellsCnt; c++) {
              //theCells[c].style.backgroundColor = bg;
			  theCells[c].setAttribute('bgcolor', bg, 0);
         }
		 if(bg.toLowerCase()==mark_color.toLowerCase()) {
			 marked_row[row_number] = true;
		 }
		 else marked_row[row_number] = false;
	}
    }
	
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
		
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0)
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // Garvin: deactivated onclick marking of the checkbox because it's also executed
            // when an action (like edit/delete) on a single item is performed. Then the checkbox
            // would get deactived, even though we need it activated. Maybe there is a way
            // to detect if the row was clicked, and not an item therein...
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function

function checkSearch(f) {
	var keys;
	var keys_lower;
	var keys_upper;
	f.action = '';
	keys = Trim(f.k.value);
	if (keys!='') {
	 	f.k.value = keys;
		keys_lower = keys.toLowerCase();
		f.l.value = keys_lower;
		keys_upper = keys.toUpperCase();
		f.u.value = keys_upper;
		f.action = '?pgid=search_product';
		f.pgid.value="search_product";
		return true;
	}
	f.action = '';
	return false;
}	
function checkNewsletter(f){
	if(isEmail(f.email.value)){
		window.open('newsletter.php?email='+f.email.value,'PopNewsLetter','width=350,height=60');
	}
	else{
		alert('Email không hợp lệ. Vui lòng kiểm tra lại !');
		f.email.focus();
	}
	return false;
}
function checkMail(f){
	if(isEmail(f.email.value)){
		window.open('mail2friend.php?email='+f.email.value,'PopEmail','width=350,height=60');
	}
	else{
		alert('Email không hợp lệ. Vui lòng kiểm tra lại !');
		f.email.focus();
	}
	return false;
}
	function setCookie(name,value){
		document.cookie = name + '=' + escape(value) +  ';path=/';
		return ;
	}
	function getCookie(name){
		var cname = name + '=';
		var dc = document.cookie;
		if (dc.length > 0) {
			var begin = dc.indexOf(cname);
			if (begin != -1) {
			begin += cname.length;
			var end = dc.indexOf(';', begin);
			if (end == -1) end = dc.length;
				return unescape(dc.substring(begin, end));
			}
		}
		return null;
	}
	
function GetYear() {
	var mydate=new Date()
	var year=mydate.getYear()
	if (year < 1000)
		year+=1900
	document.write (year)
}
function openBox(winWidth, winHeight, scrollbars,toolbar,top,left,fileSrc) {
	var newParameter = "width=" + winWidth + ",height=" + winHeight ;
	newParameter += ",scrollbars="+scrollbars+",toolbar="+toolbar+",top="+top+",left="+left;
    var newWindow = open(fileSrc,"",newParameter);
}
function DateDisplay() {
	var mydate=new Date()
	var year=mydate.getYear()
	if (year < 1000)
		year+=1900
	var day=mydate.getDay()
	var month=mydate.getMonth()
	var daym=mydate.getDate()
	if (daym<10) daym="0"+daym
		var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
		var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
		document.write(dayarray[day]+", "+montharray[month]+" "+daym+", "+year)
}

function writeTime()
{
	var mydate=new Date()
	
	var year = mydate.getYear()
	if (year < 1000)
		year += 1900
	var month = mydate.getMonth() + 1
	if (month < 10)
		month = "0" + month
	var day = mydate.getDate()
	if (day < 10)
		day = "0" + day

	var dayw = mydate.getDay()
	
	var hour = mydate.getHours()
	if (hour < 10)
		hour = "0" + hour
	
	var minute=mydate.getMinutes()
	if (minute < 10)
		minute = "0" + minute
	var dayarray=new Array("Ch&#7911; Nh&#7853;t","Th&#7913; Hai","Th&#7913; Ba","Th&#7913; T&#432;","Th&#7913; N&#259;m","Th&#7913; S&#225;u","Th&#7913; B&#7843;y")
	document.write(dayarray[dayw]+", "+day+"/"+month+"/"+year+",&nbsp;"+hour+":"+minute+" (GMT+7)")
}



	function getCategoryName(id){
		var i;
		for(i=0;i<Tree.length;i++){
			var arrElement = Tree[i].split('|');
			if(arrElement[0]==id){
				return arrElement[2];
			}
		}
		return 'Products';
	}
	function getCategoryName4member(id){
		var i;
		for(i=0;i<Tree4member.length;i++){
			var arrElement = Tree4member[i].split('|');
			if(arrElement[0]==id){
				return arrElement[2];
			}
		}
		return '';
	}
	function instantStr(str){
		var imax = str.length;
		var str_new = '';
		for(var i=0;i<str.length;i++){
			str_new += str.charAt(i)+'&nbsp;'; 
		}
		return str_new;
	}
	function getTopicName(id){
		var i;
		for(i=0;i<arr_document_topic.length;i++){
			if(arr_document_topic[i][0]==id) return arr_document_topic[i][1];
		}
		return 'N/A';
	}
	function setCookie(name,value){
		document.cookie = name + '=' + escape(value) +  ';path=/';
		return ;
	}
	function getCookie(name){
		var cname = name + '=';
		var dc = document.cookie;
		if (dc.length > 0) {
			var begin = dc.indexOf(cname);
			if (begin != -1) {
			begin += cname.length;
			var end = dc.indexOf(';', begin);
			if (end == -1) end = dc.length;
				return unescape(dc.substring(begin, end));
			}
		}
		return null;
	}	
	
function showMediaPlayer(link,width,height,play)
{
	var WMP7;
	try
	{
		if ( navigator.appName != "Netscape" )
		{
			WMP7 = new ActiveXObject('WMPlayer.OCX');
		}
	}
	catch (error)
	{
		;
	}
	var HTML = '';

	// Windows Media Player 7 Code
	if ( WMP7 )
	{
	HTML +=  ('<OBJECT height="'+height+'" width="'+width+'" classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" VIEWASTEXT>');
	HTML +=  ('<PARAM NAME="URL" VALUE="'+link+'">');
	HTML +=  ('<PARAM NAME="rate" VALUE="1">');
	HTML +=  ('<PARAM NAME="balance" VALUE="0">');
	HTML +=  ('<PARAM NAME="ShowStatusBar" VALUE="False">');
	HTML +=  ('<PARAM NAME="ShowControls" VALUE="False">')
	HTML +=	 ('<PARAM NAME="ShowAudioControls" VALUE="False" />')
	HTML +=  ('<PARAM NAME="ShowPositionControls" value="False" />');
	HTML +=  ('<PARAM NAME="currentPosition" VALUE="0">');
	HTML +=  ('<PARAM NAME="defaultFrame" VALUE="">');
	HTML +=  ('<PARAM NAME="playCount" VALUE="999">');
	HTML +=  ('<PARAM NAME="autoStart" VALUE="'+play+'">');
	HTML +=  ('<PARAM NAME="currentMarker" VALUE="0">');
	HTML +=  ('<PARAM NAME="invokeURLs" VALUE="-1">');
	HTML +=  ('<PARAM NAME="baseURL" VALUE="">');
	HTML +=  ('<PARAM NAME="mute" VALUE="0">');
	HTML +=  ('<PARAM NAME="uiMode" VALUE="full">');
	HTML +=  ('<PARAM NAME="stretchToFit" VALUE="0">');
	HTML +=  ('<PARAM NAME="windowlessVideo" VALUE="1">');
	HTML +=  ('<PARAM NAME="enabled" VALUE="-1">');
	HTML +=  ('<PARAM NAME="enableContextMenu" VALUE="0">');
	HTML +=  ('<PARAM NAME="fullScreen" VALUE="0">');
	HTML +=  ('<PARAM NAME="SAMIStyle" VALUE="">');
	HTML +=  ('<PARAM NAME="SAMILang" VALUE="">');
	HTML +=  ('<PARAM NAME="SAMIFilename" VALUE="">');
	HTML +=  ('<PARAM NAME="captioningID" VALUE="">');
	HTML +=  ('<PARAM NAME="Volume" VALUE="100">');
	HTML +=  ('</OBJECT>');
	}

	// Windows Media Player 6.4 Code
	else
	{
	HTML +=  ('<OBJECT  classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" ');
	HTML +=  ('codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" ');
	HTML +=  ('width="'+width+'" height="'+height+'"');
	HTML +=  ('standby="Loading Microsoft Windows Media Player components..." ');
	HTML +=  ('type="application/x-oleobject" VIEWASTEXT> ');
	HTML +=  ('<PARAM NAME="FileName"           VALUE="'+link+'">');
	HTML +=  ('<PARAM NAME="TransparentAtStart" Value="false">');
	HTML +=  ('<PARAM NAME="AutoStart"          Value="false">">');
	HTML +=  ('<PARAM NAME="AnimationatStart"   Value="false">');
	HTML +=  ('<PARAM NAME="ShowStatusBar" VALUE="True">');
	HTML +=  ('<PARAM NAME="ShowControls" VALUE="True">')
	HTML +=	 ('<PARAM NAME="ShowAudioControls" VALUE="True" />')
	HTML +=  ('<PARAM NAME="ShowPositionControls" value="True" />');
	HTML +=  ('<PARAM NAME="ShowDisplay"	 value ="false">');
	HTML +=  ('<PARAM NAME="playCount" VALUE="10">');
	HTML +=  ('<PARAM NAME="displaySize" 	 Value="0">');
	HTML +=  ('<PARAM NAME="Volume" VALUE="100">');
	HTML +=  ('<Embed type="application/x-mplayer2" ');
	HTML +=  ('pluginspage= ');
	HTML +=  ('"http://www.microsoft.com/Windows/MediaPlayer/" ');
	HTML +=  ('src="'+link+'" ');
	HTML +=  ('Name=MediaPlayer ');
	HTML +=  ('transparentAtStart=0 ');
	HTML +=  ('autostart=1 ');
	HTML +=  ('showstatusbar=1 ');
	HTML +=  ('showscontrols=1 ');
	HTML +=  ('playcount=10 ');
	HTML +=  ('volume=100');
	HTML +=  ('animationAtStart=0 ');
	HTML +=  ('width="'+width+'" height="'+height+'"');	
	HTML +=  ('></embed> ');
	HTML +=  ('</OBJECT> ');
	}	
		
	return HTML;	
}

function showpic(whichpic){
	var source= whichpic.getAttribute("name");
	var placeholder=document.getElementById("placeholder"); 
	placeholder.setAttribute("src",source); 
	var text =whichpic.getAttribute("id");
	var description = document.getElementById("description"); 
	description.firstChild.nodeValue=text; 
	
	}
function showpic_detail(whichpic){
	var source= whichpic.getAttribute("name");
	var placeholder=document.getElementById("placeholder"); 
	placeholder.setAttribute("src",source); 
	}
function showpic_detail_(whichpic,i){
	var source= whichpic.getAttribute("name");
	var placeholder=document.getElementById("placeholder"); 
	placeholder.setAttribute("src",source); 
	var num_class="num_page"+i; 
	num_class=getElementById("num_class");
	num_class.setAttribute("class","num_page_current");
	}
function showpic_introduce(whichpic){
	var source = whichpic.getAttribute("name");
	var placeholder=document.getElementById("placeholder"); 
	placeholder.setAttribute("src",source); 
	var id =whichpic.getAttribute("id");
	/*var text ='inc_introduce.php?id='+id+'&lang='+lang; 
	var description = document.getElementById("description"); 
	description.setAttribute("src",text); */
	var title= document.getElementById("title");
	title.firstChild.nodeValue=whichpic.getAttribute("title");
	}
function showpic_contact(whichpic){
	var source = whichpic.getAttribute("name");
	var placeholder=document.getElementById("placeholder"); 
	placeholder.setAttribute("src",source); 
	var id =whichpic.getAttribute("id");
	/*var text ='inc_contact_info.php?id='+id+'&lang='+lang; 
	var description = document.getElementById("description"); 
	description.setAttribute("src",text); */
	/*var title= document.getElementById("title");
	title.firstChild.nodeValue=whichpic.getAttribute("title");*/
	}	
function showpic_service(whichpic){
	var source = whichpic.getAttribute("name");
	var placeholder=document.getElementById("placeholder"); 
	placeholder.setAttribute("src",source); 
	var id =whichpic.getAttribute("id");
	//var text ='inc_service.php?id='+id+'&lang='+lang; 
	//var description = document.getElementById("description"); 
	//description.setAttribute("src",text); 
	/*var title= document.getElementById("title");
	title.firstChild.nodeValue=whichpic.getAttribute("title");*/
	}	
function showpic_news(whichpic){
	var source = whichpic.getAttribute("name");
	var placeholder=document.getElementById("placeholder"); 
	placeholder.setAttribute("src",source); 
	var id =whichpic.getAttribute("id");
	/*var text ='inc_news.php?catid='+id+'&lang='+lang; 
	var description = document.getElementById("description"); 
	description.setAttribute("src",text); */
/*	var title= document.getElementById("title");
	title.firstChild.nodeValue=whichpic.getAttribute("title");*/
	}	
		
var baseopacity=50

function slowhigh(which2){
	imgobj=which2
	browserdetect=which2.filters? "ie" : typeof which2.style.MozOpacity=="string"? "mozilla" : ""
	instantset(baseopacity)
	highlighting=setInterval("gradualfade(imgobj)",50)
}

function slowlow(which2){
cleartimer()
instantset(baseopacity)
}

function instantset(degree){
if (browserdetect=="mozilla")
imgobj.style.MozOpacity=degree/100
else if (browserdetect=="ie")
imgobj.filters.alpha.opacity=degree

}

function cleartimer(){
if (window.highlighting) clearInterval(highlighting)
}

function gradualfade(cur2){
if (browserdetect=="mozilla" && cur2.style.MozOpacity<1)
cur2.style.MozOpacity=Math.min(parseFloat(cur2.style.MozOpacity)+0.1, 0.99)
else if (browserdetect=="ie" && cur2.filters.alpha.opacity<100)
cur2.filters.alpha.opacity+=10
else if (window.highlighting)
clearInterval(highlighting)
}
