
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Sandeep Gangadharan | http://www.sivamdesign.com/scripts/ */

var exp = 5;

function newCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  } else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameSG = name + "=";
  var nuller = '';
  if (document.cookie.indexOf(nameSG) == -1)
  return nuller;
  var ca = document.cookie.split(';');
  for(var i=0; i<ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameSG) == 0) return c.substring(nameSG.length,c.length);
  }
  return null;
}

function eraseCookie(name) {
  newCookie(name,"",-1);
}

if (document.getElementById) {
  document.writeln('<style type="text/css">')
  document.writeln('.main {text-decoration:none; color:blue; cursor:hand; cursor:pointer}')
  document.writeln('span:hover.mainLink {text-decoration:underline; color:red}')
  document.writeln('.sublinks1 {display:none; padding-left:14px}')
  document.writeln('.link2 {text-decoration:none; color:blue}')
  document.writeln('a:hover.link2 {text-decoration:underline; color:red}')
  document.writeln('</style>') }

    // Below you should add a1, a2 etc. for each main link you wish to include
    // so if you want 3 main links you should add a1, a2, a3 in the format shown
    // enclosed in double quotes
  var mainNum = new Array("a1","a2","a3");

    // Below you should add b1, b2 etc. for each sub link you wish to include
    // under one main link, here the first main link. so if you want 4 sub links you
    // should add b1, b2, b3, b4 in the format shown enclosed in double quotes
  var subNum1 = new Array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40");

    // Below, this is for sub links under the second main link. there are 3 sub links
    // in the given example
  var subNum2 = new Array("a1","a2","a3","a4","a5","a6","a7","a8","a9","a10","a11","a12","a13","a14","a15","a16","a17","a18","a19","a20","a21","a22","a23","a24","a25","a26","a27","a28","a29","a30","a31","a32","a33","a34","a35","a36","a37","a38","a39","a40");

  var subNum3 = new Array("b1","b2","b3","b4","b5","b6","b7","b8","b9","b10","b11","b12","b13","b14","b15","b16","b17","b18","b19","b20","b21","b22","b23","b24","b25","b26","b27","b28","b29","b30","b31","b32","b33","b34","b35","b36","b37","b38","b39","b40");

 

function openClose(theName, menuArray, theID) {

  for(var i=0; i < menuArray.length; i++) {
    if (menuArray[i] == theID) {
      if (document.getElementById(theID).style.display == "block") {
        document.getElementById(theID).style.display = "none";
        document.getElementById("tick_"+menuArray[i]).innerHTML = "<img src ='templates/images/u.gif' border ='0'/>";
        eraseCookie(theName); }
      else {
        document.getElementById(theID).style.display = "block";
        document.getElementById("tick_"+menuArray[i]).innerHTML = "<img src ='templates/images/d.gif' border ='0'/>";
        newCookie(theName,menuArray[i],exp); }
      }
    else {
      document.getElementById(menuArray[i]).style.display = "none";
      document.getElementById("tick_"+menuArray[i]).innerHTML = "<img src ='templates/images/u.gif' border ='0'/>";
    }
  }
}
function openClose1(theName, menuArray, theID) {

  for(var i=0; i < menuArray.length; i++) {
    if (menuArray[i] == theID) {
      if (document.getElementById(theID).style.display == "block") {
        document.getElementById(theID).style.display = "none";
        document.getElementById("tick_"+menuArray[i]).innerHTML = "<img src ='templates/images/u.gif' border ='0'/>";
        eraseCookie(theName); }
      else {
        document.getElementById(theID).style.display = "block";
        document.getElementById("tick_"+menuArray[i]).innerHTML = "<img src ='templates/images/d.gif' border ='0'/>";
        newCookie(theName,menuArray[i],exp); }
      }
    else {
      document.getElementById(menuArray[i]).style.display = "none";
      document.getElementById("tick_"+menuArray[i]).innerHTML = "<img src ='templates/images/u.gif' border ='0'/>";
    }
  }
}

function openClose2(theName, menuArray, theID) {
  for(var i=0; i < menuArray.length; i++) {
    if (menuArray[i] == theID) {
      if (document.getElementById(theID).style.display == "block") {
        document.getElementById(theID).style.display = "none";
        document.getElementById("tick_"+menuArray[i]).innerHTML = "<img src ='templates/images/u.gif' border ='0'/>";
        eraseCookie(theName);
		}
      else {
        document.getElementById(theID).style.display = "block";
        document.getElementById("tick_"+menuArray[i]).innerHTML = "<img src ='templates/images/d.gif' border ='0'/>";
        newCookie(theName,menuArray[i],exp); }
      }
    else {
		try{
			document.getElementById(menuArray[i]).style.display = "none";
			document.getElementById("tick_"+menuArray[i]).innerHTML = "<img src ='templates/images/u.gif' border ='0'/>";
		}catch(e){
		}
    }
  }
}

function memStatus() {
  var num = readCookie("MN");
  if (num) {
    document.getElementById(num).style.display = "block";
    document.getElementById("tick_"+num).innerHTML = "<img src ='templates/images/d.gif' border ='0'/>"; }
  var num1 = readCookie("SB");
  var num2 = readCookie("SB1");
  var num3 = readCookie("SB2");
  if (num1) {
    document.getElementById(num1).style.display = "block";
    document.getElementById("tick_"+num1).innerHTML = "<img src ='templates/images/d.gif' border ='0'/>"; }
	if (num2) {
    document.getElementById(num2).style.display = "block";
    document.getElementById("tick1_a"+num2).innerHTML = "<img src ='templates/images/d.gif' border ='0'/>"; }

	if (num3) {
    document.getElementById(num3).style.display = "block";
    document.getElementById("tick1_b"+num3).innerHTML = "<img src ='templates/images/d.gif' border ='0'/>"; }
}
// Multiple onload function created by: Simon Willison
// http://simonwillison.net/2004/May/26/addLoadEvent/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
  memStatus();
});



function openNewWindow(url, width, height){
	    var nLeft = (window.screen.width - width)/2;
	    var nTop = (window.screen.height - height)/2;
	    var properties = "width=" + width
	                     + ",height=" + height 
	                     + ",top="+ nTop
	                     + ",left=" + nLeft 
	                     + ",titlebar=no,status=yes,menubar=no,toolbar=no,scrollbars=yes,resizable=no,location=no,title='Thiet bi ve sinh...'";
		var newName = "newWin"; // + suffix;
		var win = window.open(url, newName , properties, true);	
		win.focus();    
	    return;
}


function doSearch(){
  document.searchProduct.submit();
}
