/*	Mouseover Preview Images Script */
// Set the document up to keep track of the mouse position
var cX = 0; var cY = 0;
var isSiteReleased, rootURL, isSecureConnection, isFESSite;
var cabURL, pluginURL;
if (window.document.location.href.toLowerCase().indexOf('embroiderydesigns.com') > -1)
{isSiteReleased = true; rootURL = "/";}
else
{isSiteReleased = false; rootURL = "/embroiderydesigns/";}
if (window.document.location.href.toLowerCase().indexOf('freeembroiderystuff.embroiderydesigns.com') > -1){isFESSite=true;}
else if (window.document.location.href.toLowerCase().indexOf('edfreestuff') > -1){isFESSite=true;}
else {isFESSite =false;}
if (window.document.location.protocol == "http:"){isSecureConnection = false;}else{isSecureConnection = true;}
if(isSecureConnection){cabURL='https://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab';pluginURL='https://www.adobe.com/go/getflashplayer';}
else {cabURL='http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab';pluginURL='http://www.adobe.com/go/getflashplayer';}

function UpdateCursorPosition(e){cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){	cX = event.clientX + document.body.scrollLeft;cY = event.clientY + document.body.scrollTop;}
if(document.all) {document.onmousemove = UpdateCursorPositionDocAll;}else {document.onmousemove = UpdateCursorPosition; }
function truebody(){return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body}

var cursorInDiv=false; var cursorInImg=false;
var previewHtmlBegin = "<table cellSpacing=\"0\" cellpadding=\"0\" runat=\"server\" width=\"250\"><TR><td align=\"center\"><table bgColor=\"#ffffff\" class=\"TableBorder\" width=\"100%\" cellpadding=\"0\"><tr><td><table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">"
var previewHtmlCrossStitch = "<tr class=\"CustomTableColor\" style=\"padding:5px 5px 0 5px;\" align=\"center\"><td class=\"defaultText12\">This is a <strong>CROSS-STITCH</strong> pattern.</td></tr>"
var previewHtmlApplique = "<tr class=\"CustomTableColor\" style=\"padding:5px 5px 0 5px;\" align=\"center\"><td class=\"defaultText12\">This is an <strong>APPLIQUE</strong> pattern.</td></tr>"
var previewHtmlSoftware = "<tr class=\"CustomTableColor\" style=\"padding:5px 5px 0 5px;\"><td class=\"defaultText12\">"

var previewHtmlImg1 = "<tr><td align=\"center\" style=\"padding:5px;\">"
var previewHtmlImg2 = "</td></tr><tr class=\"CustomTableColor\" style=\"padding:0 5px 5px 5px;\"><td valign=\"top\" align=\"center\" class=\"defaultText12\"><strong>Vendor: </strong>"
var previewDivEFP = "<div class=\"CustomTableColor\" style=\"padding:5px 5px 0 5px;\" align=\"center\"><font class='defaultText12'>This is a <strong>keyboard font</strong> - requires <strong>Embroidery Fonts Plus</strong> software.</font></div>"
var previewDivFont = "<div class=\"CustomTableColor\" style=\"padding:5px 5px 0 5px;\" align=\"center\"><font class='defaultText12'>This is an <strong>alphabet</strong>. Each letter, number, or symbol is an <strong>individual stitch file</strong>.</font></div>"
var previewHtmlImg3 = "<br><a class=\"defaultText10\" href=\"linkgoeshere\">Click for details</a>"
var previewHtmlEnd = "</td></tr></table></td></tr></table></td></tr></table>"

