// JavaScript Document
function clickIE4() {
	if (event.button==2){
		return false;
	}
}

function clickNS4(e) {
	if (document.layers||document.getElementById&&!document.all){
		if (e.which==2||e.which==3){
		return false;
		}
	}
}

function OpenTV(URL) {
	// Vars
	var Width = 550;
	var Height = 515;
	//Center the Window
	var left = ((screen.width - Width) / 2) - 150;
	var top = ((screen.height - Height) / 2) - 50;
	//Set the Params
	var params = 'toolbar=0, scrollbars=0, location=0, statusbar=0, menubar=0, resizable=1, width='+Width+', height='+Height+', left='+left+', top = '+top+'';
	//Pop the Window
	WinName = window.open(URL, 'TVViewer', params);
	WinName.focus();
}

function PopUp(Width,Height,Scrolling,URL) {
	//Center the Window
	var left = (screen.width - Width) / 2;
	var top = (screen.height - Height) / 2;
	//Set the Params
	var params = 'toolbar=0, scrollbars='+Scrolling+', location=0, statusbar=0, menubar=0, resizable=1, width='+Width+', height='+Height+', left='+left+', top = '+top+'';
	//Pop the Window
	WinName = window.open(URL, 'Preview', params);
	WinName.focus();
}

function JumpToURL(URL) {
	window.self.location = URL;
}

function UpdateTextCounter(elem, max) {
	var counter = document.getElementById(elem.id + "_counter");
	var remaining = document.getElementById(elem.id + "_remaining");
	if(elem.value.length > max) {
		elem.value = elem.value.substring(0, max);
	}
	if(counter != null) {
		counter.innerHTML = elem.value.length;
	}
	if(remaining != null) {
		remaining.innerHTML = max - elem.value.length;
	}
}

function setLyr(obj,lyr) {
	var newX = (findPosX(obj)-150);
	var newY = (findPosY(obj)-10);
	var layerwidth = 150;
	if (lyr == 'testP') { 
		newY -= 50;
	}
	var x = lyr;
	if (navigator.appName == 'Microsoft Internet Explorer') {
		newY = newY+14;
		newX = newX+10;
	}
	if (newY > 425) {
		
	}
	//
	if (document.layers) {
        layerwidth = x.document.width;
	}
    else if (document.all) {
        layerwidth = x.clientWidth;
	}
	//
	x.style.top = (newY-10) + 'px';
	x.style.left = (newX-150) + 'px';
	}

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x) {
		curleft += obj.x;
	}
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y) {
		curtop += obj.y;
	}
	return curtop;
}

function DisplayWeatherHint(theField,Init) {
	if (Init == 'OnLoad') {
		if ((theField.value.length == 0) || (theField.value == 'Enter Zip Code')){
			theField.style.color = '#CCCCCC';
			theField.value = 'Enter Zip Code';
		}
		else {
			theField.style.color = '#FFFFFF';
		}
	}
	else {
		if (theField.value.length == 0) {
			theField.style.color = '#CCCCCC';
			theField.value = 'Enter Zip Code';
		}
		else if (theField.value == 'Enter Zip Code') {
			theField.style.color = '#FFFFFF';
			theField.value = '';
		}
		else {
			theField.style.color = '#FFFFFF';
		}
	}
}

function ShowZipField() {
	document.getElementById('ZipCode').style.color = '#CCCCCC';	
	document.getElementById('EnterZip').style.display = '';	
}

function ShowHintText(theField,theHint,activeColor) {
	if (theField.value.length == 0) {
		theField.style.color = '#CCCCCC';
		theField.value = theHint;
	}
	else if (theField.value == theHint) {
		theField.style.color = activeColor;
		theField.value = '';
	}
}

