<!--

function playVideo(videoURL, duration, width, height){

	var theFlashContainer = document.getElementById('flashvideoplayer');
	if(theFlashContainer == null){
		var theFlashDiv = document.createElement('div');
		theFlashDiv.id = "flashvideoplayer";
		var theContainer = document.getElementById('container');
		theContainer.appendChild(theFlashDiv);
		theFlashDiv.style.display = "none"; 
	}
	
	
	var mifso = new SWFObject("/flash/mainsite/HDVideoPlayer.swf","mainflash","586","480",9,"#3C3C39");
	mifso.addParam("align", "middle");
    mifso.addParam("menu", "false");
    mifso.addParam("scale", "noscale");
    mifso.addParam("wmode", "transparent");
	mifso.addVariable("videoUrl", videoURL);
	mifso.addVariable("videoWidth", width);
	mifso.addVariable("videoHeight", height);
	mifso.addVariable("videoDuration", duration);
    mifso.write("flashvideoplayer");
    tb_show("","#TB_inline?height=730&width=586&inlineId=flashvideoplayer","");
	$('#TB_closeAjaxWindow').hide();
	
	$('#TB_window').addClass('videoPlayer');
	document.getElementById('TB_window').style.marginTop = "0";
	$("html").css("overflow","auto");	
	
	// 5-19-2009 fix for IE6 positioning bug
	document.getElementById('TB_window').style.top = "84px";
	
}

function removeVideo() {
	tb_remove();
}

var movieplayer_loaded = false;

$(document).ready(function() {
	$(function(){
		/* $("[rel='pdf']").click(function(event){
			var pdffilename = $(this).attr("href");
			popUp("/pdf_detect.html?pdfdoc=" + pdffilename,"800","600");
			event.preventDefault();
		}); */
		$("[rel='pdf']").addClass("pdfLink");
		$("[rel='pdf']").attr("target","_blank");
	});
});

function showMovie(arg1, arg2, arg3, arg4) {
  if (movieplayer_loaded) {
    moviePlayerAppear(arg1, arg2, arg3, arg4);
  } else {
    window.location.href = window.location.href;
  }
}

function checkIfSafari3_1() {
  n = navigator;
  nua = n.userAgent;
  if (nua.indexOf('Version/3.1') != -1 && nua.indexOf('Safari') != -1) return true;
  else return false;
}

safari_3_1_mac_popup_block_msg = 'You are using Safari 3.1 and it has blocked our Pop-Up Window.\nTo view the Pop-Up Window:\n1) disable your Pop-Up blocker by going into the Safari menu in your browser\'s menu bar and unselecting the Block Pop-Up Windows option\n2) then click on the link again';
safari_3_1_win_popup_block_msg = 'You are using Safari 3.1 and it has blocked our Pop-Up Window.\nTo view the Pop-Up Window:\n1) disable your Pop-Up blocker by going into the Edit menu in your browser\'s menu bar and unselecting the Block Pop-Up Windows option\n2) then click on the link again';

function closePopup(){
	window.close();
}

function popUpPDF(pdffilename,width,height) {
	//popUp("/pdf_detect.html?pdfdoc=" + pdffilename,width,height);
	popUp(pdffilename,width,height);
}

function popUpPDFNoScrollReturnStatus(pdffilename,width,height) {
	//return popUpReturnStatus("/pdf_detect.html?pdfdoc=" + pdffilename,width,height);
	return popUpReturnStatus(pdffilename,width,height);
}

function popUp(filename,width,height) {
	popup=window.open(filename,"popup","height="+height+",width="+width+",resizable=yes,status=no,toolbar=no,directories=no,menubar=no,scrollbars=yes,location=no");
}

function popUpNoScroll(filename,width,height) {
	popup2=window.open(filename,"popup2","height="+height+",width="+width+",resizable=yes,status=no,toolbar=no,directories=no,menubar=no,scrollbars=no,location=no");
}

