//****************************************************************
//****************************************************************
//	Embroidery Designs Download
//	Copyright 2009
//
//****************************************************************
//****************************************************************
var browserName = navigator.appName;
var browserVer = parseInt(navigator.appVersion);
var version = "no";

if (browserName == "Netscape" && browserVer >=3) version = "yes";
if (browserName == "Microsoft Internet Explorer" && browserVer >=4) version = "yes";

//****************************************************************
//  Form Validation
//****************************************************************
function ValidateForm(FormName) 
{ 
  // Check if neither Format nor Size were selected
  if ((FormName.Size.value == 'NoSelection') && (FormName.Format.value == 'NoSelection')){
  alert("Please select a Size and Format!");
  return false;
  }
  // Check if Size has been selected
  if (FormName.Size.value == 'NoSelection'){
  alert("Please select a Size!");
  return false;
  }
  // Check if Format has been selected
  if (FormName.Format.value == 'NoSelection'){
  alert("Please select a Format!");
  return false;
  }
  // If Format and Size have been selected
  return true;
}

//****************************************************************
//	Popup
//****************************************************************
function popup(mylink, windowname) 
{ 
if (! window.focus)return true; 
var href; 
if (typeof(mylink) == 'string') 
	href=mylink; 
else 
	href=mylink.href; 
	var newWin = window.open(href, windowname, 'width=625,height=475,left=150,top=150,scrollbars=yes,resizable=yes'); 
	newWin.focus()
	return false; 
} 

//****************************************************************
//	picSwitch
//****************************************************************
function picSwitch(name) {
var pic = eval( "document." + name );
if (pic) {
	if (pic.src.indexOf("c.gif") > -1) {
		// Don't change
		}
	else if (pic.src.indexOf("a.gif") == -1) {
		pic.src = pic.src.substring(0,pic.src.length-5)+"a.gif"
		} 
	else {
		pic.src = pic.src.substring(0,pic.src.length-5)+"b.gif"
		}
	}
}

//****************************************************************
//	FAQ Accordion Menu
//****************************************************************
if (document.getElementById){
document.write('<style type="text/css">\n')
document.write('span.faq_answer{display: none;}\n')
document.write('</style>\n')
}

function ShowLevel(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
		if(el.style.display == "block"){
				el.style.display = "none";
		}else{
			el.style.display = "block";
		}
	}
}

//****************************************************************
//	Toggle Background Color of Element Between White and #99CCFF
//****************************************************************
function toggleBgColor(element)
{
  var style2 = element.style;
  style2.backgroundColor = style2.backgroundColor? "":"#99CCFF";
  document.body.style.cursor = document.body.style.cursor? "":"hand";
}