// *********
function Validate() {
	var SpecialOption = 'NA';
	var KitCount = document.getElementById('KitCompCount').value;
	document.getElementById('ValidateMsg').style.display = 'none';
	//ResetMessages('Options',OptCount);
	ResetMessages('Kits',KitCount);
	
	// Set Special Options
	if (document.getElementById('SpecialOptions')) {
		SpecialOption = document.getElementById('SpecialOptions').value;
	}
	
	// Validate Options
	for (i=0; i<1; i++) {
		if (document.getElementById('Options') != null) {
			OptionField = document.getElementById('Options');
			OptionValue = OptionField.options[OptionField.selectedIndex].value;
			ValidateMessage = document.getElementById('ValidateMsg');
		}else{
			ValidateMessage = document.getElementById('ValidateSpecialMsg');
			OptionValue = 'NA';
		}
		if ((OptionValue == 'NA') && (SpecialOption == 'NA')) {
		ValidateMessage.style.display = '';
		return false;
		}
	}

	// Validate Kits
	for (i=0; i<KitCount; i++) {
		KitField = document.getElementById('kitComp' + i);
		KitValue = KitField.options[KitField.selectedIndex].value;
		ValidateMessage = document.getElementById('ValidateKitMsg' + i);
		if (KitValue == 'NA') {
		ValidateMessage.style.display = '';
		return false;
		}
	}
	return true;
}
function ResetMessages(Type,Count) {
	if (Type == 'Options') {
		for (i=0; i<Count; i++) {
			if (document.getElementById('ValidateMsg' + i) != null) {
				document.getElementById('ValidateMsg' + i).style.display = 'none';
			}	
		}
	}
	else if (Type == 'Kits') {
		for (i=0; i<Count; i++) {
			document.getElementById('ValidateKitMsg' + i).style.display = 'none';
		}
	}
}
function OpenViewer() {
	// Vars
	var Width = 430;
	var Height = 465;
	var URL = '';
	//Center the Window
	var left = ((screen.width - Width) / 2) - 150;
	var top = (screen.height - Height) / 2;
	//Set the Params
	var params = 'toolbar=0, scrollbars=0, location=0, statusbar=0, menubar=0, resizable=1, width='+Width+', height='+Height+', left='+left+', top = '+top+'';
	//Pop the Window
	WinName = window.open(URL, 'ZoomViewer', params);
	WinName.focus();
}

function OpenChart(ChartID) {
	// Vars
	var Width = 475;
	var Height = 425;
	var URL = '/store/viewchart.cfm?ChartID=' + ChartID;
	var left = screen.width - Width;
	var top = 0;
	//Set the Params
	var params = 'toolbar=0, scrollbars=1, location=0, statusbar=0, menubar=0, resizable=1, width='+Width+', height='+Height+', left='+left+', top = '+top+'';
	//Pop the Window
	WinName = window.open(URL, 'ChartViewer', params);
	WinName.focus();
}

function ShowBestSellerOpts(InitField,TargetOption) {
	// Set Vars
	var TargetField = document.getElementById('Option' + TargetOption);
	var OptionCount = document.getElementById('OptCount').value;
	
	// Reset all forward fields
	for (i=TargetOption; i<OptionCount; i++) {
		CurrentField = document.getElementById('Option' + i);
		CurrentField.selectedIndex = 0;
		for (n=0; n<CurrentField.length; n++) {
			CurrentField.options[n].style.color = '';
		}
	}
	
	// Check if this option has an array
	ArrayFound = false;
	for (i=0; i<ArrayNames.length; i++) {
		if (ArrayNames[i] == InitField.options[InitField.selectedIndex].value) {
			ArrayFound = true;
			break;
		}
	}
	if (!ArrayFound) {
		return;
	}
	
	// Set array name
	var OptionArray = eval('Arr_' + InitField.options[InitField.selectedIndex].value + '_' + TargetOption);
	
	// Highlight Options
	if ((TargetField) && (OptionArray)) {
		for (i=0; i<TargetField.length; i++) {
			for (a=0; a<OptionArray.length; a++) {
				if (TargetField.options[i].value == OptionArray[a]) {
					TargetField.options[i].style.color = '#FF0000';
				}
			}
		}
	}
}
/*
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}
*/
function AC_AddExtension(src, ext)
{
	// Only add extension if it's not already there
	if(src.indexOf(ext) == -1) {
		if (src.indexOf('?') != -1) {
			return src.replace(/\?/, ext+'?'); 
		} else {
			return src + ext;
		}
	} else {
		return src;
	}
}
function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}