function popUpNormal(filename,width,height) {
	if (width != null && height != null && width > 1 && height > 1) {
		popup3=window.open(filename,"popup3","height="+height+",width="+width);
	} else {
		popup3=window.open(filename,"popup3");
	}
}

function popUpReturnStatus(filename,width,height) {
	//alert("filename: "+filename+" w:" +width+" h:"+height);
	popup=window.open(filename,"popup","height="+height+",width="+width+",resizable=yes,status=no,toolbar=no,directories=no,menubar=no,scrollbars=yes,location=no");
	
	if (!popup) {
		if (checkIfSafari3_1()) {
			n = navigator;
			na = n.appVersion;
			if ( na.indexOf( 'Mac' ) != -1 ) {
				alert(safari_3_1_mac_popup_block_msg);
			} else {
				alert(safari_3_1_win_popup_block_msg);
			}
		}
		
		return false;
	}
	else {
		return true;
	}
}

function popUpNoScrollReturnStatus(filename,width,height) {
	popup2=window.open(filename,"popup2","height="+height+",width="+width+",resizable=yes,status=no,toolbar=no,directories=no,menubar=no,scrollbars=no,location=no");
	if (!popup2){
		if (checkIfSafari3_1()) {
			n = navigator;
			na = n.appVersion;
			if ( na.indexOf( 'Mac' ) != -1 ) {
				alert(safari_3_1_mac_popup_block_msg);
			} else {
				alert(safari_3_1_win_popup_block_msg);
			}
		}
		return false;
	}
	else return true;
}

function popUpNormalReturnStatus(filename,width,height) {
	if (width != null && height != null && width > 1 && height > 1) {
		popup3=window.open(filename,"popup3","height="+height+",width="+width);
	} else {
		popup3=window.open(filename,"popup3");
	}
	if (!popup3) {
		if (checkIfSafari3_1()) {
			n = navigator;
			na = n.appVersion;
			if ( na.indexOf( 'Mac' ) != -1 ) {
				alert(safari_3_1_mac_popup_block_msg);
			} else {
				alert(safari_3_1_win_popup_block_msg);
			}
		}
		return false;
	}
	else return true;
}

function emailPopUpNoScroll(filename,width,height) {
	var url = filename + "?r=";
	url += escape(document.URL);
	url += "&t=";
	url += escape(document.title);
	popUpNoScroll(url,width,height);
}

function glossaryTermPopUp(glossaryTerm) {
	var url = "glossary_popup.jsp?term=" + glossaryTerm;
	popUpNoScroll(url,600,300);
}

function ChangeImage() {
	if (document.images) {
		if (ChangeImage.arguments.length == 4)
			document[ChangeImage.arguments[0]].src = ChangeImage.arguments[3] + '/' + ChangeImage.arguments[1];
		else
			document[ChangeImage.arguments[0]].src = '/' + ChangeImage.arguments[1];
		}
	
	if (ChangeImage.arguments.length > 2)
		window.status=ChangeImage.arguments[2];
}

function ChangeImageEx() {
	if (document.images) {
		if (ChangeImageEx.arguments.length == 5)
			{
			if (document.layers) 
				document.layers[ChangeImageEx.arguments[0]].document[ChangeImageEx.arguments[1]].src = ChangeImageEx.arguments[4] + '/' + ChangeImageEx.arguments[2];
			else
				document[ChangeImageEx.arguments[1]].src = ChangeImageEx.arguments[4] + '/' + ChangeImageEx.arguments[2];

			if (ChangeImageEx.arguments.length > 2)
				window.status=ChangeImageEx.arguments[3];
			}				

		if (ChangeImageEx.arguments.length == 6)
			{
			if (document.layers) 
				document.layers[ChangeImageEx.arguments[0]].document.layers[ChangeImageEx.arguments[1]].document[ChangeImageEx.arguments[2]].src = ChangeImageEx.arguments[5] + '/' + ChangeImageEx.arguments[3];
			else
				document[ChangeImageEx.arguments[2]].src = ChangeImageEx.arguments[5] + '/' + ChangeImageEx.arguments[3];

			if (ChangeImageEx.arguments.length > 2)
				window.status=ChangeImageEx.arguments[4];
			}	
		}
	
}