function AssignPosition(d,e,prd) {
var xcoord=0;
var ycoord=0;
var defaultimageheight=290;
var defaultimagewidth=265;
if (prd != null) {if (prd.toLowerCase() == "font") defaultimageheight=320;}

var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

if (typeof window.event != "undefined"){
	if (docwidth - event.clientX < defaultimagewidth ){xcoord = event.clientX + truebody().scrollLeft - xcoord - defaultimagewidth; // Move to the left side of the cursor
	} 
	else {xcoord += truebody().scrollLeft+event.clientX}
	if (docheight - event.clientY < (defaultimageheight)){ycoord += event.clientY + truebody().scrollTop - Math.max(0,(defaultimageheight + event.clientY - docheight));} 
	else {ycoord += truebody().scrollTop + event.clientY;}
} 
else {
	if (docwidth - cX < defaultimagewidth ){xcoord = cX - xcoord - defaultimagewidth; // Move to the left side of the cursor
	} else {xcoord += cX;}
	if (docheight - cY < defaultimageheight){ycoord += cY - Math.max(0,(defaultimageheight + cY - docheight - truebody().scrollTop));} 
	else {ycoord += cY;}
}
d.style.left = xcoord+"px";
d.style.top = ycoord+"px";
}
/*	toggleDiv revised 10/6/2009 --> Support for Licensed Designs
	toggleDiv revised 3/3/2009 --> Support for FES Article/Projects
	toggleDiv revised 1/7/2008 --> Support for different FontTypes 
	Original: isEFP had "True" or "False" values
	Change: isEFP will have "True", "False" or <FontType>

	toggleDiv revised 4/1/2008 --> Pulse or Wilcom version in blurb
*/
function toggleDiv(obj,ancHref,imgSrc,isCrossStitch,isEFP,vendor,prdType,name,IsApplique,desc){
	var obj1 = MM_findObj(obj);var anc1 = MM_findObj(ancHref);
	var buildTag="";

	if (IsApplique == null){IsApplique="false";}
	if (isCrossStitch == null){isCrossStitch="false";}
	if (isEFP == null){isEFP="false";}
	if (vendor == null) {vendor="Other";}if (prdType == null) {prdType = "design";}
	if (desc == null) {desc="none";}

	if (anc1 != null && imgSrc != null && obj1.innerHTML == "")
	{	
		buildTag = previewHtmlBegin; 
		if (IsApplique.toLowerCase() =="true"){buildTag = buildTag + previewHtmlApplique;}
		if (isCrossStitch.toLowerCase() =="true"){buildTag = buildTag + previewHtmlCrossStitch;}
		if (desc!="none"){
			if (prdType.toLowerCase() == "printart"){buildTag = buildTag + previewHtmlSoftware + "This is <b>" + desc + "</b> Design</td></tr>";}
			else if (prdType.toLowerCase() == "licenseddesign"){buildTag = buildTag + previewHtmlSoftware + "This design is by <b>" + desc + "</b></td></tr>";}
			else if (prdType.toLowerCase()=="articles"){buildTag = buildTag + previewHtmlSoftware + "<font align=center><b>" + desc + "</b><br/><i>" + name + "</i></font></td></tr>";}
			else {buildTag = buildTag + previewHtmlSoftware + desc + "</td></tr>";}
		}
		
		if (prdType.toLowerCase() == "font"){
			if (isEFP.toLowerCase() == "true"){buildTag = buildTag + previewDivEFP}
			else if (isEFP.toLowerCase() == "false"){buildTag = buildTag + previewDivFont}
			else {
				if (isEFP.toLowerCase()=="pulse fonts")
				{
					var pulseVersion = "Pulse Version 12 or higher";
					if (vendor != null && vendor.toLowerCase() == "grand slam designs")
						pulseVersion = "Pulse Version 9.1Q or higher";
					buildTag = buildTag + previewDivEFP.replace("Embroidery Fonts Plus",isEFP.replace("Pulse Fonts",pulseVersion));
				}
				else if (isEFP.toLowerCase()=="wilcom fonts")
				{
					buildTag = buildTag + previewDivEFP.replace("Embroidery Fonts Plus",isEFP.replace("Wilcom Fonts","Wilcom 2006 or higher"));
				}
				else
				{
					buildTag = buildTag + previewDivEFP.replace("Embroidery Fonts Plus",isEFP.replace(" Fonts",""));
				}
			}
		}
		
		var ancImg = "<a href=\"" + anc1 + "\">"; 
		ancImg = ancImg + "<img src=\"" + imgSrc + "\" title=\"" + name.replace('"','&quot;');
		if (prdType.toLowerCase()=="font"){ancImg = ancImg + " embroidery font"; } 
		else if (prdType.toLowerCase()=="printart"){ancImg = ancImg + " print art/heat press"; } 
		else if (prdType.toLowerCase()=="articles") {ancImg = ancImg + ": " + desc; }
		else {ancImg = ancImg + " embroidery design" }
		ancImg = ancImg + "\" border=\"0\" onmousedown=\"return false;\" oncontextmenu=\"alert(\'Images are copyright-protected!\');return false;\" onselectstart=\"return false;\"></a>";
		if (prdType.toLowerCase()=="articles"){buildTag = buildTag + previewHtmlImg1 + ancImg + previewHtmlImg2.replace("Vendor:","") + vendor + previewHtmlImg3.replace("linkgoeshere",anc1) + previewHtmlEnd;}
		else{buildTag = buildTag + previewHtmlImg1 + ancImg + previewHtmlImg2 + vendor + previewHtmlImg3.replace("linkgoeshere",anc1) + previewHtmlEnd;}
		
		obj1.innerHTML = buildTag;
	}
	if(cursorInImg) {AssignPosition(obj1);obj1.style.visibility ='visible';}
	if(cursorInDiv&&obj1.style.visibility !='visible') {obj1.style.visibility ='visible';}
	//alert(buildTag);
}

