var mediaArray = new Array();
var submitcount = 0;
var previous_img;

function popWin(URL, Width, Height, Resizable, Scrollbars, Status, Toolbar) {

	if ((Width == null) || (Width == "")) { Width = 570; }
	if ((Height == null) || (Height == "")) { Height = 340; }
	if ((Resizable == null) || (Resizable == "")) { Resizable = "no"; }
	if ((Scrollbars == null) || (Scrollbars == "")) { Scrollbars = "no"; }
	if ((Status == null) || (Status == "")) { Status = "no"; }
	if ((Toolbar == null) || (Toolbar == "")) { Toolbar = "no"; }
	
	var positionX = (screen.availWidth - Width) / 2;
	var positionY = (screen.availHeight - Height) / 2;

	Day = new Date();
	WindowName = Day.getTime();

	window.open(URL,WindowName,"width=" + Width + ",height=" + Height + ",left=" + positionX + ",top=" + positionY + ",channelmode=0,dependent=0,directories=0,location=0,menubar=0,resizable=" + Resizable + ",scrollbars=" + Scrollbars + ",status=" + Status + ",toolbar=" + Toolbar);
}


function popTour(tourFile,tourWidth,tourHeight,tourDir) {

	var tourFile = tourFile.toLowerCase();

	if ((tourWidth == null) || (tourWidth == "")) { tourWidth = 770; }
	if ((tourHeight == null) || (tourHeight == "")) { tourHeight = 510; }
	if ((tourDir == null) || (tourDir == "")) { tourDir = "/tour/quickbooks/2006/"; }

	/* Non-Toolhouse tours that require the JHTML viewer, and other legacy tours */
	if ((tourFile == "customer_mgr_1") || (tourFile == "customer_mgr_2") || (tourFile == "customer_mgr_3") || (tourFile == "customer_mgr_4") ||	(tourFile == "41-cor-s3s") || (tourFile == "41-ole-f1s") || (tourFile == "41-ole-f3s") || (tourFile == "bs") || (tourFile == "ccs") || (tourFile == "pos")) {
		tourWindow = "/tour/popup_tour.jsp?tourFile="+tourFile;
		}

	/* New User Interview needs a special JHTML file to pass the priorityCode throughout the Flash file */
	else if (tourFile == "51-nui-t1") {
		tourWindow = "/tour/quickbooks/2005/51-nui-t1.jsp";
		}

	/* Non-standard new tour that requires its own file set */
	else if (tourFile == "qb_bs") {
		tourWindow = "/tour/quickbooks/2006/qb_bs/movies/qbbs.html";
		}

	/* Oddball legacy tour that requires its own file set */
	else {
		tourWindow = tourDir+tourFile+".html";
		}

	var positionX = (screen.availWidth - tourWidth) / 2;
	var positionY = (screen.availHeight - tourHeight) / 2;
    windowName = "QuickBooks_Tour_" + tourFile.replace (/-/g,"_");
	if (tourFile.length > 0) {
	  window.open(tourWindow, windowName,"width=" + tourWidth + ",height=" + tourHeight + ",left=" + positionX + ",top=" + positionY + ",directories=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no");
	}

}

function qbDSSGetSize () {
	if (screen.width > 1023) {
		window.open('http://web.intuit.com/tour/quickbooks/2006/retail/61-dss-t1.html','a',config='height=659,width=985, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');
	}
	else {
		window.open('http://web.intuit.com/tour/quickbooks/2006/retail/61-dss-t1b.html','b',config='height=540,width=790, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');
	}
}

function popSSStarbursts(URL) {

	var Width = 760;
	var Height = 420;
	var positionX = (screen.availWidth - Width) / 2;
	var positionY = (screen.availHeight - Height) / 2;

	Day = new Date();
	WindowName = Day.getTime();

	window.open(URL,WindowName,"width=" + Width + ",height=" + Height + ",left=" + positionX + ",top=" + positionY + ",channelmode=0,dependent=0,directories=0,location=1,menubar=1,resizable=1,scrollbars=1,status=1,toolbar=1");
}