function isMac()
{
	var platform = navigator.platform;
	if (platform.indexOf("Mac") >= 0) {
		return true;
	}
	else {
		return false;
	}
}

function isNetscape()
{
	var browser = navigator.appName;
	if (browser == "Netscape") {
		return true;
	}
	else {
		return false;
	}
}

function checkForReturn(activefield,e) {
  var keycode;
  if (window.event) keycode = window.event.keyCode;
  else if (e) keycode = e.which;
  else return true;
  
  if (keycode == 13) {
    if (activefield.form.onsubmit) {
      if (activefield.form.onsubmit()) {
        activefield.form.submit();
      }
    } else {
      activefield.form.submit();
    }
  }
  return true;
}

function isNS6()
{
	var version = parseInt(navigator.appVersion);
	if (isNetscape()){
		if (version >= 5) {
			return true;
		}
	}
	else {
		return false;
	}
}

function isIE()
{
	var browser = navigator.appName;
	if (browser == "Microsoft Internet Explorer") {
		return true;
	}
	else {
		return false;
	}
}


function getParm(string,parm,filter)
{
	// returns value of parm from string
	var retVal = "";
	
	// make sure we check there is a value to look for
	var endPos = string.indexOf("=");
	if (endPos == -1 || isNaN(parseInt(endPos)))
		return retVal;
	
	// make sure we check for the full parm name
	var startPos = string.indexOf("?" + parm + "=");
	if (startPos < 0)
		startPos = string.indexOf("&" + parm + "=");
	
	// Increment passed the parameter seperator
	startPos = startPos + 1;

	if (startPos > -1)
		{
	    startPos = startPos + parm.length + 1;
	    endPos = string.indexOf("&",startPos);
		if (endPos == -1)
		endPos = string.length;
		if (filter == true)
			{
			for (var i = startPos; i < endPos; i++)
				{
				if (string.charAt(i) == "+")
					retVal = retVal + " ";
				else
					retVal = retVal + string.charAt(i);
				}
			}
		else
			retVal = string.substring(startPos,endPos);
	    return unescape(retVal);
		}
	return retVal;
}

function nothing(){}


// **BEGIN DATA VALIDATION FUNCTIONS**
// JavaScript sees numbers with leading zeros as octal values, so strip zeros
function stripZeros(inputStr) {
	var result = inputStr;
	while (result.substring(0,1) == "0") {
		result = result.substring(1,result.length)
	}
	return result;
}

function IsNumeric(vVal)
{
	if (isNaN(vVal) || vVal==""){return false}
	else{return true}	
}

function IsValidEmail(vVal)
{
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(vVal))){return false}
	else{return true}	
}

function isValid(vVal) {
	if (!IsNumeric(vVal)) {
		alert("Please make sure entries are numbers only.");
		return false;
	}
	return true
}

function ShowMessage(sMessage, objField){
  	alert(sMessage)
   	objField.focus()
   	return;
}

function monthValid(inputStr) {
	inputStr = stripZeros(inputStr);
	if (!IsNumeric(inputStr)) {
		alert("Please make sure entries are numbers only.");
		return false;
	}
	if (parseInt(inputStr) < "1" || parseInt(inputStr) > "12") {
		alert("Please make sure the month is between 1 to 12.");
		return false;
	}
	return true;
}

function setAnswerList(formName, cookieName, destinationURL) {
var answerList = "";
var elementType = "";
  if (document.forms[formName]) {
	for (var i = 0; i < document.forms[formName].elements.length; i++) {
		elementType = document.forms[formName].elements[i].type;
		if (elementType == "checkbox" || elementType == "radio") {
			if (document.forms[formName].elements[i].checked) {
				if (document.forms[formName].elements[i].value > 0) 
					answerList = answerList + document.forms[formName].elements[i].value + ",";
			}
		}
	}
	// trim off trailing comma if necessary
	if (answerList.length > 1) {
		answerList = answerList.substr(0, answerList.length - 1);
		setCookie (cookieName, answerList);
		document.location.href = destinationURL+"?a="+answerList;
	} else {
		alert ("We're sorry.  You have made no choices.\nIf you indicate your preferences, we can help you select\nthe ideal Hunter Douglas products for your needs.");
	}
  }
}

