//This little piece of script is to solve
//the IE 6 bug in which text couldn't be selected or highlighted.
//Source: http://blog.tom.me.uk/2003/07/23/boie6selecta.php
if (window.createPopup && document.compatMode && document.compatMode=="CSS1Compat")
{
  document.onreadystatechange = onresize = function fixIE6AbsPos()
  {
    if (!document.body) return;
    if (document.body.style.margin != "0px") document.body.style.margin = 0;
    onresize = null;
    document.body.style.height = 0;
    setTimeout(function(){ document.body.style.height = document.documentElement.scrollHeight+'px'; }, 1);
    setTimeout(function(){ onresize = fixIE6AbsPos; }, 100);
  }
}
//End of IE 6 Bug fix

function BookMarkIt()
{
	if (navigator.userAgent.indexOf('MSIE') > 0)
		window.external.AddFavorite(location.href, document.title);
	else
		alert("The bookmark feature is currently\nonly supported by Internet Explorer. \n However, you can manually bookmark\nthis page using your browser's \n 'Bookmarks' or 'Add to Favorites' feature. ");

}

function JumpURL(selection)
{
	var tempIndex, selectedURL;
	tempIndex = selection.selectedIndex;
	selectedURL = selection.options[tempIndex].value;
	if (selectedURL != '')
	{
		window.top.location.href = selectedURL;
	}
}

function initArray() {
	for (var i = 0; i < initArray.arguments.length; i++) {
	this[i] = initArray.arguments[i];
	}
	this.length = initArray.arguments.length;
	}
	var colors = new initArray(
	"white",
	"red");
	delay = .1; // seconds
	link = 0;

function FlashBG(counter) {
	link = (link+1)%colors.length;
	document.loginform.Username.style.background = colors[link];
	if (counter < 15)
		setTimeout("FlashBG(" + (counter+1) + ")",delay*1000);
	}

function MySchaeffersHighlight()
{
	// go to MyAccount page first to log in; pass return path in qs param jms
	var here=document.location.href;
	location.href="/MyAccount.aspx?return="+escape(here.substr(here.indexOf("/",here.indexOf("//")+2)));


	//// the old way, since loginform isn't on the same page anymore -  jms
	//// document.loginform.Username.focus();
	//// //document.loginform.Username.style.background = "#DFEFEB";

	//// FlashBG(0);
}

 /*
 Try to use the OpenWindow function to open pop-up windows whenever possible. -MCT
 winURL = the URL of the page
 winParameters = all the specific window parameters
 EXAMPLE: OpenWindow('/members/sdb/blah.aspx', 'width=450, height=500')
 */
function OpenWindow(winUrl, winParameters)
{
	window.open(winUrl, "SIRWindow", winParameters);
}
function to_old_win(url)
{
	opener.location.href = url;
	self.close();
}

function formHandler(shortcut)
{
	var URL = document.shortcut.product.options[document.shortcut.product.selectedIndex].value;
		window.location.href = URL;
}

function printWindow() {
	bV = parseInt(navigator.appVersion);
	if (bV >= 4) window.print();
}

function checkOpenMenu()
{
	//This is used by the poll.
	var querystring = window.location.search;
	var querystringValue = '';

	if (querystring.indexOf("openmenu=") > -1)
	{
		//find the beginning point of open menu values.
		querystringValue = querystring.substring(querystring.indexOf("openmenu=") + 9, querystring.length);

		if (querystringValue != '')
		{
			//Check to see if there are any other querystring variables after openmenu.
			//If so, truncate the string.
			if (querystringValue.indexOf("&") > -1)
			{
				querystringValue = querystringValue.substring(0, querystringValue.indexOf("&"));
			}

			var nameVal = querystringValue.split(',');

			openmenu2(nameVal[0], nameVal[1]);
		}
	}
}

function parseQueryString()
{
	var idx = location.href.indexOf('?');
	var params = new Array();
	if (idx != -1)
	{
		var pairs = location.href.substring(idx+1, location.href.length).split('&');
		for (var i=0; i<pairs.length; i++)
		{
			nameVal = pairs[i].split('=');
			params[i] = nameVal[1];
			params[nameVal[0]] = nameVal[1];
		}
	}
	return params;
}


function storehelp()
{
window.open ("https://secure.schaeffers.net/optionsource/helpform.asp","new_window","width=450,height=500, location=0,menubar=0,resizable=0,scrollbars=1,status=0,titlebar=0,toolbar=0,left=10,top=10,screenx=10,screeny=10");
}

function matrix()
{
window.open ("/market/sds_matrix.asp#primer","new_window","width=600,height=600, location=0,menubar=0,resizable=0,scrollbars=1,status=0,titlebar=0,toolbar=1,left=10,top=10,screenx=10,screeny=10");
}

function moreinfo(infourl)
{
window.open(infourl,"store_help","width=500,height=500, location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=0,toolbar=0,left=10,top=10,screenx=10,screeny=10");
}

function prodpop(prodid)
{
window.open("/shop/bernie_guidance.aspx?id=" + prodid,"prodpop","width=450,height=300, location=0,menubar=0,resizable=0,scrollbars=1,status=0,titlebar=0,toolbar=0,left=10,top=10,screenx=10,screeny=10");
 }



function winpop(url) {
sealWin=window.open(url,"win","toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=650,height=450,left=0,top=0,screenx=0,screeny=0");
self.name = "mainWin"; }

function products(sectiontype)
{
var myURL = "/shop/productlist.aspx?view=" + sectiontype;

DealUnder=window.open(myURL,'Products','width=400,height=300, location=0,menubar=0,resizable=0,scrollbars=1,status=0,toolbar=0,location=0,directories=0,left=10,top=10,screenx=10,screeny=10');
}

function loadunder()
{
		DealUnder=window.open("/shop/popunder_dealofweek.aspx",'DealUnder','width=720,height=550, location=0,menubar=0,resizable=0,scrollbars=1,status=0,toolbar=0,location=0,directories=0,left=10,top=2,screenx=10,screeny=2');
		if (DealUnder)
		{
			DealUnder.blur();
			this.focus();
		}
}
function loadundersingle()
{
		DealUnder=window.open("/shop/popunder_dealofweek_single.aspx",'DealUnder','width=600,height=400, location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0,location=0,directories=0,left=10,top=2,screenx=10,screeny=2');

		if (DealUnder)
		{
			DealUnder.blur();
			this.focus();
		}
}

function open_selected(val)
{
	if (val != "")
 		window.open (val,"prod","width=785,height=500, location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=0,toolbar=0,left=0,top=0,screenx=0,screeny=0");
	else
		return true;
	self.close();
}

function load(file,target)
{
    if (target != '' && opener)
	{
        target.window.location.href = file;
		window.close();
	}
    else
	{
        top.location.href = file;
	}
}

function open_search(val)
{
	if (val == "datetime")
	{
		document.searchForm.SearchString.value = "Enter a Valid Date (mm/dd/yyyy)"
		if(document.all)
		{
			document.all['datetime'].innerHTML = "<i><b>This option will find all articles greater than or equal to the date entered.  Please enter a date in the following format:  MM/DD/YYYY</b></i>";
		}
	}
	else
		if(document.all)
		{
			document.all['datetime'].innerHTML = "";
			document.searchForm.SearchString.value = "";
		}

	return true;
}