function swapImageOff(imgName) {
	if (document.images) {
		document[imgName].src = eval(imgName + "_Off.src");
		document[imgName].src = previous_img;
		previous_img = "";
	}
}

function swapImageOn(imgName) {
	if (document.images) {
		previous_img = document[imgName].src;
		document[imgName].src = eval(imgName + "_On.src");
	}
}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function resetSubmitCount() {
	submitcount = 0;
}

// Stops Double Submit
function doubleSubmit() {

	if (submitcount == 0) {
		submitcount++;
		return true;
	}

	else {
		return false;
	}
}

function openPopUp(url, name, width, height)
{
	
	//first set the attributes of the popup window
	settings = "toolbar=no,location=no,directories=no,"+
	           "status=no,menubar=no,scrollbars=yes,"+
	           "resizable=yes,width="+width+",height="+
	           height+",left=250,top=150,screenX=250,screenY=10";
	var PopUp1 = window.open(url, name, settings); 
	
	//added following code to keep window active when clicking on the next link,
	//especially on the mydownloads page in estore.
	if (!PopUp1 || PopUp1.closed)
	{
		PopUp1 = window.open(url, name, settings);
	}
	else
	{
		PopUp1.focus();
	}
}

function openPopUp2(url, name, width, height)
{
	
	//first set the attributes of the popup window
	settings = "toolbar=1,location=1,directories=0,"+
	           "status=1,menubar=1,scrollbars=1,"+
	           "resizable=1,width="+width+",height="+
	           height+",left=250,top=10,screenX=250,screenY=10";
	var PopUp1 = window.open(url, name, settings); 
	
	//added following code to keep window active when clicking on the next link,
	//especially on the mydownloads page in estore.
	if (!PopUp1 || PopUp1.closed)
	{
		PopUp1 = window.open(url, name, settings);
	}
	else
	{
		PopUp1.focus();
	}
}

function openPopUp3(url, name, width, height)
{
	
	//first set the attributes of the popup window
	settings = "toolbar=no,location=no,directories=no,"+
	           "status=no,menubar=no,scrollbars=no,"+
	           "resizable=no,width="+width+",height="+
	           height+",left=250,top=10,screenX=250,screenY=10";
	var PopUp1 = window.open(url, name, settings); 
	
	//added following code to keep window active when clicking on the next link,
	//especially on the mydownloads page in estore.
	if (!PopUp1 || PopUp1.closed)
	{
		PopUp1 = window.open(url, name, settings);
	}
	else
	{
		PopUp1.focus();
	}
}

function DetectCookie(url,name,settings)
{
	// This Function is used as OnLoad on the Home Page to detect whether the User has turned Off the Cookies
	// This Function does not Submit any Form - It just Opens a Pop-Up Window
	if (navigator.appName.indexOf("Netscape") == -1 && navigator.appVersion.indexOf("MSIE 6.0") == -1) //Treat IE 6 like NN
	{
		 //IE
		if (navigator.cookieEnabled == false) 
		{
			var CookieError = window.open(url,name,settings);
		}
	}
	else 
	{
		//Netscape
	    setCookie('temp','temp');
		var temp = getCookie('temp');
		if (!temp) 
		{
			var CookieError = window.open(url,name,settings);
		}
	}
}



