﻿//Khai báo biến global chứa đường dẫn đến root
//var strGlobalRoot = "/";

 function CreateHTML(id,html)
{
	    var d = document.getElementById(id);
  	    d.innerHTML = html;
}
function TextChange(strControl,field)
{    
   var ct = document.getElementById(strControl);
   if(ct!=null)
   {
      if(field.value!='')
      {
        if(ct.Checked==false)            
         ct.Checked = true;            
      }
   }   
}

function searchOnFocus(field,Msg,strControl) {
	if(field.value==Msg) 
	{
		field.value = '';
		var obj = document.getElementById(strControl);
		if(obj!=null)
		   obj.checked = true;
	}
}

function searchOnBlur(field,Msg,strControl) {
	if(field.value=='')
	{
		field.value=Msg;
		var obj = document.getElementById(strControl);
		if(obj!=null)
		   obj.checked = false;	
	}
}   

function setfocus(){
    document.forms[0].field.focus()
}
function setfocus(strControl)
{
    var obj = document.getElementById(strControl);
	if(obj!=null)
      obj.focus();
}
// RadioButton server in Repeater
function SetUniqueRadioButton(nameregex, current)
{
   re = new RegExp(nameregex);
   for(i = 0; i < document.forms[0].elements.length; i++)
   {
      elm = document.forms[0].elements[i]
      if (elm.type == 'radio')
      {
         if (re.test(elm.name))
         {
            elm.checked = false;
         }
      }
   }
   current.checked = true;
}


function ShowMessage(strMessage)
{
  alert(strMessage);
  return false;
}
 function showModalPopupViaClient(Ishow,ModalPopupBehaviorID)
  {      
      var modalPopupBehavior = $find(ModalPopupBehaviorID);
      if(Ishow==1)      
        modalPopupBehavior.show();
      else
        modalPopupBehavior.hide();
 }

//<!-- Dùng cho hover toolbar
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
// -->

//<!-- Dùng cho hover tab 24h
function ActiveTab(tab)
{
    DeactiveTab('Promotion');
    DeactiveTab('Price');
    DeactiveTab('Product');
    DeactiveTab('News');
    document.getElementById(tab).style.display = 'block';
    document.getElementById(tab + '_Left').className = 'Block24hActiveLeft';
    document.getElementById(tab + '_Center').className = 'Block24hActiveBg';
    document.getElementById(tab + '_Right').className = 'Block24hActiveRight';
}
function DeactiveTab(tab)
{
    document.getElementById(tab).style.display = 'none';
    document.getElementById(tab + '_Left').className = 'Block24hNormalLeft';
    document.getElementById(tab + '_Center').className = 'Block24hNormalBg';
    document.getElementById(tab + '_Right').className = 'Block24hNormalRight';
}
/*
 *	Code for 4 tab general
 */
