
// SEARCH FUNCTIONS START //

function ClearSearch ( element ) {
  if ( element.value=="Search News" ){
    element.value = "";
  }
}

function ValidateSearch (form) {

  if ( form.q.value=="Search News" || form.q.value=="" ) {
    alert("Please enter your keywords");
    form.q.focus();
    return false;
  }
  return true;

}

// SEARCH FUNCTIONS END //


// MENU FUNCTIONS START //

function InitCatMenu () {
	var els = document.getElementById("menu").getElementsByTagName("A");
	for ( var i=0; i < els.length; i++ ) {
		if ( els[i].id ) {
			document.getElementById(els[i].id).onmouseover = function () { ShowCats(this); };
			document.getElementById(els[i].id).onmouseout  = function () { HideCats(); };
		}
	}
}

function ShowCats ( obj ) {
  curObj = obj;
  curObj.className = "on";
  var cat = obj.id;
  var curleft = curtop = 0;
  if ( obj.offsetParent ) {
    curleft = obj.offsetLeft;
    curtop  = obj.offsetTop;
    while ( obj = obj.offsetParent ) {
      curleft += obj.offsetLeft;
      curtop  += obj.offsetTop;
    }
  }
  var j = 0;
  var html = "";
  for ( i = 0; i < Cats.length; i++ ) {
    if ( Cats[i].parent == cat ) {
      html += '<a href="/news/category/' + Cats[i].url + '">' + Cats[i].name + '</a>';
      j++;
    }
  }
  if ( html ) {
    smenu.innerHTML = html;
    smenu.style.display = "block";
    smenu.style.left    = curleft + "px";
    smenu.style.top     = curtop + 28 + "px";
  }
}

function CatsVisible () {
  curObj.className = "on";
  smenu.style.display = "block";
}

function HideCats () {
  smenu.style.display = "none";
  curObj.className = "";
}

function Cat (Parent,Name,URL) {
  this.parent = Parent;
  this.name   = Name;
  this.url    = URL;
}

var Cats = [
new Cat("ch2","Manufacturers","company-profiles/manufacturers"),
new Cat("ch2","Retailers","company-profiles/retailers"),
new Cat("ch2","Wholesalers","company-profiles/wholesalers"),
new Cat("ch3","Auctions","wholesale/auctions"),
new Cat("ch3","Business Services","wholesale/business-services"),
new Cat("ch3","ChinaMart","wholesale/chinamart"),
new Cat("ch3","Closeouts","wholesale/closeouts"),
new Cat("ch3","Dollar Stores","wholesale/dollar-stores"),
new Cat("ch3","Flea Markets &amp; Swap Meets","wholesale/flea-markets-swap-meets"),
new Cat("ch3","Liquidations &amp; Returns","wholesale/liquidations-returns"),
new Cat("ch3","Wholesale News","wholesale/wholesale-news"),
new Cat("ch4","Apparel","product-news/apparel"),
new Cat("ch4","Electronics","product-news/electronics"),
new Cat("ch4","Fashion","product-news/fashion"),
new Cat("ch4","Handbags","product-news/handbags"),
new Cat("ch4","Jewelry","product-news/jewlery"),
new Cat("ch4","New Products","product-news/new-products"),
new Cat("ch4","Novelties","product-news/novelties"),
new Cat("ch4","Toys","product-news/toys"),
new Cat("ch5","ASD","trade-shows/asd"),
new Cat("ch5","National Hardware Show","trade-shows/national-hardware-show"),
new Cat("ch5","Offprice","trade-shows/offprice"),
new Cat("ch5","Trade Show Expertise","trade-shows/trade-show-expertise"),
new Cat("ch6","Avoiding Scams","marketing/avoiding-scams"),
new Cat("ch6","B2B Marketing Tips","marketing/b2b-marketing-tips"),
new Cat("ch6","E-Commerce","marketing/e-commerce"),
new Cat("ch6","Merchandising","marketing/merchandising"),
new Cat("ch6","Mobile Marketing","marketing/mobile-marketing"),
new Cat("ch6","SEO &amp; SEM","marketing/seo-sem"),
new Cat("ch6","Social Media","marketing/social-media"),
new Cat("ch6","Videos","marketing/videos"),
new Cat("ch6","Web Design","marketing/web-design"),
new Cat("ch7","Dropshipping","business/dropshipping"),
new Cat("ch7","Finance","business/finance"),
new Cat("ch7","Government &amp; Legal","business/government-legal"),
new Cat("ch7","Import &amp; Export","business/import-export"),
new Cat("ch7","Product Disputes","business/product-disputes"),
new Cat("ch7","Small Business","business/small-business"),
new Cat("ch7","Sourcing Tips","business/sourcing-tips"),
new Cat("ch7","Technology","business/technology"),
new Cat("ch8","China","asia/china"),
new Cat("ch8","India","asia/india")
];

// MENU FUNCTIONS END //


// AJAX LOADER START //

function Load (container, url) {
  var xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null) { return; }
  xmlHttp.onreadystatechange = function () {
    if (xmlHttp.readyState==4) {
      document.getElementById(container).innerHTML=xmlHttp.responseText;
    }
  }
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

// AJAX LOADER END //


// XMLHTTP OBJECT START //

function GetXmlHttpObject() {
  var xmlHttp=null;
  try
    {
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}

// XMLHTTP OBJECT END //


// ONLOAD FUNCTIONS START //

var smenu, curObj;

window.onload = function () {
	smenu = document.getElementById("smenu");
	smenu.onmouseover = function () { CatsVisible(); };
	smenu.onmouseout  = function () { HideCats(); };
	InitCatMenu();
};

// ONLOAD FUNCTIONS END //