// Returns false if cookies not found
function DetectCookie(url,name,settings)
{
	// This Function is used as OnLoad on the Home Page to detect whether the User has turned Off the Cookies
	// This Function does not Submit any Form - It just Opens a Pop-Up Window
	if (navigator.appName.indexOf("Netscape") == -1 && navigator.appVersion.indexOf("MSIE 6.0") == -1) //Treat IE 6 like NN
	{
		//IE
		if (navigator.cookieEnabled == false) 
		{
			var CookieError = window.open(url,name,settings);
			return false;
		}
	}
	else if (navigator.appName.indexOf("Netscape") == -1)// IE 6
	{
		//Netscape
	        setIE6Cookie('temp','temp');
		var temp = getCookie('temp');
		if (!temp) 
		{
			var CookieError = window.open(url,name,settings);
			return false;
		}
	}
	else 
	{
		//Netscape+Firefox
	    setCookie('temp','temp');
		var temp = getCookie('temp');
		if (!temp) 
		{
			var CookieError = window.open(url,name,settings);
			return false;
		}
	}

	return true;
}


function setIE6Cookie(name, value) 
{
	var expireDate = new Date();
	expireDate.setYear(expireDate.getFullYear() + 1);
	value = escape(value);
	document.cookie = name + '=' + value + "; expires=" + expireDate;
}


function setCookie(name, value) 
{
	value = escape(value);
	document.cookie = name + '=' + value;
}

function setARCookie(value){
	setARSignupCookie('ARSignup',value);
}

function setARSignupCookie(name, value){
	value = escape(value);
	document.cookie = name + '=' + value + '; domain=turbotax.intuit.com; path=/'
}


function getCookie(name) 
{
	var cookies = document.cookie;
	var start = cookies.indexOf(name + '=');
	if (start == -1) return null;
	var len = start + name.length + 1;
	var end = cookies.indexOf(';',len);
	if (end == -1) end = cookies.length;
	return unescape(cookies.substring(len,end));
}



function CheckCookies(url,name,settings,theForm,theType) 
{
	// This Function is used on the Order Buttons to check for the Cookies - If the Cookies are Disabled - this Function would Open Up a Pop-Up Window and not Submit the form
	// If the Cookie is enabled - then this function would submit the form without displaying the Pop-Up Window.
	var mNoError = true;
	
	// Used to stop double submit
	mNoError = doubleSubmit();

	// Check valid Dropdown values
	if(theType == "business" || theType == "state" || theType == "value" || theType == "free state" || theType == "past year state" || theType == "past year business")
	{
		if(mNoError == true)
		{
			mNoError = ProductSelection(theForm, theType);

			// If Error occurs because Dropdown was not populated correctly, reset Double Submit to Zero
			if(mNoError != true)
			{
				submitcount = 0;
			}
		}
	}


	if(mNoError == true)
	{
		// Detect if Cookies are Enabled
		mNoError = DetectCookie(url,name,settings);

		// If cookies are turned off, reset Double Submit to Zero
		if(mNoError == false)
		{
			resetSubmitCount();
		}
	}

	return mNoError;
}

/* For Submit to Cart Regular SKU with arbitrary property names */
function Set_formItemProperty(theForm, propertyName, index, skuInputName)
{
  var mCatalogRefId
  var mSKU = theForm[skuInputName];

  /*
   the input field can go from not an array to array on the fly,
   so we need to check which one it is. We don't know exactly why,
   but suspect it may have to do with this function getting called
   while the page is still being loaded.
   */
  mCatalogRefId = theForm.elements[propertyName];
  if (mCatalogRefId.length)
  {
      mCatalogRefId = mCatalogRefId[index];
  }

   mCatalogRefId.value = mSKU.options[mSKU.selectedIndex].value;
}

function Clear_formItemProperty(theForm, propertyName, index)
{
  var mCatalogRefId

  /*
   the input field can go from not an array to array on the fly,
   so we need to check which one it is. We don't know exactly why,
   but suspect it may have to do with this function getting called
   while the page is still being loaded.
   */
  mCatalogRefId = theForm.elements[propertyName];
  if (mCatalogRefId.length)
  {
      mCatalogRefId = mCatalogRefId[index];
  }

   mCatalogRefId.value = "";
}