function ActiveTabGeneral(tab)
{
    DeactiveTabGeneral('tab1');
    DeactiveTabGeneral('tab2');
    DeactiveTabGeneral('tab3');
    DeactiveTabGeneral('tab4');
    document.getElementById(tab).style.display = 'block';
    document.getElementById(tab + '_Left').className = 'Block24hActiveLeft';
    document.getElementById(tab + '_Center').className = 'Block24hActiveBg';
    document.getElementById(tab + '_Right').className = 'Block24hActiveRight';
}
function DeactiveTabGeneral(tab)
{
    document.getElementById(tab).style.display = 'none';
    document.getElementById(tab + '_Left').className = 'Block24hNormalLeft';
    document.getElementById(tab + '_Center').className = 'Block24hNormalBg';
    document.getElementById(tab + '_Right').className = 'Block24hNormalRight';
}
function ActiveTabShopping(tab,index)
{
    if(document.getElementById(tab) != null)
    {
        DeactiveTabShopping('tab1');
        DeactiveTabShopping('tab2');
        DeactiveTabShopping('tab3');
        DeactiveTabShopping('tab4');
        document.getElementById(tab).style.display = 'block';
        document.getElementById(tab + '_Left').className = 'Block24hActiveLeft';
        document.getElementById(tab + '_Center').className = 'Block24hActiveBg';
        document.getElementById(tab + '_Right').className = 'Block24hActiveRight';
        document.getElementById("indextab").value = index;
    }
}
function DeactiveTabShopping(tab)
{
    document.getElementById(tab).style.display = 'none';
    document.getElementById(tab + '_Left').className = 'Block24hNormalLeft';
    document.getElementById(tab + '_Center').className = 'Block24hNormalBg';
    document.getElementById(tab + '_Right').className = 'Block24hNormalRight';
}
function ActiveTabShopping3(tab,index)
{
    if(document.getElementById(tab) != null)
    {
        DeactiveTabShopping3('tab1');
        DeactiveTabShopping3('tab2');
        DeactiveTabShopping3('tab3');        
        document.getElementById(tab).style.display = 'block';
        document.getElementById(tab + '_Left').className = 'Block24hActiveLeft';
        document.getElementById(tab + '_Center').className = 'Block24hActiveBg';
        document.getElementById(tab + '_Right').className = 'Block24hActiveRight';
        document.getElementById("indextab").value = index;
    }
}
function DeactiveTabShopping3(tab)
{
    document.getElementById(tab).style.display = 'none';
    document.getElementById(tab + '_Left').className = 'Block24hNormalLeft';
    document.getElementById(tab + '_Center').className = 'Block24hNormalBg';
    document.getElementById(tab + '_Right').className = 'Block24hNormalRight';
}
function ActiveTabTwo(tab)
{
    DeactiveTabTwo('tab1');
    DeactiveTabTwo('tab2');   
    document.getElementById(tab).style.display = 'block';
    document.getElementById(tab + '_Left').className = 'Block24hActiveLeft';
    document.getElementById(tab + '_Center').className = 'Block24hActiveBg';
    document.getElementById(tab + '_Right').className = 'Block24hActiveRight';
}
function DeactiveTabTwo(tab)
{
    document.getElementById(tab).style.display = 'none';
    document.getElementById(tab + '_Left').className = 'Block24hNormalLeft';
    document.getElementById(tab + '_Center').className = 'Block24hNormalBg';
    document.getElementById(tab + '_Right').className = 'Block24hNormalRight';
}
function ActiveTabThree(tab)
{
    DeactiveTabThree('tab1');
    DeactiveTabThree('tab2');   
    DeactiveTabThree('tab3');   
    document.getElementById(tab).style.display = 'block';
    document.getElementById(tab + '_Left').className = 'Block24hActiveLeft';
    document.getElementById(tab + '_Center').className = 'Block24hActiveBg';
    document.getElementById(tab + '_Right').className = 'Block24hActiveRight';
}
function DeactiveTabThree(tab)
{
    document.getElementById(tab).style.display = 'none';
    document.getElementById(tab + '_Left').className = 'Block24hNormalLeft';
    document.getElementById(tab + '_Center').className = 'Block24hNormalBg';
    document.getElementById(tab + '_Right').className = 'Block24hNormalRight';
}
// -->

//<!-- Nạp trước ảnh của toolbar
function PreloadImageToolbar(path)
{
    MM_preloadImages(path + '/Images/SiteImages/MenuIcon/dtdd_02.gif', 
        path + '/Images/SiteImages/MenuIcon/phukien_02.gif',
        path + '/Images/SiteImages/MenuIcon/sim_02.gif',
        path + '/Images/SiteImages/MenuIcon/maycu_02.gif',
        path + '/Images/SiteImages/MenuIcon/download_02.gif',
        path + '/Images/SiteImages/MenuIcon/rao_02.gif',
        path + '/Images/SiteImages/MenuIcon/dichvu_02.gif',
        path + '/Images/SiteImages/MenuIcon/tim_02.gif');
}
//-->

//<!-- Đối tượng phone để sử dụng ajax
function AjaxPhoneObject(minprice, maxprice, branch, name)
{
    this.intMinPrice = minprice;
    this.intMaxPrice = maxprice;
    this.strDivName = name;
    this.intBranchID = branch;
    this.LoadPhoneList = LoadPhoneList;
}
function LoadPhoneList()
{
    document.getElementById(strDivName).innerHTML = CreateRequest(intMinPrice, intMaxPrice);
}
function CreateRequest(minprice, maxprice)
{
    return "";
}
//-->

//<!-- Đối tượng tạo ajax request

