//var PayMethod = "cc";
document.onmousemove = CaptureMousePosition;
document.onmousedown = CaptureMouseDown;

xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

function BodyLoad()
{
	//alert("navigator.appName=" + navigator.appName);

//	if ( navigator.appName.indexOf("Netscape") != -1 )
	if ( navigator.appName.indexOf("Microsoft") != -1 || navigator.appName.indexOf("Explorer") != -1 )
		ChangeImageLoop(true);
}

function ChangeImageLoop(FirstTime)
{ 
	if ( !FirstTime )
	{
		ChangeImage();
	}
	setTimeout('ChangeImageLoop(false)', 10000);
}

function ChangeImage()
{
	if (document.getElementById("RotatorImage") != null)
	{
		Rotator.filters[0].apply();
		UpdateDisplayedImage();
		Rotator.filters[0].play();
	}
}

function UpdateDisplayedImage()
{
	if (document.getElementById("RotatorImage").src.indexOf("Necklaces") != -1)
	{
		document.getElementById("RotatorImage").src = document.getElementById("RotatorImage").src.replace("Necklaces", "Bracelets");
		document.getElementById("RotatorImage").alt = "Bracelets";
		document.getElementById("RotatorLink").href = "default.aspx?link=x&pg=list&type=b&listnum=0";
	}
	else if (document.getElementById("RotatorImage").src.indexOf("Bracelets") != -1)
	{
		document.getElementById("RotatorImage").src = document.getElementById("RotatorImage").src.replace("Bracelets", "Earrings");
		document.getElementById("RotatorImage").alt = "Earrings";
		document.getElementById("RotatorLink").href = "default.aspx?link=x&pg=list&type=e&listnum=0";
	}
	else if (document.getElementById("RotatorImage").src.indexOf("Earrings") != -1)
	{
		document.getElementById("RotatorImage").src = document.getElementById("RotatorImage").src.replace("Earrings", "Necklaces");
		document.getElementById("RotatorImage").alt = "Necklaces";
		document.getElementById("RotatorLink").href = "default.aspx?link=x&pg=list&type=n&listnum=0";
	}
}

function PayPal()
{
	//document.getElementById("business").value = "hello@myflair.net";
	//document.getElementById("return").value = "http://www.myflair.net/default.aspx?pg=thanks";
	document.theForm.action = "https://www.paypal.com/cgi-bin/webscr";
	document.theForm.submit();
}

function SearchBox()
{
	if ( document.theForm.srchbx.value.length == 0 )
	{
		alert("Please enter search text");
		return;
	}
	if ( document.theForm.srchbx.value.length < 3 )
	{
		alert("Please enter at least 3 characters of search text");
		return;
	}
	//document.theForm.action = "default.aspx?pg=srch";
	document.theForm.action = "default.aspx";
	document.theForm.submit();
}

function SearchLength()
{
	if ( document.theForm.SearchLength.value == 0 )
	{
		alert("Please select a length");
		return;
	}
	document.theForm.SearchStone.value = "0";
	document.theForm.SearchColor.value = "0";
	document.theForm.action = "default.aspx";
	document.theForm.submit();
}

function SearchStone()
{
	if ( document.theForm.SearchStone.value == 0 )
	{
		alert("Please select a stone or bead");
		return;
	}
	document.theForm.SearchLength.value = "0";
	document.theForm.SearchColor.value = "0";
	document.theForm.action = "default.aspx";
	document.theForm.submit();
}

function SearchColor()
{
	if ( document.theForm.SearchColor.value == 0 )
	{
		alert("Please select a color");
		return;
	}
	document.theForm.SearchLength.value = "0";
	document.theForm.SearchStone.value = "0";
	document.theForm.action = "default.aspx";
	document.theForm.submit();
}

function LinkBtnMouseOver(obj, LinkBtn)
{
	//obj.style.backgroundColor = "#336699";
	//document.getElementById(LinkBtn).style.borderColor = "#000066";
	obj.style.color = "#008080";
}

function LinkBtnMouseOut(obj, LinkBtn)
{
	//obj.style.backgroundColor = "#6699CC";
	//document.getElementById(LinkBtn).style.borderColor = "#008080";
	obj.style.color = "#000066";
}

function LinkMouseOver(obj, color)
{
	obj.style.color = color;
}

function LinkMouseOut(obj, color)
{
	obj.style.color = color;
}

function BodyLinkMouseOver(obj)
{
	obj.style.textDecoration = "underline";
}

function BodyLinkMouseOut(obj)
{
	obj.style.textDecoration = "none";
}

function mOvr(obj)
{
	obj.style.textDecoration = "underline";
}

function mOut(obj)
{
	obj.style.textDecoration = "none";
}

function ButtonMouseOver(obj)
{
	obj.style.cursor="hand";
}

function ButtonMouseOut(obj)
{
	obj.style.cursor="default";
}

function ValidNumber(obj)
{
	if ( obj.value.length > 0 )
		if ( isNaN(obj.value) )
		{
			alert("Invalid entry: " + obj.value + " , only numbers allowed, please correct.");
			obj.focus();
			return false;
		}
	return true;
}

function VerifyDay(m, d, y)
{
	if ( m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12 )
		return true;
	if ( m != 2 )
		if ( d < 31 )
			return true;
		else
			return false;
	// month is february
	if ( y == 2004 || y == 2008 || y == 2012 || y == 2016 || y == 2020 )
		if ( d < 30 )
			return true;
		else
			return false;
	if ( d < 29 )
		return true;
	else
		return false;
}

