// JavaScript Document
function findPosX(obj){
	var curleft = 0;
	if(obj.offsetParent)
		while(1) 
		{
		  curleft += obj.offsetLeft;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if(obj.offsetParent)
		while(1)
		{
		  curtop += obj.offsetTop;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}

function findWidth(obj){
	xPos = obj.offsetWidth;
	return xPos;
}

function findHeight(obj){
	xPos = obj.offsetHeight;
	return xPos;
}

//Start of drop down script
var subMnus="";
function showMenu(idx,img){
	try{
		hideAllMenu();
		var dv=document.getElementById("sub"+idx);
		if(idx==5)
			dv.style.left=(findPosX(document.getElementById(img))+findWidth(document.getElementById(img)))-findWidth(dv)+"px";
		else
			dv.style.left=findPosX(document.getElementById(img))+"px";
		dv.style.top=127+"px";
		dv.style.visibility="visible";
	}
	catch(e){}
}

//This function is to hide the dropdown menu
function hideAllMenu(){
	try{
		var ar=subMnus.split(',');
		for(i=0;i<ar.length;i++){
			var dv=document.getElementById("sub"+ar[i]);
			dv.style.visibility="hidden";
		}
	}
	catch(e){}
}
//End of drop down script

// This function checks to see if a selection was made in a checkbox group
function cbxSelectionMade(cbx){
	var isGood=false;
	if(cbx.checked){
		isGood=true;
	}
	for(i=0;i<cbx.length && !isGood;i++){
		if(cbx[i].checked){
			isGood=true;
		}
	}
	return isGood;
}

// This function checks to see if a selection was made in a dropdown box
function cboSelectionMade(cbo){
	var isGood=false;
	
	if(cbo.options[cbo.selectedIndex].value!="")
		isGood=true;
		
	return isGood;
}

// This function is used to validate email entries
function isValidEmail(thisEmail){
	var emailexp = /.*\@.*\..*/;
	if (!emailexp.test(thisEmail)) {
		alert("The email you entered is not valid");
		return false;
	} 
	return true;
}

// function checks a date value to make sure its valid
function isValidDate(aDate) {
	var dateexp = /^(\d{1,2}\/\d{1,2}\/\d{4})$/;
    if (!dateexp.test(aDate)) { return false; } 	
	var	temp = new String(aDate), m = 0, d = 0;
	
	for (i=0; i < temp.length; i++){ 
		var str = temp.charAt(i); 
		if (str == "/") { if (m == 0) { m = i; } else { d = i; break; }}			
	}
	
	var month = parseInt(temp.substring(0, m), 10);
	var day = parseInt(temp.substring(m + 1, d), 10); 
	var year = parseInt(temp.substring(d + 1, temp.length), 10);								
					
	switch (month) {
		case 1:	case 3:	case 5:	case 7:	case 8:	case 10: case 12:					
			if ((day < 1) || (day > 31)) {  return false;	} break;
		case 2:		
			if ((year % 400 == 0) || (year % 4 == 0)) {	if ((day < 1) || (day > 29)) {  return false;	} break}
			if ((day < 1) || (day > 28)) {  return false; } break;
		case 4:	case 6:	case 9: case 11:
			if ((day < 1) || (day > 30)) {	 return false; } break;
		default: return false;			
	}		
	return true;		
}


function MM_swapImgRestore() { //v3.0
  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() { //v3.0
  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() { //v3.0
  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];}
}

// This function is used to pop up windows
function popUpa(c,w,h){
	window.open(c,'','width='+w+',height='+h+',scrollbars=1');
}


function writeSlideShow(dvSwf,fvars)
{
	var str='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="940" height="356" id="slideshowswf" align="middle">';
	str+='<param name="allowScriptAccess" value="sameDomain" />';
	str+='<param name="menu" value="false" />';
	str+='<param name="wmode" value="transparent" />';
	str+='<param name="flashvars" value="'+fvars+'" />';
	str+='<param name="allowFullScreen" value="false" />';
	str+='<param name="movie" value="slideshow.swf" />';
	str+='<param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />';
	str+='<embed src="slideshow.swf" quality="high" bgcolor="#ffffff" width="940" height="356" name="slideshowswf" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" menu="false" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'+fvars+'"/>';
	str+='	</object>';
	document.getElementById(dvSwf).innerHTML=str;
}

function popCalcWindow(url, wname){
	window.open(url,wname,"width=450,height=715,scrollbars=1,resizable=1");
	return false;
}

function popWindow(url,wname,w,h){
	window.open(url,wname,"width="+w+",height="+h);
	return false;
}


/*       MAIN SLIDE SHOW FUNCTIONS     */
var mainSlides=null;
var mainSlideCurrent=0;
var mainSlideChanging=false;
var mainSlideTimer;
var mainSlideInterval=6000;
var mainSlideFadeInterval=500;

function nextMainSlide(){
	if(mainSlideChanging){
		return false;
	}
	if(mainSlides){
		if(mainSlideCurrent>=(mainSlides.length-1)){
			gotoMainSlide(0);
		}
		else{
			gotoMainSlide(mainSlideCurrent+1);
		}		
	}
}

function gotoMainSlide(idx){
	if(mainSlideChanging){
		return false;
	}
	if(idx<mainSlides.length && idx>(-1)){
		// stop timer
		mainSlideTimerStop();
		// set changing flag to true
		mainSlideChanging=true;
		// set background image of slide image td to next slide
		$("#tdSlideImg").css("background-image", "url("+mainSlides[idx].src+")");
		$("#slideLink").attr("href",""+mainSlideLinks[idx]+"");
		// fade out green arrow and box
		$("#slideWrap"+mainSlideCurrent).fadeOut(mainSlideFadeInterval);
		// Show the overlay
		$("#slideOverlay"+mainSlideCurrent).css('display','block');
		$("#slideGreenArrow").fadeOut(mainSlideFadeInterval,function() {
			// the slide has now faded out
			// setup the green arrow position 
			var tdpos=$("slideTD"+idx).offset();
			var w=$("#tdSlideImg").width();
			var t=((mainSlides.length-idx)*72);
			$("#slideGreenArrow").css("margin","-"+t+"px 0 0 677px");
			// Hide overlay
			$("#slideOverlay"+idx).css('display','none');
			// fade in green arrow and box
			$("#slideWrap"+idx).fadeIn(mainSlideFadeInterval);
			$("#slideGreenArrow").fadeIn(mainSlideFadeInterval, function() {mainSlideChanging=false;mainSlideTimerStart();});
		});
		// set current slide to passed index
		mainSlideCurrent=idx;
		// fade out old slide image
		$("#imgHomeSlide").fadeOut(mainSlideFadeInterval*2,function() {
			// change the image src to the new slide
			$("#imgHomeSlide").attr("src",mainSlides[mainSlideCurrent].src);
			// set the main image alpha
			$("#imgHomeSlide").fadeIn();
		});
	}
}

function mainSlideTimerReset(){
	mainSlideTimerStop();
	mainSlideTimerStart();
}

function mainSlideTimerStart(){
	mainSlideTimer=setTimeout(nextMainSlide,mainSlideInterval);
}

function mainSlideTimerStop(){
	clearTimeout(mainSlideTimer);
}



function validateNewFeed(){
	if(document.feedbackFORM.fbData.value == ""){
		alert("Please enter your comments");
		return false;
	}
	else{
		if(document.feedbackFORM.imageVerify.value == imgverifyconfirmtxt){
		return true;
		}else{
		alert("The number you have entered does not match the number in the image");
		return false;
		}
	}
}