//****************************************************************
//	SlideShow
//****************************************************************
function RunSlideShow()
{

// PicAddys contains string of picture URLs separated by colons
// Delete colon at end of string
PicAddys = PicAddys.substring(0,PicAddys.length-1);
// Split into an array
var images = PicAddys.split(":");
images.sort();

var SlideShowHeight = 180;
var SlideShowWidth = 240;
var imageTimeout = 2000;  // milliseconds

/*
// Alternate Method
var images = new Array(
'Pic1.gif',
'Pic2.gif',
'Pic3.gif'
);
*/

//Specify full path, needed due to dynamic nature of http:// vs. https://
var site = window.location.protocol + '//' + window.location.hostname;
var ImagesToLoad = images.length;
var nextImage = 1;
    
// Preload images (while default image is being displayed)
var ResizedImage = new Array();
for(var i=0; i<images.length; i++) {
  ResizedImage[i] = new Image();
  ResizedImage[i].onload=ImageLoaded;  //Will call function once for each image 
  ResizedImage[i].src = site.concat(images[i]); 
  }

function ImageLoaded(){
  ImagesToLoad--;
  if (ImagesToLoad == 0){
    // All Images now preloaded
    for(var i=0; i<images.length; i++) {
      var OriginalPictureHeight = ResizedImage[i].height;
      var OriginalPictureWidth = ResizedImage[i].width;
      var HeightScaleFactor = SlideShowHeight / OriginalPictureHeight;
      var WidthScaleFactor = SlideShowWidth / OriginalPictureWidth;
      if ((HeightScaleFactor >= 1) && (WidthScaleFactor >= 1)){
        // Image is smaller that screen, maintain original image size
        var NewPictureHeight = Math.floor(OriginalPictureHeight);
        var NewPictureWidth = Math.floor(OriginalPictureWidth);
        var OffsetLeft = Math.floor((SlideShowWidth-OriginalPictureWidth)/2);
        var OffsetTop = Math.floor((SlideShowHeight-OriginalPictureHeight)/2);
      }else{
        // Image is larger than screen, shrink image to fit screen
        if (HeightScaleFactor <= WidthScaleFactor){
          var NewPictureHeight = Math.floor(OriginalPictureHeight * HeightScaleFactor);
          var NewPictureWidth = Math.floor(OriginalPictureWidth * HeightScaleFactor);
          var OffsetLeft = Math.floor((SlideShowWidth-NewPictureWidth)/2);
          var OffsetTop = 0;
        }else{
          var NewPictureHeight = Math.floor(OriginalPictureHeight * WidthScaleFactor);
          var NewPictureWidth = Math.floor(OriginalPictureWidth * WidthScaleFactor);
          var OffsetLeft = 0;
          var OffsetTop = Math.floor((SlideShowHeight-NewPictureHeight)/2);
        }
      }
      ResizedImage[i].style.position = 'absolute';
      ResizedImage[i].style.visibility = 'hidden';
      ResizedImage[i].style.height = NewPictureHeight + 'px';
      ResizedImage[i].style.width = NewPictureWidth + 'px';
      ResizedImage[i].style.marginLeft = OffsetLeft + 'px';
      ResizedImage[i].style.marginTop = OffsetTop + 'px';
      ResizedImage[i].style.backgroundColor = '#FFFFFF';
      ResizedImage[i].style.zIndex = 1;
    }
    // Make first slideshow image visible
    ResizedImage[0].style.visibility = 'visible';
    // Get DIV Element, eliminate children, set slideshow display dimensions
    var el = document.getElementById('home_slideshow');
    while (el.firstChild) { el.removeChild(el.firstChild); }
    el.style.height = SlideShowHeight + 'px';
    el.style.width = SlideShowWidth + 'px';
    // Add images to show
    for(var i=0; i<images.length; i++) {
      el.appendChild(ResizedImage[i]);
    }
    // Start Slideshow fading
    window.setTimeout(startFading, imageTimeout);
  }
}

function startFading() {
	var el = document.getElementById('home_slideshow').childNodes[nextImage];
	setOpacity(el, 0);
	el.style.visibility = 'visible';
	el.style.zIndex = 2;
	FadeInNextImage(el, 0);
	nextImage = (nextImage < images.length-1) ? nextImage + 1 : 0;
}

function setOpacity(el, opacity) {
	//  Specify opacity for different browsers
	opacity /= 100;
	// FireFox
	el.style.MozOpacity = opacity;
	// Internet Explorer
	el.style.filter = "alpha(opacity=" + (opacity*100) + ")";
	// Everything Else
	el.style.opacity = opacity;
}

function FadeInNextImage(el, currentOpacity) {
  var prevEL = el.previousSibling ? el.previousSibling : el.parentNode.lastChild;
	currentOpacity = currentOpacity + 5;
	if (currentOpacity < 100) {
    setOpacity(el, currentOpacity);
    setOpacity(prevEL, 100-currentOpacity);
    window.setTimeout(function() { FadeInNextImage(el, currentOpacity); }, 50);
	}else{
		setOpacity(el, 100);
    setOpacity(prevEL, 0);
		el.style.zIndex = 1;
		prevEL.style.visibility = 'hidden';
		window.setTimeout(startFading, imageTimeout);
	}
}

}  

//****************************************************************
// Disable right mouse clicks 
//****************************************************************
var message="";
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if 
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers) 
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
//document.oncontextmenu=new Function("alert(message);return false")  //displ msg
document.oncontextmenu=new Function("return false")  // silent


//****************************************************************
// Resize Image
//****************************************************************
function ReSizeImg(image){
  if (image == undefined || image == null) return false; 
  maxsize = 100;
  if (image.width > image.height) {
    if (image.width > maxsize) image.width = maxsize;
  } else {
    if (image.height > maxsize) image.height = maxsize;
  }
}
