var brandImages = new Array();
var currentBrand = "";
var brandImageCounter = 0;
var timer, imageCount = 2;

function doJavascriptLinks() {
  if (!document.getElementsByTagName) return false;
  if(document.getElementById('tools')){
	var newul = document.createElement('ul');
   	newul.innerHTML='<li><a href=../untitled/webwordwizards - Contact us_files//"#/" class=\"print\">Print</a></li><li class=\"noBg\"><a href=\"#\" onclick=\"window.open(\'send_page_link_popup.asp?subject=Link+to+webwordwizards&link=\' + escape(this.href.replace(\'#\',\'\')), \'linkWindow\', \'width=300,height=500\');\" title=\"Send this page\">Email</a></li>';
   	document.getElementById('tools').appendChild(newul);
  }
}

function doPopups() {
  if (!document.getElementsByTagName) return false;
  var links = document.getElementsByTagName("a");
  for (var i=0; i < links.length; i++) {
    if (links[i].className.match("print")) {
      links[i].onclick = function() {
        window.print(this.href);
        return false;
      }
    }
  }
}

function PrintPopups() {
  if (!document.getElementsByTagName) return false;
  var links = document.getElementsByTagName("a");
  for (var i=0; i < links.length; i++) {
    if (links[i].className.match("printPopup")) {
      links[i].onclick = function() {
	  newwindow=window.open(this.href,'name','width=650, scrollbars=yes');
	 if (window.focus) {newwindow.focus()}
        return false;
      }
    }
  }
}

function radio() {
  if (!document.getElementsByTagName) return false;
  var links = document.getElementsByTagName("input");
  for (var i=0; i < links.length; i++) {
    if (links[i].name.match("reason")) {
      links[i].onclick = function() {
        contact(this.id);
      }
    }
  }
}

function contact(objId) {
	if(document.getElementById('brochure_request') && document.getElementById('query')){	
		if (document.getElementById('brochure_request').checked) {
			document.getElementById('brochure').style.display="block";
			//document.getElementById('source').style.display="block";
			document.getElementById('marketing').style.display="block";
			document.getElementById('query').style.display="none";

   			document.getElementById('brochure_order').value = 'true';
   			document.getElementById('reason_id').value = 'brochure_request';
	        
			return false;
		}
		else{
			document.getElementById('brochure').style.display="none";
			//document.getElementById('source').style.display="none";
			document.getElementById('marketing').style.display="none";		
			document.getElementById('query').style.display="block";

   			document.getElementById('brochure_order').value = 'false';
   			document.getElementById('reason_id').value = objId;

		} 

	}	 
}

function initBrandChanger() {
	var el = document.getElementById("brand-wrapper");
	if (!el) return;
	var li = el.getElementsByTagName("li");
	
	for (var i=0; i < li.length; i++) {
		li[i].onclick = function () {
			setBrand(this);
			return false;
		};
		
		if (li[i].className == "current")
			setBrand(li[i]);
	}
}

function setBrand(el) {
	var li = el.parentNode.getElementsByTagName("li");
	var img = document.getElementById("brand-img");
	var txt = document.getElementById("brand-txt");
	var link = el.getElementsByTagName("a")[0]
	var anchor = link.getAttribute("href", 1);
	currentBrand = anchor.substring(anchor.indexOf("#")+1, anchor.length);


	if (!brandImages[currentBrand]) return;

	for (var i=0; i < li.length; i++)
		li[i].className = (li[i].id == el.id) ? "current" : "";

	txt.src = brandImages[currentBrand + "-txt"][0];
	txt.parentNode.href = brandImages[currentBrand + "-txt"][1];
	
	img.src = brandImages[currentBrand][0];

	if (timer)
		window.clearInterval(timer);

	timer = window.setInterval(changeBrandImage, 5000);
}

function changeBrandImage() {
	var el = document.getElementById("brand-img");
	if (!el) return;

	var src = el.src;

	for (var i=0; i < brandImages[currentBrand].length; i++) {
		if (i+1 >= brandImages[currentBrand].length) {
			i = 0; 
			break;
		}
		else if (src.indexOf(brandImages[currentBrand][i]) > -1) {
			i++;
			break;
		}
	}
	
	el.src = brandImages[currentBrand][i];
}

	
window.onload = function() {
		initBrandChanger();
		doJavascriptLinks();
		doPopups();
		contact();
		radio();
		PrintPopups();
}

function openNewWindow(sUrl, iW, iH, bD){
	var sP = "height="+ iH +",innerHeight="+ iH +",width="+ iW +",innerWidth="+ iW;
	if (window.screen) {
		var iY = ((screen.availHeight) - iW) / 2;
		var iX = ((screen.availWidth) - iH) / 2;
		sP += ",left="+ iX +",screenX="+ iX +",top=" + iY+ ",screenY="+ iY;
	}
	if(bD == true) 
		sP += ",menubar=0,location=0,resizable=1,scrollbars=1,status=0";
	else
		sP += ",menubar=0,location=0,resizable=1,scrollbars=0,status=0";
		
	window.open(sUrl, "PopUpWindow", sP);
}

function ChangeAction()
{
	if(document.getElementById('searchForm').searchradio[1].checked)
		document.getElementById('searchForm').action = '/actions/SearchPages.asp';
}


