var homeImg1=new Image()
homeImg1.src="/common/images/homeImg1.jpg"
var homeImg2=new Image()
homeImg2.src="/common/images/homeImg2.jpg"
var homeImg3=new Image()
homeImg3.src="/common/images/homeImg3.jpg"
var homeImgsm1=new Image()
homeImgsm1.src="/common/images/homeImgsm1.jpg"
var homeImgsm2=new Image()
homeImgsm2.src="/common/images/homeImgsm2.jpg"
var homeImgsm3=new Image()
homeImgsm3.src="/common/images/homeImgsm3.jpg"


/**********************************************************************
TERMS OF USE - EASING EQUATIONS
Open source under the BSD License.
Copyright (c) 2001 Robert Penner
JavaScript version copyright (C) 2006 by Philippe Maegerman
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

   * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
   * Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
   * Neither the name of the author nor the names of contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*****************************************/
OpacityTween.prototype = new Tween();
OpacityTween.prototype.constructor = Tween;
OpacityTween.superclass = Tween.prototype;

function OpacityTween(obj,func,fromOpacity,toOpacity,duration){
	this.targetObject = obj;
	this.init(new Object(),'x',func,fromOpacity,toOpacity,duration);
}
var o = OpacityTween.prototype;
o.targetObject = {};
o.onMotionChanged = function(evt){
	var v = evt.target._pos;
	var t = this.targetObject;
	t.style['opacity'] = v / 100;
	t.style['-moz-opacity'] = v / 100;
	if(t.filters) t.filters.alpha['opacity'] = v;
}

var step=1
function slideit(){
//if browser does not support the image object, exit.
if (!document.images)
return
document.images.slide.src=eval("homeImg"+step+".src")
if (step<3)
step++
else
step=1
//call function "slideit()" every 5 seconds
setTimeout("slideit()",4250)
opacityTween = new
OpacityTween(document.getElementById('sliderImg'),Tween.regularEaseInOut, 10, 100, 1);
opacityTween.start();
setTimeout("fadeOut()",3000)
}

function slideit2(){
//if browser does not support the image object, exit.
if (!document.images)
return
document.images.slide.src=eval("homeImgsm"+step+".src")
if (step<3)
step++
else
step=1
//call function "slideit()" every 5 seconds
setTimeout("slideit2()",4250)
opacityTween = new
OpacityTween(document.getElementById('sliderImg'),Tween.regularEaseInOut, 10, 100, 1);
opacityTween.start();
setTimeout("fadeOut()",3000)
}

function fadeOut(){
opacityTween = new
OpacityTween(document.getElementById('sliderImg'),Tween.regularEaseInOut, 100, 10, 1);
opacityTween.start();
}



function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function validateForm() {
	$("#errorFields").html("");
	error = 0;
	reasonReturnError = 0;
	failureError = 0;
	$(".requiredField").each(function(){
		if(this.value == "") {
			$(this).addClass('errorField');
			error = error+1;
		}
		else {
			$(this).removeClass('errorField');
		}
	});
	$("#reasonReturn input").each(function(){
		if($(this).attr('checked') == false) {
			reasonReturnError = reasonReturnError+1;
		}
	});
	$("#failureMode input").each(function(){
		if($(this).attr('checked') == false) {
			failureError = failureError+1;
		}
	});
	if(error > 0 || reasonReturnError > 4 || failureError > 11) {
		scrollTo(0,0);
		$("#errorFields").append("<p>There was a problem with your submission:</p>");
		if(error > 0 ) {
			$("#errorFields").append("<p>Please complete the fields outlined in red and resubmit.</p>");
		}
		if(reasonReturnError > 4 ) {
			$("#errorFields").append("<p>Please provide a reason for return.</p>");
		}
		if(failureError > 11 ) {
			$("#errorFields").append("<p>Please provide a failure mode.</p>");
		}
		if(honeyPotError > 0 ) {
			$("#errorFields").append("<p>Unspecified Error.</p>");
		}
	}
	else {
		document.frmReturn.submit();
	}
}
function validateForm2() {
	$("#errorFields").html("");
	error = 0;
	reasonReturnError = 0;
	failureError = 0;
	unitsError = 0;
	$(".requiredField").each(function(){
		if(this.value == "") {
			$(this).addClass('errorField');
			error = error+1;
		}
		else {
			$(this).removeClass('errorField');
		}
	});
	$("#unitsMeasure input").each(function(){
		if($(this).attr('checked') == false) {
			unitsError = unitsError+1;
		}
	});
	$("#reasonReturn input").each(function(){
		if($(this).attr('checked') == false) {
			reasonReturnError = reasonReturnError+1;
		}
	});
	$("#failureMode input").each(function(){
		if($(this).attr('checked') == false) {
			failureError = failureError+1;
		}
	});
	if(error > 0 || unitsError > 4 || reasonReturnError > 4 || failureError > 11) {
		scrollTo(0,0);
		$("#errorFields").append("<p>There was a problem with your submission:</p>");
		if(error > 0 ) {
			$("#errorFields").append("<p>Please complete the fields outlined in red and resubmit.</p>");
		}
		if(unitsError > 4 ) {
			$("#errorFields").append("<p>Please identify units of measure.</p>");
		}
		if(reasonReturnError > 4 ) {
			$("#errorFields").append("<p>Please provide a reason for return.</p>");
		}
		if(failureError > 11 ) {
			$("#errorFields").append("<p>Please provide a failure mode.</p>");
		}
	}
	else {
		document.frmReturn.submit();
	}
}

$(document).ready(function(){
	
	$('#searchtextfield').focus(function() {
		searchVal = $(this).val();
		$(this).val('');
	});
	$('#searchtextfield').blur(function() {
		if($(this).val() == "") {
			$(this).val(searchVal);
		}
	});
	
	$('.contactBlock:odd').css({'margin-right': '0px'});
	
	//create language preference cookie
	$('#languageSelect li a').click(function() {
		var conf = confirm("Do you want to save this country/language as your default setting? If so, Click OK.  If not, click Cancel.");
		if(conf == true) {
			var cookieLoc = $(this).attr('href');
			createCookie('dunleelanguagepreference', cookieLoc, 30);
		}
	});
	
});
function doSlides() {
	clearTimeout(slideT);
	nextImg = $('#homeSlides li.actImg').next('li');
	if(nextImg.length < 1) {
		nextImg = $('#homeSlides li:first');
	}
	nextImg.addClass('nextImg');
	$('#homeSlides li.actImg').animate({'opacity': 0}, 700, function() {
		$(this).removeClass('actImg');
		nextImg.removeClass('nextImg').addClass('actImg');
		$(this).css({'opacity': ''});
		setTimeout(doSlides, 5000);
	});
}

//Language Cookie Functions

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		cname=ca[i].substr(0,ca[i].indexOf("="));
		cval=ca[i].substr(ca[i].indexOf("=")+1);
			cname=cname.replace(/^\s+|\s+$/g,"");
		if (cname==name) {
			return unescape(cval);
 		}
	}
	return null;
}

function checkCookie(name) {
	var langcookie=readCookie(name);
	if (langcookie!=null && langcookie!="") {
		window.location = cval;
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
