﻿// JavaScript Document
//=================================================================================================
function new_window(url,width, height){
	window.open (url, "new_window", "width="+ width + ", height="+ height +", resizable=1,scrollbars=yes");
}

function confirmSubmit(){
	var agree=confirm("Are you sure?");
	if (agree)
		return true ;
	else
		return false ;
}
//Disable right mouse click Script
//By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
//For full source code, visit http://www.dynamicdrive.com

var message="Function Disabled!";

///////////////////////////////////
function clickIE4(){
if (event.button==2){
//alert(message);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
//alert(message);
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("return false")
//=================================================================================================
function remove_dot(val) {
    var str = val;
    var myStr = '';
    var temp = '';
    
    for(var i = 0; i < str.length; i++) {    
        temp = str.substring(i, i + 1); 
        if (temp >= 0 && temp <=9) {
            myStr += temp;     
        }// end if
    }// end for
    return myStr;
}
//=================================================================================================
function format_number(obj) {
    /*var str = obj.value;
    str = remove_dot(str);
    obj.value = add_dot(str);
    */
    
    obj.value = FormatNumber(obj.value);
}
//=================================================================================================
function onfocus_onblur(obj,text1, text2) {
    if(obj.value == text1)
        obj.value = text2;
}
//=================================================================================================
function FormatNumber(str){
	var strTemp = GetNumber(str);
	if(strTemp.length <= 3)
		return strTemp;
	strResult = "";
	for(var i =0; i< strTemp.length; i++)
		strTemp = strTemp.replace(".", "");
	for(var i = strTemp.length; i>=0; i--)
	{
		if(strResult.length >0 && (strTemp.length - i -1) % 3 == 0)
			strResult = "." + strResult;
		strResult = strTemp.substring(i, i + 1) + strResult;
	}	
	return strResult;
}
//=================================================================================================
function GetNumber(str)
{
    for(var i = 0; i < str.length; i++)
    {    
        var temp = str.substring(i, i + 1);        
        if(!(temp == "," || temp == "." || (temp >= 0 && temp <=9)))
        {
            //alert("Vui lòng nhập số (0-9)!");
            return str.substring(0, i);
        }
        if(temp == " ")
            return str.substring(0, i);
    }
    return str;
}
//=================================================================================================
function ConvertPriceText(strTemp)
{
    strTemp        = remove_dot(strTemp);//strTemp.replace(/,/g, "");
    //alert(strTemp);
    var priceTy    = parseInt(strTemp/1000000000,0)
    var priceTrieu = parseInt((strTemp % 1000000000)/1000000,0)
    var priceNgan  = parseInt(((strTemp % 1000000000))%1000000/1000,0)
    var priceDong  = parseInt(((strTemp % 1000000000))%1000000%1000,0)
    var so = Array("Không","Một","Hai","Ba","Bốn","Năm","Sáu","Bảy","Tám","Chín")
    var strTextPrice = ""      
    if(priceTy > 0 && parseInt(strTemp,0) > 900000000)
        strTextPrice = strTextPrice  + "<b>" + priceTy + " tỷ</b> "
    if(priceTrieu > 0)
        strTextPrice = strTextPrice  + "<b>" + priceTrieu + " triệu</b> "
    if(priceNgan > 0)
        strTextPrice = strTextPrice  + "<b>" + priceNgan + " ngàn</b> "
    
    if(priceTy > 0 || priceTrieu > 0 || priceNgan > 0 || priceDong > 0)
        strTextPrice = strTextPrice  + "<b>đồng</b>"
   return strTextPrice
}

//=================================================================================================
// Function WriteSwf
function WriteSwf(img, wsize, hsize) {
	document
			.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\""
					+ wsize + "\" height=\"" + hsize + "\">");
	document.write("<param name=\"movie\" value=\"" + img + "\">");
	document.write("<param name=\"quality\" value=\"high\">");
	document.write("<param name=wmode value=transparent>");
	document.write("<param name=\"menu\" value=\"false\">");
	document.write("<embed src=\""
					+ img
					+ "\" wmode=\"transparent\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""
					+ wsize + "\" height=\"" + hsize
					+ "\" menu=\"false\"></embed>");
	document.write("</object>");
}

//create HtmlRequest
function makeObject()
{
	var x; 
	var browser = navigator.appName; 
	if(browser == "Microsoft Internet Explorer")
	{
		x = new ActiveXObject("Microsoft.XMLHTTP");
	}else
	{
		x = new XMLHttpRequest();
	}
	return x;
}
function validate_search()
{
	var frm=document.frmSearch;
	if(frm.txtSearch.value=='')
	{
		alert("Chưa nhập từ khóa");
		frm.txtSearch.focus();
		return false;
	}
	frm.submit();
	return true;
}

	function validate()
	{
		var frm=document.frmnewsletter;
		if(!isEmailAddr(frm.txtemail.value))
		{
			alert("Nhập email không hợp lệ.");
			frm.txtemail.focus();
			return;
		}
		frm.submit();
	}

function MenuVisible(id)
{
	
	var total=document.getElementById("numMenu").value;
	for(i=1;i<total;i++)
	{
		var str="divMenu"+i;
		//alert(str);
		document.getElementById(str).style.display='none';
		
	}

	if(id==0) return;
	document.getElementById("divMenu"+id).style.display='';
	
	
}
function MenuVisibleSub(id,idSub)
{
	if(id==0)return;
	var total=document.getElementById("MenuTotal"+id);
	for(j=0;i<total;j++)
	{
		document.getElementById("MenuSub"+id+j).className='';
	}
	document.getElementById("MenuSub"+id+idSub).className='currentsubM';
}

//box menu 2
function MenuVisible2(id)
{
	
	var total=document.getElementById("numMenu2").value;
	for(i=1;i<total;i++)
	{
		var str="divMenu2"+i;
		//alert(str);
		document.getElementById(str).style.display='none';
		
	}

	if(id==0) return;
	document.getElementById("divMenu2"+id).style.display='';
	
	
}
function MenuVisibleSub2(id,idSub)
{
	if(id==0)return;
	var total=document.getElementById("numMenu2"+id);
	for(j=0;i<total;j++)
	{
		document.getElementById("MenuSub2"+id+j).className='';
	}
	document.getElementById("MenuSub2"+id+idSub).className='currentsubM';
}
//=================================================================================================
// Function
var captchaImageUrl = 'CaptchaSecurityImages.php?width=100&height=25&characters=6';
jQuery(document).ready(function() {
	jQuery('#reloadImg').click(
			function() {
				jQuery('#securityImg').attr('src',captchaImageUrl + '&rand=' + Math.random());
				return false;
			});
	jQuery('#reloadImg').click();

	//Default Action
	jQuery(".tab_content").hide(); //Hide all content
	jQuery("ul.tabs li:first").addClass("active").show(); //Activate first tab
	jQuery(".tab_content:first").show(); //Show first tab content
	
	//On Click Event
	jQuery("ul.tabs li").click(function() {
		jQuery("ul.tabs li").removeClass("active"); //Remove any "active" class
		jQuery(this).addClass("active"); //Add "active" class to selected tab
		jQuery(".tab_content").hide(); //Hide all tab content
		var activeTab = jQuery(this).find("a").attr("rel"); //Find the rel attribute value to identify the active tab + content
		//alert(activeTab);
		jQuery(activeTab).fadeIn(); //Fade in the active content
		return false;
	});
	
	jQuery("#input2").dynamicForm("#btnThem2", "#btnXoa2", {limit:5});
});
