﻿

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.0
  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 && document.getElementById) x=document.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];}
}
//-------------------------------------------------------------
// Select all the checkboxes (Hotmail style)
//-------------------------------------------------------------
function SelectAllCheckboxes(theBox){

	xState=theBox.checked;    
    elm=theBox.form.elements;
    for(i=0;i<elm.length;i++)
    if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
        {
        //elm[i].click();
        if(elm[i].checked!=xState)
        elm[i].click();
        //elm[i].checked=xState;
        }
}
//Open Image
var fBrw=(navigator.userAgent.indexOf('MSIE')!= -1 && navigator.userAgent.indexOf('Windows')!= -1);

function checkimage(file)
{	 	
    picfile = new Image(); 
    picfile.src =(file);           
    width=picfile.width;
    height=picfile.height;
    if (width>600 || height>600)
    {
        alert("kích thước ảnh không được lớn hơn 600px");
        return false;
    }
    return true;
}

function openNewImage(file)
{	 	
    picfile = new Image(); 
    picfile.src =(file);           
    width=picfile.width;
    height=picfile.height;
            
	//location.replace('http://localhost:8090/news/images/news/duongsat.jpg');
	//window.open('/news/viewpicture.aspx?filename=duongsat.jpg');
	//window.open(file,'showpicture', 'toolbar=no,location=no ,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,topmargin=0,leftmargin=0,width='+width+',height='+height);
	
	winDef = 'status=no,resizable=no,scrollbars=yes,toolbar=no,location=no,fullscreen=no,titlebar=yes,height='.concat(height).concat(',').concat('width=').concat(width).concat(',');
	winDef = winDef.concat('top=').concat((screen.height - height)/2).concat(',');
	winDef = winDef.concat('left=').concat((screen.width - width)/2);
	newwin = open('', '_blank', winDef);

	newwin.document.writeln('<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">');
	newwin.document.writeln('<a href="" onClick="window.close(); return false;"><img src="', file, '" alt="', (fBrw) ? '&#272;&#243;ng l&#7841;i' : 'Dong lai', '" border=0></a>');
	newwin.document.writeln('</body>');

}

function openImage(file,width,height)
{

	//location.replace('http://localhost:8090/news/images/news/duongsat.jpg');
	//window.open('/news/viewpicture.aspx?filename=duongsat.jpg');
	//window.open(file,'showpicture', 'toolbar=no,location=no ,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,topmargin=0,leftmargin=0,width='+width+',height='+height);
	winDef = 'status=no,resizable=no,scrollbars=no,toolbar=no,location=no,fullscreen=no,titlebar=yes,height='.concat(height).concat(',').concat('width=').concat(width).concat(',');
	winDef = winDef.concat('top=').concat((screen.height - height)/2).concat(',');
	winDef = winDef.concat('left=').concat((screen.width - width)/2);
	newwin = open('', '_blank', winDef);

	newwin.document.writeln('<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">');
	newwin.document.writeln('<a href="" onClick="window.close(); return false;"><img src="', file, '" alt="', (fBrw) ? '&#272;&#243;ng l&#7841;i' : 'Dong lai', '" border=0></a>');
	newwin.document.writeln('</body>');

}

function openWinBlank(a) {

if (a.value != 0 )
{
    window.open(a.value,'_blank','');
}
}




function openfile(file,width,height)
{

	//location.replace('http://localhost:8090/news/images/news/duongsat.jpg');
	//window.open('/news/viewpicture.aspx?filename=duongsat.jpg');
	//window.open(file,'showpicture', 'toolbar=no,location=no ,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,topmargin=0,leftmargin=0,width='+width+',height='+height);
	winDef = 'status=no,resizable=no,scrollbars=no,toolbar=no,location=no,fullscreen=no,titlebar=yes,height='.concat(height).concat(',').concat('width=').concat(width).concat(',');
	winDef = winDef.concat('top=').concat((screen.height - height)/2).concat(',');
	winDef = winDef.concat('left=').concat((screen.width - width)/2);
	newwin = open(file, '_blank', winDef);

}