function URLRedirect(url, subSkuIds, theForm, type)
{
	if( CheckCookies('/store/jhtml/popup.jsp?content=cookieerror', 'CookieError', 'width=550,height=430,scrollbars=1,menubar=0,toolbar=0,location=0,status=0,resizable=1', theForm, type) )
	{
		window.location.href = url + "&originalSKUId=" + subSkuIds;
	}
}

// Check for Dropdowns and check that they are not empty if exist
function ProductSelection(theForm, theType)
{
	var mCategory = theForm["category"];
	var mProduct = theForm["product"];
	var mSKU = theForm["sku"];
	var mNoError = true;
	var mErrorMessage = "";

	if(theType == "business")
	{
		mErrorMessage = "Please select a Business Type, a State and a Media type from the drop down menus before clicking on the 'Order' button.";
	}
	else if(theType == "past year business")
	{
		mErrorMessage = "Please select a Business Type, a State and a Media type from the drop down menus before clicking on the 'Continue' button.  If you do not want or need a State product, please click 'Cancel'.";
	}
	else if(theType == "state")
	{
		mErrorMessage = "Please select a State from the first drop down menu and then a Media type from the second drop down menu before clicking on the 'Order' button.";
	}
	else if(theType == "past year state")
	{
		mErrorMessage = "Please select a State from the first drop down menu and then a Media type from the second drop down menu before clicking on the 'Continue' button.  If you do not want or need a State product, please click 'Cancel'.";
	}
	else if(theType == "free state")
	{
		mErrorMessage = "Please select a State from the first drop down menu and then a media type from the second drop down menu before clicking on the 'Add to Order' button.  If you do not want or need a State product, please click 'Skip This Option'.";
	}
	else if(theType == "value")
	{
		mErrorMessage = "Please select a Single or Value Pack from the first drop down menu and then a Version from the second drop down menu before clicking on the 'Order' button.";
	}


	if(mCategory != null)
	{
		if(mCategory.options[mCategory.selectedIndex].value == '' && mNoError == true)
		{
			alert(mErrorMessage);
			mNoError = false;
		}
	}

	if(mProduct != null)
	{
		if(mProduct.options[mProduct.selectedIndex].value == '' && mNoError == true)
		{
			alert(mErrorMessage);
			mNoError = false;
		}
	}

	if(mSKU != null)
	{
		if(mSKU.options[mSKU.selectedIndex].value == '' && mNoError == true)
		{
			alert(mErrorMessage);
			mNoError = false;
		}
	}

	return mNoError;
}

function FillMedia(theForm, selectFirst, productInputName, skuInputName, defaultMediaText, noneAllowed, propertyName, index)
{
  var mProduct = theForm[productInputName];
  var mSKU = theForm[skuInputName];
  var mId;
  var mArrayLen;

  mSKU.options[0].text = defaultMediaText;
  mSKU.options[0].value = "";

  if (mProduct.selectedIndex)
  {
    if(mProduct.selectedIndex != -1 && mProduct.options[mProduct.selectedIndex].value != '')
    {
      mId = mProduct.options[mProduct.selectedIndex].value;

      if(mediaArray[mId] != null)
      {
        if (noneAllowed && (mProduct.selectedIndex == 1))
        {
          // in this case, we don't want the "select first" text in the first item.
          mSKU.length=1;
          mSKU.options[0].text = "N/A";
          mSKU.options[0].value = mediaArray[mId][0][0];
          mSKU.selectedIndex = 0;
          Set_formItemProperty(theForm, propertyName, index, skuInputName);
        }
        else
        {
          mArrayLen = mediaArray[mId].length + 1;
          mSKU.length = mArrayLen;

          for(var i = 1; i < mArrayLen; i++)
          {
            mSKU.options[i].text = mediaArray[mId][i - 1][1];
            mSKU.options[i].value = mediaArray[mId][i - 1][0];
          }
          Clear_formItemProperty(theForm, propertyName, index);
        }
      }
      else
      {
        mSKU.length = 4;
        mSKU.options[1].text = selectFirst;
        mSKU.options[1].value = "";
        mSKU.options[2].text = "";
        mSKU.options[2].value = "";
        mSKU.options[3].text = "";
        mSKU.options[3].value = "";
        Clear_formItemProperty(theForm, propertyName, index);
      }

      mSKU.selectedIndex = 0;
    }
    else
    {
      mSKU.length = 4;
      mSKU.options[1].text = selectFirst;
      mSKU.options[1].value = "";
      mSKU.options[2].text = "";
      mSKU.options[2].value = "";
      mSKU.options[3].text = "";
      mSKU.options[3].value = "";
      mSKU.selectedIndex = 0;
      Clear_formItemProperty(theForm, propertyName, index);
    }
  }
  else
  {
    mSKU.length = 4;
    mSKU.options[1].text = selectFirst;
    mSKU.options[1].value = "";
    mSKU.options[2].text = "";
    mSKU.options[2].value = "";
    mSKU.options[3].text = "";
    mSKU.options[3].value = "";
    mSKU.selectedIndex = 0;
    Clear_formItemProperty(theForm, propertyName, index);
  }
}