function closeDiv(obj)
{
	if(!cursorInDiv && !cursorInImg)
	{
		var obj1 = MM_findObj(obj);
		obj1.style.visibility ='hidden';	
		cursorInDiv=false;
		cursorInImg=false;
	}
}
function showDiv(obj1, obj2){
	var obj1 = MM_findObj(obj1);
	AssignPosition(obj1);
	var obj2 = MM_findObj(obj2);
	if(obj1.style.visibility == "hidden")
	{obj1.style.visibility = "visible";
	obj1.innerHTML = obj2.innerHTML;
	}
}
function CheckFreeDesignsFlash(){
var requiredMajorVersion = 6;
var requiredMinorVersion = 0;
var requiredRevision = 0;
flashrow = MM_findObj('divFlash');
adrow = MM_findObj('divAdR');
var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
flashrow.innerHTML = "";
if (hasRequestedVersion){
	flashrow.style.display="block";
	adrow.style.display="none";
	if (isFESSite)
	{	flashrow.innerHTML = AC_FL_RunContent(
									"src", "http://freeembroiderystuff.embroiderydesigns.com/images/flash_ads/freeads?dv=1234",
									"width", "300",
									"height", "165",
									"id", "edAds",
									"quality", "high",
									"bgcolor", "#FFFFFF",
									"base",".",
									"name", "detectionExample",
									"allowScriptAccess","sameDomain",
									"type", "application/x-shockwave-flash",
									'codebase', cabURL,
									"pluginspage", pluginURL
						);
	}
	else{
		flashrow.innerHTML = AC_FL_RunContent(
										"src", "http://www.embroiderydesigns.com/images/designs_images/freeads?dv=1234",
										"width", "300",
										"height", "165",
										"id", "edAds",
										"quality", "high",
										"bgcolor", "#FFFFFF",
										"base",".",
										"name", "detectionExample",
										"allowScriptAccess","sameDomain",
										"type", "application/x-shockwave-flash",
										'codebase', cabURL,
										"pluginspage", pluginURL
							);
	}
	}
else {flashrow.style.display="none";adrow.style.display="block";}
}
function CheckFlash(){
var requiredMajorVersion = 6;
var requiredMinorVersion = 0;
var requiredRevision = 0;
flashrow = MM_findObj('divFlash');
adrow = MM_findObj('divAdR');
var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
flashrow.innerHTML = "";
if (hasRequestedVersion){
	flashrow.style.display="block";
	adrow.style.display="none";
	flashrow.innerHTML = AC_FL_RunContent(
									"src", "images/loader?dv=1234",
									"width", "400",
									"height", "220",
									"id", "edAds",
									"quality", "high",
									"bgcolor", "#FFFFFF",
									"base",".",
									"name", "detectionExample",
									"allowScriptAccess","sameDomain",
									"type", "application/x-shockwave-flash",
									'codebase', cabURL,
									"pluginspage", pluginURL
						);
	}
else {flashrow.style.display="none";adrow.style.display="block";}
}
function ClickButton(e, LinkToClick) { 
var i = 0; 
while (i < document.forms(0).elements.length) { 
if (document.forms(0).elements(i).name.indexOf(LinkToClick) > -1) 
{ document.forms(0).elements(i).click(); return (true); } 
	i++; } 
i=0; 
while (i < document.links.length) 
{ if (document.links.item(i).id.toString().indexOf(LinkToClick) > -1) { 
document.links.item(i).click(); return (true); } 
i++; } return (false); }
function fixURL(inputURL)
{	if (inputURL.indexOf('http:\/\/') == -1 && inputURL.indexOf('https:\/\/') == -1)
	{
		if (isSiteReleased)
			inputURL = "/" + inputURL;
		else
			inputURL = rootURL + inputURL;
	}
	return inputURL;
} 
function newin(theURL,winName,features) 
{	theURL = fixURL(theURL);
	var x = window.open(theURL,winName,features);x.focus();}