function change_location(boxmenu) {
	var url = boxmenu[boxmenu.selectedIndex].value;
	if (url != '') {
		window.location = url;
	}
}

function showFlash(flashlink,fw,fh)
{
document.write('<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" id="obj1" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" border="0" width="' + fw +  '" height="' + fh + '" VIEWASTEXT>');
document.write('<param name="movie" value="' + flashlink + ' ">');
document.write('<param name="quality" value="High">');
document.write('<param name="menu" value="false">');
document.write('<param name="wmode" value="transparent">');
document.write('<embed src="' + flashlink + '" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="obj1" width="' + fw +  '" height="' + fh + '" quality="High" menu="false" wmode="transparent"></object>');
}


function FormatNumber(value, displayZero)
    {
		if (value == 0) return 0;
        if (value == '') return (displayZero ? '0' : '');
        try
        {
            var number = parseFloat(value);
            value = this.FormatNumber1(number, 2, '.', ',');
            return (value);
        }
        catch (err)
        {
            return (displayZero ? '0' : '');
        }
    }

   function FormatNumber1(number, decimals, decimalSeparator, thousandSeparator) 
    {
        var number = number.toFixed(decimals);
        
        var temp = number.toString();
        
        var f = temp.substr(temp.length - decimals, decimals);
        
        while (f != '' && f.charAt(f.length - 1) == '0') f = f.substr(0, f.length - 1);
        
        if (f != '') f = decimalSeparator + f;
        
        var t = temp.substr(0, temp.length - 3);
        
        if (thousandSeparator != '' && t.length > 3) 
	    {
		    h = t;
		    t = '';
    		
		    for (j = 3; j < h.length; j += 3) 
		    {
			    i = h.slice(h.length - j, h.length - j + 3);
			    t = thousandSeparator + i +  t + '';
		    }
    		
		    j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
		    t = j + t;
	    }
    	
	    temp = t + f;
    	
        return temp;
    }

function FormatDate(strDate)
{	
	if (strDate.length == 0)
	{
		return "";
	}
	//alert(strDate);
	return strDate.substr(6,2) + "/" + strDate.substr(4,2) + "/" + strDate.substr(0,4)

}

function doTrans_MyAdv(imgMyArray,htmlMy,curr) 
{	
 //if (curr==imgMyArray.length) curr=0;
 curr = curr % imgMyArray.length;
  	 var sW;
 	 var sH;
 if(navigator.appName=="Microsoft Internet Explorer")
 {
	 var part2=imgMyArray[curr].split("$$$");
	 var srcimage2=part2[0];
	 var url2=part2[1];	
 	 var type=part2[2];	
 	 


	if (srcimage2 == "")
	{
		srcimage2 = "/News/Images/noimage.jpg";
	}


	if (type == 1)
	{
	
		if (url2.split("|")[1] != 0)
		{
		 sW = " width='" + url2.split("|")[1] + "' ";
		}
		
		if (url2.split("|")[2] != 0)
		{
		 sH = " height='" + url2.split("|")[2] + "' ";
		}		
	
		htmlMy.innerHTML = "<img src = '" +  srcimage2 + "' name = '" + url2 + "' style = 'cursor:pointer;' onclick='GotoSite(this.name);' alt = '' " + sW + sH + "  >";
	}
	else if (type == 3)
	{
		//alert(url2);        
		htmlMy.innerHTML = "<embed pluginspage=http://www.macromedia.com/go/getflashplayer align=baseline src='" + srcimage2 + "' width='" + url2.split("|")[1] + "' height='" + url2.split("|")[2] + "' type=application/x-shockwave-flash loop='true' menu='false' quality='high' salign='LT' bgcolor='' wmode='transparent'></embed>"
	}	
	else if (type == 5)
	{
	    htmlMy.innerHTML = srcimage2;
	}
  }
  else
  {
	 var part2=imgMyArray[curr].split("$$$");
	 var srcimage2=part2[0];
	 var url2=part2[1];	
 	 var type=part2[2];	

	if (srcimage2 == "")
	{
		srcimage2 = "/News/Images/noimage.jpg";
	}

	if (type == 1)
	{
	
		if (url2.split("|")[1] != 0)
		{
		 sW = " width='" + url2.split("|")[1] + "' ";
		}
		
		if (url2.split("|")[2] != 0)
		{
		 sH = " height='" + url2.split("|")[2] + "' ";
		}		
	
		htmlMy.innerHTML = "<img src = '" +  srcimage2 + "' name = '" + url2 + "' style = 'cursor:pointer;' onclick='GotoSite(this.name);' alt = '' " + sW + sH + "  >";
	}
	else if (type == 3)
	{
		//alert(url2);
		htmlMy.innerHTML = "<embed pluginspage=http://www.macromedia.com/go/getflashplayer align=baseline src='" + srcimage2 + "' width='" + url2.split("|")[1] + "' height='" + url2.split("|")[2] + "' type=application/x-shockwave-flash loop='true' menu='false' quality='high' salign='LT' bgcolor='' wmode='transparent'></embed>"
	}
	else if (type == 5)
	{
	    htmlMy.innerHTML = srcimage2;
	}
  }    
}