//---------- Yeu cau du lieu, va tao du lieu yeu cau vao iframe de no back duoc 
function requestAjaxData(dataSource, divID) 
{
	//--- tao cai bieu tuong waiting
    var obj = document.getElementById(divID); 
    obj.innerHTML = "<br><br><BR><img src='images/process.gif'><br><BR><br><b> ĐANG TẢI DỮ LIỆU .....</b>";
    if (navigator.appName == "Microsoft Internet Explorer")
    {
        var html = '<script>parent.getAjaxData("' + dataSource + '","' + divID + '");</script>';
        myFrame.document.open();
        myFrame.document.write(html);
        myFrame.document.close();
    }	
    else
    {
        var mLink = "response.aspx?datalink=" + dataSource + "&container=" + divID;
        myFrame.location.href = mLink;
    }
}
function GetAjaxData(dataSource, divID) 
{ 
    var XMLHttpRequestObject = false; 
    if (window.XMLHttpRequest)
    {
        XMLHttpRequestObject = new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
        //IE
        try
        {
            XMLHttpRequestObject = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e)
            {}
        }
    }
    if(XMLHttpRequestObject)
    {
        var obj = document.getElementById(divID); 
        XMLHttpRequestObject.open("GET", dataSource); 
        XMLHttpRequestObject.onreadystatechange = function() 
        { 
            if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
            {
                obj.innerHTML = XMLHttpRequestObject.responseText; 
            } 
        } 
        XMLHttpRequestObject.send(null);
    }
}
function DisplayPhoneList(obj)
{
    var poststr = "MinPrice=" + encodeURI(obj.intMinPrice) + "&MaxPrice=" + encodeURI(obj.intMaxPrice) + "&BranchID=" + encodeURI(obj.intBranchID);
    GetAjaxData(strAjaxServer + "?" + poststr, obj.strDivName);
    //MakePOSTRequest(strAjaxServer, poststr, obj.strDivName);
}
var div = "";
function MakePOSTRequest(url, parameters, strDiv)
{
    div = strDiv;
    var http_request = false;
    if (window.XMLHttpRequest)
    {
        // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType)
        {
            //set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
        }
    }
    else if (window.ActiveXObject)
    {
        //IE
        try
        {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e)
            {}
        }
    }
    if (!http_request)
    {
        alert('Không thể nạp dữ liệu!');
        return false;
    }
    http_request.onreadystatechange = DisplayContents;
    http_request.open('POST', url, true);
    http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http_request.setRequestHeader("Content-length", parameters.length);
    http_request.setRequestHeader("Connection", "close");
    http_request.send(parameters);
}
function DisplayContents()
{
    if (http_request.readyState == 4)
    {
        if (http_request.status == 200)
        {
            alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById(div).innerHTML = result;            
        }
        else
        {
            alert("Có lỗi xảy ra khi nạp dữ liệu!");
        }
    }
}
function ShowPhoneList()
{
    if (bolIsLoadPhone)
    {
        for (var i = 0; i < intPhoneListTypeCount; i++)
        {
            DisplayPhoneList(arrPhoneListType[i]);
        }
    }
}
//-->