function CheckForInvalidChar(inText)
{
	var CheckText;
	var ReturnChar = "";
	var x;

	// check that only valid characters used, to protect against potential string problems
	CheckText = inText.toLowerCase()
	for ( x=0; x<CheckText.length; x++ )
	{
		if ( CheckText.charAt(x) == "\"" ||
			CheckText.charAt(x) == ">" ||
			CheckText.charAt(x) == "\\" ||
			CheckText.charAt(x) == "/" ||
			CheckText.charAt(x) == "<" )
		{
			ReturnChar = inText.charAt(x);
			x = CheckText.length; // stop loop
		}
	}
	return ReturnChar;
}

function ValidEmail(EmailValue)
{
	var len = EmailValue.length;
	if ( len < 10 )
		return false;
	var DotPos = EmailValue.indexOf(".");
	if ( DotPos < 1 || DotPos > len-3 )	// dot must exist and have at least 2 chars after it
		return false;
	var AmpPos = EmailValue.indexOf("@");
	if ( AmpPos < 2 )	// ampersand must exist and have at least 2 chars before it
		return false;
	if ( AmpPos+3 > DotPos ) // ampersand must be before dot and have at least 2 chars between them
		return false;
		
	return true;
}

function TrimString(str)
{
	if ( str.length == 0 )
		return "";
	while ( str.charAt(0) == " " ) // strip leading blanks (ltrim)
	{
		str = str.substr(1, str.length-1);
	}
	while ( str.charAt(str.length-1) == " " ) // strip trailing blanks (rtrim)
	{
		str = str.substr(0, str.length-1);
	}

	return str;
}

function CountNumbers(obj)
{
	var nNums = 0;
	var i;

	if ( obj.value.length == 0 )
		return 0;
	while ( obj.value.charAt(0) == " " ) // strip leading blanks (ltrim)
	{
		obj.value = obj.value.substr(1, obj.value.length-1);
	}
	while ( obj.value.charAt(obj.value.length-1) == " " ) // strip trailing blanks (rtrim)
	{
		obj.value = obj.value.substr(0, obj.value.length-1);
	}

	for ( i=0; i<obj.value.length; i++ )
	{
		if ( isNaN(obj.value.charAt(i)) )
			continue;
		else
			nNums++;
	}
			
	return nNums;
}

function PopUp(sMode, sWidth, sHeight)
{
	window.open("popup.asp?m=" + sMode, "Help", "menubar=no,location=no,scrollbars=no,width=" + sWidth + ",height=" + sHeight + ",resizable=yes")
}

function TableShow(inTable, Mode)
{
	var EstimatedWindowHeight = 200;	// could be passed in?
	var EstimatedWindowWidth = 400;

	//alert("xMousePos="+xMousePos);
	//alert("yMousePos="+yMousePos);
	//alert("xMousePosMax="+xMousePosMax);
	//alert("yMousePosMax="+yMousePosMax);
	//alert("document.body.clientWidth="+document.body.clientWidth);
	//alert("document.body.clientHeight="+document.body.clientHeight);

	document.getElementById(inTable).style.visibility = "visible";

	// window relative to mouse click
	//document.getElementById(inTable).style.top = yMousePos - 200;
	//document.getElementById(inTable).style.left = xMousePos - 400;

	if ( Mode == "center" )
	{
		// window centered on page
		document.getElementById(inTable).style.top = (document.body.clientHeight/2) - (EstimatedWindowHeight/2);
		document.getElementById(inTable).style.left = (document.body.clientWidth/2) - (EstimatedWindowWidth/2);
	}
	else
	{
		document.getElementById(inTable).style.top = yMousePos-100;
		document.getElementById(inTable).style.left = xMousePos+10;
	}
}

function TableHide(inTable)
{
	document.getElementById(inTable).style.visibility = "hidden";
}

function CaptureMousePosition(e)
{
	if ( document.all )
	{
		// When the page scrolls in IE, the event's mouse position 
		// reflects the position from the top/left of the screen the 
		// user is looking at. scrollLeft/Top is the amount the user
		// has scrolled into the page. clientWidth/Height is the height/
		// width of the current page the user is looking at. So, to be
		// consistent with Netscape (above), add the scroll offsets to
		// both so we end up with an absolute value on the page, no 
		// matter if the user has scrolled or not.
		xMousePos = window.event.x + document.body.scrollLeft;
		yMousePos = window.event.y + document.body.scrollTop;
		xMousePosMax = document.body.clientWidth + document.body.scrollLeft;
		yMousePosMax = document.body.clientHeight + document.body.scrollTop;
	}
	else if ( document.getElementById )
	{
		xMousePos = e.pageX;
		yMousePos = e.pageY;
		xMousePosMax = window.innerWidth + window.pageXOffset;
		yMousePosMax = window.innerHeight + window.pageYOffset;
    }
}

function CaptureMouseDown(e)
{
	if ( document.all )
	{
		//if ( event.button == 2 || event.button == 3 )	// right click
		//	if ( bMouseOnArtwork )
		//		alert("Right click not available on artwork.");
	}
	else if ( document.getElementById )
	{
		//if ( e.which == 3 )	// right click
		//	if ( bMouseOnArtwork )
		//	{
		//		bMouseOnArtwork = false;
		//		//alert("Right click not available on artwork.");
		//		return;
		//		// can't stop context menu (???)
		//	}
    }
}

function KeyPressed(Event, sMode)
{
	var Key = 0;

	//if ( window.event )
	if ( document.all )
		Key = window.event.keyCode;	// IE
	else if ( document.getElementById )
		Key = Event.keyCode? Event.keyCode : Event.charCode;	// firefox
	//if ( Key != 0 )
	//	alert("Key pressed! ASCII-value: " + Key);
	//if ( Key == 13 )
}