function FillProduct(theForm, selectFirst, selectSecond, categoryInputName, productInputName, skuInputName)
{
  var mCategory = theForm[categoryInputName];
  var mProduct = theForm[productInputName];
  var mSKU = theForm[skuInputName];
  var mId;
  var mArrayLen;

  if (mCategory.selectedIndex)
  {
    if(mCategory.options[mCategory.selectedIndex].value != '')
    {
      mId = mCategory.options[mCategory.selectedIndex].value;

      if(mediaArray[mId] != null)
      {
        mArrayLen = mediaArray[mId].length + 1;
        mProduct.length = mArrayLen;
			
        for(var i = 1; i < mArrayLen; i++)
        {
          mProduct.options[i].text = mediaArray[mId][i - 1][1];
          mProduct.options[i].value = mediaArray[mId][i - 1][0];
        }
      }
      else
      {
        mProduct.length = 4;
        mProduct.options[1].text = selectFirst;
        mProduct.options[1].value = "";
        mProduct.options[2].text = "";
        mProduct.options[2].value = "";
        mProduct.options[3].text = "";
        mProduct.options[3].value = "";
      }

      mProduct.selectedIndex = 0;

      mSKU.length = 4;
      mSKU.options[1].text = selectSecond;
      mSKU.options[1].value = "";
      mSKU.options[2].text = "";
      mSKU.options[2].value = "";
      mSKU.options[3].text = "";
      mSKU.options[3].value = "";
      mSKU.selectedIndex = 0;
    }
    else
    {
      mProduct.length = 4;
      mProduct.options[1].text = selectFirst;
      mProduct.options[1].value = "";
      mProduct.options[2].text = "";
      mProduct.options[2].value = "";
      mProduct.options[3].text = "";
      mProduct.options[3].value = "";
      mProduct.selectedIndex = 0;

      mSKU.length = 4;
      mSKU.options[1].text = selectFirst;
      mSKU.options[1].value = "";
      mSKU.options[2].text = "";
      mSKU.options[2].value = "";
      mSKU.options[3].text = "";
      mSKU.options[3].value = "";
      mSKU.selectedIndex = 0;
    }
  }
  else
  {
    mProduct.length = 4;
    mProduct.options[1].text = selectFirst;
    mProduct.options[1].value = "";
    mProduct.options[2].text = "";
    mProduct.options[2].value = "";
    mProduct.options[3].text = "";
    mProduct.options[3].value = "";
    mProduct.selectedIndex = 0;

    mSKU.length = 4;
    mSKU.options[1].text = selectFirst;
    mSKU.options[1].value = "";
    mSKU.options[2].text = "";
    mSKU.options[2].value = "";
    mSKU.options[3].text = "";
    mSKU.options[3].value = "";
    mSKU.selectedIndex = 0;
  }
}