function newPopUp(theURL, winsize) { 
theURL = fixURL(theURL);
  winName = null;
  var features;
	if (winsize != null)
		features = winsize + ", resizable = no, scrollbars=yes, left=10, top=10";
	else
		features = "width=500,height=500, resizable = no, scrollbars=yes, left=10, top=10";
  var x = window.open(theURL,winName,features);
  x.focus();}
function LinkPopUpToOriginalWindow(theURL) {
	theURL = fixURL(theURL);
	if (opener && !opener.closed){opener.location.href=theURL;}
	else {opener = window.open(theURL, 'main');}
	return false;}
function MM_swapImgRestore() { var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;}
function MM_preloadImages() { 
  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 MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;}
function MM_swapImage() { 
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}}
function MM_jumpMenu(targ,selObj,restore){
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;}

//This function checks the current page to see if the page name matches one of the Links in the 
//Tab and highlights the current page on the Tab
function checkTopLink(){	
var cnt = document.anchors.length;
for (i=0; i< cnt; i++){	var st = document.anchors[i].href.toUpperCase();
	var dt = document.URL.toUpperCase(); 
	if (st==dt && document.anchors[i].className=="LinkText")
		{document.anchors[i].className = "LinkHighlight";}
	else
	{ if(document.anchors[i].className == "LinkHighlight")
		document.anchors[i].className = "LinkText";
	}
}
if (isFESSite == true){showNav('fesdiv','true')}
else{
var leftnavitemvalue = ReadCookie("Cookie_LeftNavItem");
if(leftnavitemvalue=="") {showNav('eddiv');} else {showNav(leftnavitemvalue);}
}
}

// This function handles Hiding and Displaying Left Navigation Items
function showNav(ctrlID, isFES){
var edctrl = MM_findObj('edDIV');var epctrl = MM_findObj('epDIV');var cdctrl = MM_findObj('cdDIV');var efctrl = MM_findObj('efDIV');
var gcctrl = MM_findObj('gcDIV');var wnctrl = MM_findObj('wnDIV');var etctrl = MM_findObj('etDIV');var esctrl = MM_findObj('esDIV');
var fbctrl = MM_findObj('fbDIV');var edcctrl = MM_findObj('edcDIV');var eqctrl = MM_findObj('eqDIV');var fesctrl = MM_findObj('fesDIV');
var ebctrl = MM_findObj('ebDIV');var pactrl = MM_findObj('paDIV');var ldctrl = MM_findObj('ldDIV');
if (edctrl != null) {edctrl.className="hoverMenuOff";}
if (epctrl != null) {epctrl.className="hoverMenuOff";}
if (cdctrl != null) {cdctrl.className="hoverMenuOff";}
if (efctrl != null) {efctrl.className="hoverMenuOff";}
if (gcctrl != null) {gcctrl.className="hoverMenuOff";}
if (wnctrl != null) {wnctrl.className="hoverMenuOff";}
if (etctrl != null) {etctrl.className="hoverMenuOff";}
if (esctrl != null) {esctrl.className="hoverMenuOff";}
if (fbctrl != null) {fbctrl.className="hoverMenuOff";}
if (edcctrl != null) {edcctrl.className="hoverMenuOff";}
if (eqctrl != null) {eqctrl.className="hoverMenuOff";}
if (fesctrl != null) {fesctrl.className="hoverMenuOff";}
if (ebctrl != null) {ebctrl.className="hoverMenuOff";}
if (pactrl != null) {pactrl.className="hoverMenuOff";}
if (ldctrl != null) {ldctrl.className="hoverMenuOff";}
if (isFES != null){
	if (fesctrl != null) {fesctrl.className="hoverMenuOn"; return;}
}
switch (ctrlID.toLowerCase()){
	case "eddiv": if (edctrl != null) {edctrl.className="hoverMenuOn";SetCookie("Cookie_LeftNavItem","eddiv",24); }break;
	case "epdiv": if (epctrl != null) {epctrl.className="hoverMenuOn";SetCookie("Cookie_LeftNavItem","epdiv",24); }break;
	case "ebdiv": if (ebctrl != null) {ebctrl.className="hoverMenuOn";SetCookie("Cookie_LeftNavItem","ebdiv",24); }break;
	case "cddiv": if (cdctrl != null) {cdctrl.className="hoverMenuOn";SetCookie("Cookie_LeftNavItem","cddiv",24); }break;
	case "efdiv": if (efctrl != null) {efctrl.className="hoverMenuOn";SetCookie("Cookie_LeftNavItem","efdiv",24); }break;
	case "wndiv":if (wnctrl != null) { wnctrl.className="hoverMenuOn";SetCookie("Cookie_LeftNavItem","wndiv",24); }break;
	case "gcdiv": if (gcctrl != null) {gcctrl.className="hoverMenuOn";SetCookie("Cookie_LeftNavItem","gcdiv",24); }break;
	case "etdiv": if (etctrl != null) {etctrl.className="hoverMenuOn";SetCookie("Cookie_LeftNavItem","etdiv",24); }break;
	case "esdiv": if (esctrl != null) {esctrl.className="hoverMenuOn";SetCookie("Cookie_LeftNavItem","esdiv",24);  }break;
	case "fbdiv": if (fbctrl != null) {fbctrl.className="hoverMenuOn";SetCookie("Cookie_LeftNavItem","fbdiv",24); }break;
	case "edcdiv": if (edcctrl != null) {edcctrl.className="hoverMenuOn";SetCookie("Cookie_LeftNavItem","edcdiv",24); }break;
	case "eqdiv": if (eqctrl != null) {eqctrl.className="hoverMenuOn";SetCookie("Cookie_LeftNavItem","eqdiv",24); }break;
	case "fesdiv": if (fesctrl != null) {fesctrl.className="hoverMenuOn";SetCookie("Cookie_LeftNavItem","fesdiv",24); }break;
	case "padiv": if (pactrl != null) {pactrl.className="hoverMenuOn";SetCookie("Cookie_LeftNavItem","padiv",24); }break;
	case "lddiv": if (ldctrl != null) {ldctrl.className="hoverMenuOn";SetCookie("Cookie_LeftNavItem","lddiv",24); }break;
}
}