function CreateHTML(id,html)
{
	var d = document.getElementById(id);
  	d.innerHTML = html;  	
}
//Ẩn/hiển thị layer trên control Branch
function ShowHideBranch(layer_ref) 
{
    var state = document.getElementById(layer_ref).style.display;
    if (state == 'block') 
    {
        state = 'none';
    }
    else
    {
        state = 'block';
    }
    try
    {
    
        if (document.all) 
        {    
            //IS IE 4 or 5 (or 6 beta)
            eval( "document.all." + layer_ref + ".style.display = state");
        }
        else if (document.getElementById && !document.all) 
        {
            hza = document.getElementById(layer_ref);
            hza.style.display = state;
        }
    }
    catch (e)
    {}
}
//đổi hình mũi tên trái sang mũi tên down
function ChangeImage(layer_ref)
{
    var img1 = strGlobalRoot + "/Images/SiteImages/Branch/IconArrowLeft.gif";
    var img2 = strGlobalRoot + "/Images/SiteImages/Branch/IconArrowUp.gif";
    var img = document.getElementById(layer_ref).src;
    
    if (img.indexOf("IconArrowLeft.gif") >= 0)
        document.getElementById(layer_ref).src = img2;
    else
        document.getElementById(layer_ref).src = img1;
}
//Đổi màu sản phẩm và giá
function ChangeProductColor(image, price,preorderprice, ProductCode, IsExist,pricedown,brandid)
{
    try
    {
        document.getElementById("PhoneDetailImage").src = strProductImagePath + "/" + image;
    }
    catch (e)
    {}
    try
    {
        document.getElementById("PhoneDetailPrice").innerHTML = price + " VND";
        document.getElementById("hdProductCode").value = ProductCode;
        document.getElementById("hdPrice").value = price;                   
        if(parseFloat(price) > 0)
            document.getElementById("dvStockProduct").style.display = "block";
        else
            document.getElementById("dvStockProduct").style.display = "none";
            
            if(preorderprice!="" && preorderprice != "0,000")
            {
                document.getElementById("spPre").style.display = "none";                
                document.getElementById("hdPreOrderPrice").value = preorderprice;                
                if(pricedown != "0")
                {
                  document.getElementById("hdValuePreOrder").value = pricedown;
                  document.getElementById("divPreOrder_Detail").style.display = "";
                  if (brandid != 2)
                    document.getElementById("spValuePre").innerHTML = "Đặt hàng online giá rẻ hơn: " + pricedown + " VND";
                  else
                    document.getElementById("spValuePre").innerHTML = "Đặt hàng online giá rẻ hơn!";
                  document.getElementById("spPopupPriceDown").innerHTML = pricedown + " VND";
                }
                else
                {
                   document.getElementById("spPre").style.display = "none";
                   document.getElementById("hdValuePreOrder").value = "0";
                   document.getElementById("divPreOrder_Detail").style.display = "none";
                }                
            }
            else
            {                
                document.getElementById("spPre").style.display = "none";                
                document.getElementById("hdValuePreOrder").value = "0";                
                document.getElementById("divPreOrder_Detail").style.display = "none";
            }
    }
    catch (e)
    {      
       document.getElementById("dvStockProduct").style.display = "none";
       document.getElementById("divPreOrder_Detail").style.display = "none";
    }
    try
    {
        if(parseFloat(price) > 0)
            document.getElementById("spnMsgBranchName").style.display = "block";
        else
            document.getElementById("spnMsgBranchName").style.display = "none";        
    }
    catch(e)
    {
        document.getElementById("spnMsgBranchName").style.display = "none";
    }
}
/*-- Đối tượng Promotion --*/
function Promotion(product, promotioninfo)
{
    this.ProductID = product;
    this.PromotionInfo = promotioninfo;
}
function ShowPromotion(productid)
{
    for (var i = 0; i < intPhoneCount; i++)
    {
        if (objPromotion[i].ProductID == productid)
        {
            document.getElementById("PhonePromotionInfo").innerHTML = objPromotion[i].PromotionInfo;
            break;
        }
    }
}
var objPromotion = new Array();
var intPhoneCount = 0;
/*--// Đối tượng Promotion --*/

/*-- Đối tượng StandardKit --*/
function StandardKit(product, standardkit)
{
    this.ProductID = product;
    this.StandardKit = standardkit;
}
function ShowStandardKit(productid)
{
    for (var i = 0; i < objStandardKit.length; i++)
    {
        if (objStandardKit[i].ProductID == productid)
        {
            document.getElementById("PhoneStandardKit").innerHTML = objStandardKit[i].StandardKit;
            break;
        }
    }
}
var objStandardKit = new Array();
/*--// Đối tượng StandardKit --*/
//Hiển thị divName
function ShowSpecificationTab(divName)
{
    try
    {
        document.getElementById(divName).style.display = "block";
    }
    catch (e)
    {
    }
}
function HideSpecificationTab(divName)
{
    try
    {
        document.getElementById(divName).style.display = "none";
    }
    catch (e)
    {
    }
}
function SetClassName(id, name)
{
    document.getElementById(id + "Left").className = name + "_Left";
    document.getElementById(id + "Bg").className = name + "_Bg";
    document.getElementById(id + "Right").className = name + "_Right";
}
/// <summary>
/// Hàm tạo mới 1 cửa sổ của RadWindow
/// </summary>
/// <param name="o"></param>
function GetRadWindow()
{
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow;
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
    return oWindow;
}
/// <summary>
/// Hàm mở cửa sổ download thứ nhất
/// </summary>
/// <param name="o"></param>
/// <param name="oWin"></param>
function ShowNewWindow(o, oWin)
{      
    var oWindow;
    oWindow = window.radopen (o, oWin);        
    oWindow.setSize (400, 400);
    oWindow.set_modal(true);
    oWindow.set_title ("Kết quả khảo sát");
    
}
function OpenWindow121(url)
{    
    window.open(url,"Khảo sát","width=450,height=115,toolbars=no,menubar=no,scrollbars=no,resizable=no,status=no");
}
//set default cho btn_Search
function PerformClick(e, target) 
{
    if (e.which || e.keyCode)
    {
        if ((e.which == 13) || (e.keyCode == 13))
        {
            document.getElementById(target).click();
            return false;
        }
    }
    else
    {
        return true;
    } 
}