function Length_TextField_Validator()
{
// Check the length of the value of the element named text_name
// from the form named form_name if it's < 6 and > 32 characters
// display a message asking for different input
if ((document.formcreateacct.password.value.length < 6) || (document.formcreateacct.password.value.length > 32))
{
// Build alert box message showing how many characters entered
mesg = "You have entered " + document.formcreateacct.password.value.length + " character(s) in the password field\n"
mesg = mesg + "Valid entries are between 6 and 32 characters.\n"
mesg = mesg + "Please verify your input and submit again."
alert(mesg);
// Place the cursor on the field for revision
document.formcreateacct.password.focus();
// return false to stop further processing
return (false);
}
// If text_name is not null continue processing
return (true);
}

function openPopUp4(url, name, width, height)
{
	
	//first set the attributes of the popup window
	settings = "toolbar=no,location=no,directories=no,"+
	           "status=no,menubar=no,scrollbars=yes,"+
	           "resizable=yes,width="+width+",height="+
	           height+",left=250,top=10,screenX=250,screenY=10";
	var PopUp1 = window.open(url, name, settings); 
	
	//added following code to keep window active when clicking on the next link,
	//especially on the mydownloads page in estore.
	if (!PopUp1 || PopUp1.closed)
	{
		PopUp1 = window.open(url, name, settings);
	}
	else
	{
		PopUp1.focus();
	}
}

function clearAllCheckBoxes(myForm){
	if (myForm != null)
	{
		myForm.reset();
	}
}

function submitShippingMethod(formName){

		document.forms[formName].submit();
	
}

//This next area handles the select options in AM/AR/Checkout for phone types
//If primary phone type is one, the alternate phone type can only show the other

// initialize list arrays
listOne = new Array(1)
listTwo = new Array(0)
listThree = new Array(0)

listOne[1] = "Home"
listOne[2] = "Business"

// create entirely new options list
function changePhone(choice) {
	var listObj = document.checkout_form.phoneTypeAlt

	if (listObj.type) 
	{
		// get setting
		var lang = (document.checkout_form.phoneTypePrim.options[document.checkout_form.phoneTypePrim.selectedIndex].text)

		// empty options from list
		listObj.length = 0

		// create new option object for each entry
		if (lang == "Home") {
		    listObj.options[0] = new Option("Work", "20")
		} else if (lang == "Work") {
		     listObj.options[0] = new Option("Home", "10")
		} else {
		     listObj.options[0] = new Option("Please select", "0")
		     listObj.options[1] = new Option("Home", "10")
		     listObj.options[2] = new Option("Work", "20")
		}
	}
}
/* Added from 2006 Site */
function popScreenShot(imageUrl,pageTitle,width,height,resizable,scrollbars,status,toolbar,location,directories,menubar){
	// for parameters resizable, scrollbars, use 'yes' or 'no' or leave them blank for 'yes'.
	// for the rest of the parameters, they default to 'no', if you leave them blank.
	var w = width ? width : 700;
	var h = height ? height : 480;
	var resize = resizable ? ',resizable='+resizable : ',resizable=yes';
	var scroll = scrollbars ? ',scrollbars='+scrollbars : ',scrollbars=yes';
	var stat = status ? ',status='+status : ',status=no';
	var tool = toolbar ? ',toolbar='+toolbar : ',toolbar=no';
	var loc = location ? ',location='+location : ',location=no';
	var dir = directories ? ',directories='+directories : ',directories=no';
	var menu = menubar ? ',menubar='+menubar : ',menubar=no';

	var myWin;
	if(myWin && !myWin.closed){
		myWin.close();
	}
	myWin = window.open('','_win_','height='+h+',width='+w+resize+scroll+stat+tool+loc+dir+menu);
	myWin.document.write('<html><body bgcolor="#ffffff"><img src=\"'+imageUrl+'\"></body></html>');
	myWin.document.title = pageTitle;
	myWin.focus();
}