//--- Main Js -- //

//Note make handler /atv/ point to  displayadv.aspx?id={uid}

function GotoSite(url2)
{	 		
	 //window.location.href=url2;
	 var w,h,uid;
	 var p = url2.split("|");
	 uid = p[0];
	 w=p[1];
	 h=p[2];

	 if (url2 != '')
	 {
		if (w == 0) 
		{
			window.open('/vn/atv/' + uid + '/index.aspx','','',''); 
		}
		else
		{
			openfile('/vn/atv/' + uid + "/index.aspx",w,h);
		}
	 }
}

function validate_email(email) {
    var objRegExp = /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i;
    return objRegExp.test(email);
}

function clearById(obj_id) {
    clear($(obj_id));
}
function clear(obj) {
    while (obj.firstChild) {
        obj.removeChild(obj.firstChild);
    }
}

function get_url_params(name) {
 name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
 var regexS = "[\\?&]"+name+"=([^&#]*)";
 var regex = new RegExp( regexS );
 var results = regex.exec(window.location.href);
 if( results == null ) {
 return "";
 }
 else {
 return decodeURI(results[1].split('+').join(' '));
 }
} 

function get_url_multi_params(name) {
    var vars, hash;
    vars = "";
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        if(name == hash[0])
            vars = vars  + hash[1] + ","; 
    }
    return vars;
}

function getUrlMultiParam(name) {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        if(name == hash[0])
        vars.push(hash[1]);       
    }
    return vars;
}

function set_home_page(obj) {
	var url = 'http://sanbds.vn';	
	var userAgent = navigator.userAgent.toLowerCase();
	var ie = false;
	if (userAgent.indexOf('msie') > -1) {
		ie = true;
	}
	if (ie) {
		obj.style.behavior = 'url(#default#homepage)';
		obj.setHomePage(url);
	}
		else{// Mozilla Firefox Bookmark
		window.sidebar.addPanel('sanbds.vn', url, '');
	}
	return false;
}

function init_lightbox(eid) {
    var imgs = document.getElementById(eid).getElementsByTagName('img');
	for (var i = 0; i < imgs.length; i++) {
	   
	    var $img = imgs[i];
	    var $a = document.createElement('a');
	    $a.setAttribute('rel', 'lightbox[' + eid + ']');
	    $a.setAttribute('href', $img.src);
	    try {
		    $a.setAttribute('title', $img.alt);
	    }
	    catch (e) {}
	    $img.parentNode.insertBefore($a, $img);
	    $img.removeAttribute('onclick');
	    $a.appendChild($img);
	    
    }
}