function setFormState(formName,cookieName) {
var answerArray;
var answers = getCookie(cookieName);
  if (document.forms) {
  if (document.forms[formName]) {
	if (answers != null) {
		if (answers.length > 0) {
			answerArray = answers.split(",");
			for (var i = 0; i < answerArray.length; i++) {
				checkElementByValue(formName,answerArray[i]);
			}
		}
	}
  }
  }
}

function checkElementByValue(formName,answer) {
	for (var i = 0; i < document.forms[formName].elements.length; i++) {
		elementType = document.forms[formName].elements[i].type;
		if (elementType == "checkbox" || elementType == "radio") {
			if (document.forms[formName].elements[i].value == answer) {
				document.forms[formName].elements[i].checked = true;
			}
		}
	}
}

function processCompareForm() {
  var formName = "comparisonForm";
  var cookieName = "Comparison";
  var destinationURL = "product_comparison.jsp";
  var answerArray = new Array();
  var answers = getCookie(cookieName);
  var elementType;
  var answerList = "";
  var addValue;
  var numAnswers;
  if (answers != null) {
    if (answers.length > 0) {
      answerArray = answers.split(",");
    }
  }
  var savedAnswers = answerArray.length;
  if (document.forms[formName]) {
    for (var i = 0; i < document.forms[formName].elements.length; i++) {
      elementType = document.forms[formName].elements[i].type;
      if (elementType == "checkbox" || elementType == "radio" || elementType == "hidden") {
	if (elementType == "hidden" || document.forms[formName].elements[i].checked) {
	  addValue = true;
	  for (var j = 0; j < answerArray.length; j++) {
	    if (answerArray[j] == document.forms[formName].elements[i].value) 
	      addValue = false;
	  }  
	  if (addValue) {
	    answerArray[answerArray.length] = document.forms[formName].elements[i].value;
	  }
	} else {
	  // element is in form, and has been de-checked...
	  for (var j = 0; j < answerArray.length; j++) {
	    if (answerArray[j] == document.forms[formName].elements[i].value) 
	      answerArray[j] = 0;
	  }  
	}
      }
    }
    numAnswers = 0;
    for (var i = 0; i < answerArray.length; i++) {
      if (answerArray[i] > 0) {
	numAnswers++;
	answerList = answerList + answerArray[i] + ",";
      }
    }
    if (numAnswers > 4) {
      if (savedAnswers > 0) {
        alert("We're sorry but you have exceeded the number of products possible for comparison.\nYou already have "+savedAnswers+" products in My Product Comparison, and your selections bring the total to "+numAnswers+".\nYou may only compare up to four total products.");
      } else {
        alert("We're sorry but you have exceeded the number of products possible for comparison.\nPlease limit your selection to between two and four products then select Compare.");
      }
    } else if (numAnswers == 0) {
      alert("You have not selected any products to compare.\nAfter adding between two and four products to your\ncomparison list, you can view your results.");
    } else {
      // trim off trailing comma if necessary
      if (answerList.length > 1) {
	answerList = answerList.substr(0, answerList.length - 1);
	setCookie (cookieName, answerList);
	document.location.href = destinationURL+"?a="+answerList;
      }
    }
  }
}

function removeComparison(id) {
  var cookieName = "Comparison";
  var answers = getCookie(cookieName);
  var answerArray = new Array();
  var destinationURL = "product_comparison.jsp";
  var answerList = "";
  var numAnswers = 0;
  if (answers != null) {
    if (answers.length > 0) {
      answerArray = answers.split(",");
    }
  }
  for (var i = 0; i < answerArray.length; i++) {
    if (answerArray[i] != id) {
      numAnswers++;
      answerList = answerList + answerArray[i] + ",";
    }
  }
  if (answerList.length > 1) {
    answerList = answerList.substr(0, answerList.length - 1);
    setCookie (cookieName, answerList);
    document.location.href = destinationURL+"?a="+answerList;
  } else {
    setCookie (cookieName,'');
    document.location.href = "index.jsp";
  }
}