function SetCookie(cookieName,cookieValue,nHours) {
 var today = new Date();
 var expire = new Date();
 if (nHours==null || nHours==0) nHours=1;
 expire.setTime(today.getTime() + 3600000*nHours);
 document.cookie = cookieName+"="+cookieValue+ ";expires="+expire.toGMTString();}
function ReadCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return ""; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return theCookie.substring(ind+cookieName.length+1,ind1);}

function fnTrapKD(btnID, event){btn = MM_findObj(btnID);
	if (document.all)
	{	if (event.keyCode == 13)
		{	event.returnValue=false;event.cancel = true;btn.click();}}
	else if (document.getElementById)
	{	if (event.which == 13)
		{	event.returnValue=false;event.cancel = true;btn.focus();btn.click();}}
	else if(document.layers)
	{	if(event.which == 13)
		{	event.returnValue=false;event.cancel = true;btn.focus();btn.click();}}}

//===================== GET Page QueryString ==========================
function PageQuery(q) {
	if(q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	this.keyValuePairs = new Array();
	if(q) {
	for(var i=0; i < this.q.split("&").length; i++) {
	this.keyValuePairs[i] = this.q.split("&")[i];
	}
}

this.getKeyValuePairs = function() { return this.keyValuePairs; }
this.getValue = function(s) {
for(var j=0; j < this.keyValuePairs.length; j++) {
if(this.keyValuePairs[j].split("=")[0] == s)
return this.keyValuePairs[j].split("=")[1];
}
return false;
}
this.getParameters = function() {
var a = new Array(this.getLength());
for(var j=0; j < this.keyValuePairs.length; j++) {
a[j] = this.keyValuePairs[j].split("=")[0];
}
return a;
}
this.getLength = function() { return this.keyValuePairs.length; } 
}
function queryString(key){
var page = new PageQuery(window.location.search); 
return unescape(page.getValue(key)); 
}
function GetQueryStringValue(key){
if(queryString(key)=='false') 
{
return "";
}else{
return queryString(key);
}
}
function scrollToTop(anchorName){	
	if (window.location.href.toLowerCase().indexOf('#') > -1)
	{		
		window.location = window.location.href.substring(0, window.location.href.toLowerCase().indexOf('#')) + "#" + anchorName;	
	}
	else
	{
		window.location = window.location + "#" + anchorName;
	}
}