function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) 
{
  // the highlightStartTag and highlightEndTag parameters are optional
  if ((!highlightStartTag) || (!highlightEndTag)) {
    highlightStartTag = "<font style='color:blue; background-color:yellow;'>";
    highlightEndTag = "</font>";
  }
  
  // find all occurences of the search term in the given text,
  // and add some "highlight" tags to them (we're not using a
  // regular expression search, because we want to filter out
  // matches that occur within HTML tags and script blocks, so
  // we have to do a little extra validation)
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();
    
  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {
      // skip anything inside an HTML tag
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
        // skip anything inside a <script> block
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
          bodyText = bodyText.substr(i + searchTerm.length);
          lcBodyText = bodyText.toLowerCase();
          i = -1;
        }
      }
    }
  }
  return newText;
}



var mainWidth = 960; 
var bannerWidth = 115;
function FloatTopDiv()
{
    var ns = (navigator.appName.indexOf("Netscape") != -1);
    if(!ns)
    {
        startLX = document.body.clientWidth/2 - (mainWidth/2 + bannerWidth + 25) , startLY = 172;
        startRX = ((document.body.clientWidth)/2) + mainWidth/2 + 25 , startRY = 172;
    }
    else
    {
        startLX = document.body.clientWidth/2 - (mainWidth/2 + bannerWidth + 25) , startLY = 172;
        startRX = ((document.body.clientWidth)/2) + mainWidth/2 + 25 , startRY = 172;
       
    }
    var d = document;

    function m1(id)
    {
        var e1=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
        if (e1 != null){
            e1.sP=function(x,y){this.style.left=x+"px";this.style.top=y+"px";};
            e1.x = startRX;
            e1.y = startRY;
        }
        return e1;
    }
    function m2(id)
    {
        
        var e2=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
        if(e2 != null){
            e2.sP=function(x,y){this.style.left=x+"px";this.style.top=y+"px";};
            e2.x = startLX;
            e2.y = startLY;
        }
        return e2;
    }
    window.stayTopLeft=function()
    {
        if (document.documentElement && document.documentElement.scrollTop){
            var pY = ns ? pageYOffset : document.documentElement.scrollTop;
            if (document.documentElement.scrollTop > 172){
                startLY = 3;
                startRY = 3;
            } else {
                startLY = 172;
                startRY = 172;
            }
        }
        else if (document.body){
            var pY = ns ? pageYOffset : document.body.scrollTop;
            if (document.body.scrollTop > 172){
                startLY = 3;
                startRY = 3;
            } else {
                startLY = 172;
                startRY = 172;
            }        
          
        }
        if (ftlObj != null){ 
            ftlObj.y += (pY + startRY - ftlObj.y)/16;
            ftlObj.sP(ftlObj.x, ftlObj.y);
        }
        if (ftlObj2 != null){
            ftlObj2.y += (pY + startLY - ftlObj2.y)/16;
            ftlObj2.sP(ftlObj2.x, ftlObj2.y);
        }
        if ((ftlObj != null) ||(ftlObj2 != null)){
            setTimeout("stayTopLeft()", 1);
        }
    }
    ftlObj = m1("banner_floating_right");
    ftlObj2 = m2("banner_floating_left");
    stayTopLeft();
}

function ShowAdDiv()
{
    try{
    
        var objAdDivRight = document.getElementById("banner_floating_right");
        var objAdDivLeft = document.getElementById("banner_floating_left");
        
        if (document.body.clientWidth <= 1024)
        {
            objAdDivRight.style.display = "none";
            objAdDivLeft.style.display = "none";
        }
        else
        {
            
            if (objAdDivLeft != null ){
                objAdDivLeft.style.display = "block";
            }
            if (objAdDivRight != null ){
                objAdDivRight.style.display = "block";
            }
            
            FloatTopDiv();
        }
    }catch(e){}
}

	