function fixCookieDate (date)
{
var base = new Date(0);
var skew = base.getTime(); 
if (skew > 0)  
	date.setTime (date.getTime() - skew);
}

function setCookie (name,value,expires,path,domain,secure)
{
document.cookie = name + "=" + escape (value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
}

function getCookieVal (offset)
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
   	endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function getCookie (name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
	{
	var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
    	return getCookieVal (j);
	i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0)
		break; 
	}
return null;
}

function deleteCookie (name,path,domain)
{
if (getCookie(name))
	{
   	document.cookie = name + "=" +
	   	((path) ? "; path=" + path : "") +
   		((domain) ? "; domain=" + domain : "") +
	   	"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function setWorkbook (id) {
	var date = new Date();
	fixCookieDate (date);
	date.setFullYear("2020");
	setCookie ("HD_Workbook",id,date);
}

function setLastProductID(id) {
	var date = new Date();
	fixCookieDate (date);
	date.setFullYear("2020");
	setCookie("HDLastProductID",id,date);
}


function riaTrack(eventName, eventType, eventId) {
// NOTE: used for Rich Internet Application Tracking - FlashTrackAction and AJAX Track
  dcsMultiTrack('DCSext.eventname', eventName, 'DCSext.eventtype', eventType, 'DCSext.eventid', eventId);
  if (window.location.pathname == '/our-products-detail.jsp') {
    var id = 0;
    var qs = window.location.search;
    var qsarr = qs.split('&');
    for (var i=0; i<qsarr.length; i++) {
      arg = qsarr[i].split('=',2);
      if (arg[0] == 'id' || arg[0] == '?id') id=arg[1];
    }
    // alert("Path - "+window.location.pathname+"\nid - "+id+"\nEvent Name - "+eventName+"\nEvent Type - "+eventType);
    if (id != 0 && id != 53 && id != 6 && id != 1 && id != 4 && id != 50 && id != 51 && id != 3) {
      if (eventName == 'VideoPlayerEvent' && eventType == 'VideoEnd') {
        baitWait("WWW=ProductVideoEnd",id);
	setBaitS();
      }
      if (eventName == 'ProductDetailPrintButtonClick') {
        baitWait("WWW=ProductDetailPrint",id);
	setBaitS();
      }
    }

  }
}
function legacyFlashTrack(trackerinfo) {
// NOTE: used for iMagine and Alustra Collection Microsite that previously used /tracker.jsp
  dcsMultiTrack('DCS.dcsuri','/tracker.jsp','DCS.dcsqry',trackerinfo); 
  var id=0;
  var act='';
  var qsarr = trackerinfo.split('&');
  for (var i=0; i<qsarr.length; i++) {
    arg = qsarr[i].split('=',2);
    if (arg[0] == 'product_id') {
      id=arg[1];
      // alert("arg[0] - "+arg[0]+"\narg[1] - "+arg[1]);
    }
    if (arg[0] == 'action_completed') {
      act=arg[1];
      // alert("arg[0] - "+arg[0]+"\narg[1] - "+arg[1]);
    }
  }
  if (act == 'clicked_swatch') {
    if (id != 0 && id != 53 && id != 6 && id != 1 && id != 4 && id != 50 && id != 51 && id != 3) {
      baitWait("WWW=iMagineProduct",id);
      setBaitS();
    }
  }
}


function supRegTrade(copy) {
  if (copy != null) {
    var re = /&reg;/g;
    var re2 = /&#174;/g;
    copy = copy.replace(re,"<sup>&reg;</sup>");
    copy = copy.replace(re2,"<sup>&reg;</sup>");
    return copy;
  }
  return null;
}

var expdate = new Date ();
fixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000)); // 24 hrs from now 
