﻿function elfadein(el){
	Effect.Appear(el, { duration : 2.0 });
}

function elfadeout(el){
	Effect.Fade(el, { duration : 2.0 });
}

function testfade(tp){
	switch (tp){
		case "in":
			elfadein('testimonialtitle');
			elfadein('testimonialsig');
		break;
		case "out":
			elfadeout('testimonialtitle');
			elfadeout('testimonialsig');
		break;
	}
}

// NEWS BLURB SWAPPING

var curnews = 0;

function newsswap(){
	fadeobj ('newsttl',2500, "out");
	fadeobj ('newsdt',2500, "out");
	fadeobj ('newsblurb',2500, "out");
	fadeobj ('newspic',2500, "out");
	curnews = document.getElementById('newsid').value;
	setTimeout("doAjaxNews()",2500);
}

function doAjaxNews(){
	var uri = '/newsswapper.js.php?n=' + curnews;
	new Ajax(uri,{onComplete: newsswapfinish}).request();
}
 
function newsswapfinish(request){
	eval(request);
	fadeobj ('newsttl',2500, "in");
	fadeobj ('newsdt',2500, "in");
	fadeobj ('newsblurb',2500, "in");
	fadeobj ('newspic',2500, "in");
	setTimeout('newsswap()',delay);
}

// TESTIMONIAL SWAPPING

function testimonialswap(){

	fadeobj ('testimonialholder',2500, "out");
//	fadeobj ('testimonialtitle',2500, "out");
//	fadeobj ('testimonialshort',2500, "out");
//	fadeobj ('testimonialsig',2500, "out");
//	fadeobj ('testimonialcompany',2500, "out");
//	fadeobj ('testimonialpic',2500, "out");
	setTimeout("doAjaxTestimonial()",2500);
//	elfadeout('testimonialtitle');
//	elfadeout('testimonialsig');
//	new Ajax('/testimonials.js.php',{onComplete: testimonialswapfinish}).request();
//	return false;

//	new Ajax.Updater('testimonialtitle', '/testimonials.js.php', {onComplete:function(){ alert('Got it') },asynchronous:true, evalScripts:true});
 // this will evaluate any scripts in <script></script> blocks. Also it will hightlight mydiv on complete.

}

function doAjaxTestimonial(){
	new Ajax('/testimonials.js.php',{onComplete: testimonialswapfinish}).request();
}

function testimonialswapfinish(request){
	alert(request);
	eval(request);

	alert('ok');
//	sIFR.replace(tahoma, {
//		selector: 'h4'
//		,wmode: 'transparent'
//	    ,css: {
//	      '.sIFR-root': { 'color': '#FFFFFF', 'font-size': '16px', 'text-align': 'right' }
//	    }
//		,filters: {
//	    	DropShadow: {
//				distance: 1
//				,color: '#000000'
//				,strength: 2
//			}
//		}
//	});

	fadeobj ('testimonialholder',2500, "in");
//	fadeobj ('testimonialtitle',2500, "in");
//	fadeobj ('testimonialshort',2500, "in");
//	fadeobj ('testimonialsig',2500, "in");
//	fadeobj ('testimonialcompany',2500, "in");
//	fadeobj ('testimonialpic',2500, "in");
	setTimeout('testimonialswap()',delay);
}

function fadeobj (obj,len, dir){
	var fx1 = new Fx.Style(obj, 'opacity', {
		duration: len, 
		transition: Fx.Transitions.Quart.easeInOut
	});
	switch (dir){
		case "in":
			fx1.start(0,1); 
		break;
		case "out":
			fx1.start(1,0); 
		break;
	}
}

//	var dv;
//	var im;
//	var newimg;
//	var imgw;
//	var imgh;
//	var divw;
//	var divh;
//	
//	function swapimage(newimg,imgw,imgh,divw,divh,txt){
//		fadeobj ('fadediv',500, "out")
//		cmd = "swapimage_swap('" + newimg + "'," + imgw + "," + imgh + "," + divw + "," + divh + ",'" + txt + "')";
//	//prompt('query',cmd);
//		setTimeout(cmd,600);
//	}
//	
//	function swapimage_swap(newimg,imgw,imgh,divw,divh,pgtxt){
//	//alert("OK");
//		var pic = document.getElementById('mainpic');
//		var tx = document.getElementById('txtdiv');
//		var dv = document.getElementById('picdiv');
//	//	var dv2 = document.getElementById('picdiv2');
//	//	alert ("img = " + imgw + "x" + imgh + "\ndiv = " + divw + "x" + divh);
//	
//		pic.src = newimg;
//		pic.width = imgw;
//		pic.height = imgh;
//	//	alert(tx);
//	//	alert(pgtxt);
//		tx.innerHTML = pgtxt;
//		dv.style.width = divw;
//		dv.style.height = divh;
//	//	dv2.style.width = divw;
//	//	dv2.style.height = divh;
//		setTimeout("swapimage_finish()",1000);
//	}
//	
//	function swapimage_finish(){
//	//alert("OK 2");
//		fadeobj ('fadediv',500, "in")
//	}

function swapimage(newimg, imgw, imgh, divw, divh, txt) {
	imgw = (typeof(imgw) == 'undefined') ? 300 : imgw;
	imgh = (typeof(imgh) == 'undefined') ? 300 : imgh;
	divw = (typeof(divw) == 'undefined') ? 300 : divw;
	divh = (typeof(divh) == 'undefined') ? 300 : divh;
	txt = (typeof(txt) == 'undefined') ? '' : txt;
	
	$('#picdiv').fadeOut('slow', function() {
		$('#mainpic').attr('src', newimg).attr('alt', txt).css({'width' : imgw, 'height' : imgh});
		$('#txtdiv').html(txt);
		$('#mainpiclink').attr('href', newimg);
		$(this).css('width', divw).css('height', divh).fadeIn('slow');
	});
}

// Trim white space
function trim(s){
	return s.replace(/^\s*(.*?)\s*$/,"$1")
}

// Form validation
function checkcontents(tp,snd,req,arr){
	// Trim the sent value
	if(tp != 'checkbox') {
		snd = trim(snd.value);
	}
	
	// Required field?
	req = typeof(req) != 'undefined' ? req : false;
	
	// Check required field
	if(req && snd == "") {
		alert('Please fill in the required fields.');
		return false;
	}
	
	// Which type of check?
	switch (tp){
		case "text":
			if(snd != "") {
				var digits = /\d/; // at least one digit?
				if(digits.test(snd)) {
					alert('Please use only text, no numbers.');
					return false;
				}
			}
		break;
		case "checkbox":
			if(req) {
				var checked = false;
				for(var i = 0; i < arr.length; i++) {
				    if(document.getElementById(snd + '[' + arr[i] + ']').checked) {
				        checked = true;
				    }
				}
				if(!checked) {
					alert('Please check at least one item.');
					return false;
				}
			}
		break;
		case "number":
			if (snd != ""){
				var digitonly = /(^\-{0,1}\d+\.\d+$)|(^\-{0,1}\d+$)/;
				if (!digitonly.test(snd)){
					alert('Please use only numbers, no text.');
					return false;
				}
			}
		break;
		case "date":
			if (snd != ""){
				var dateformat = /^\d{1,2}(\-)\d{1,2}\1\d{4}$/;
				if (!dateformat.test(snd)){
					alert('Please enter a valid date (e.g. 01-01-2007).');
					return false;
				}
			}
		break;
		case "time":
			if (snd != ""){
				var timeformat = /^\d{1,2}(\:)\d{2}\1\d{2}$/;
				if (!timeformat.test(snd)){
					alert('Please enter a valid time (e.g. 11:25:45).');
					return false;
				}
			}
		break;
		case "email":
			if (snd != ""){
				var emailformat = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
				if (!emailformat.test(snd)){
					alert('Please enter a valid email address (e.g. example@domain.com).');
					return false;
				}
			}
 		break;
		case "zip":
			if (snd != ""){
				//var digitonly = /(^\d{5}$)|(^\d{5}\-\d{4}$)/;
				//if (!digitonly.test(snd)){
				//	alert('Please enter a valid zip code (e.g. 12345 or 12345-6789).');
				//	return false;
				//}
			}
		break;
		case "phone":
			if (snd != ""){
				//var phone = /^\d{3}\-\d{3}\-\d{4}$/;
				//if (!phone.test(snd)){
				//	alert('Please enter a valid phone number (e.g. 555-555-5555).');
				//	return false;
				//}
			}
		break;
		case "file":
			if (snd != ""){
				var file = snd.split(".");
				if (!(file[1] == 'doc' || file[1] == 'pdf' || file[1] == 'txt' || file[1] == 'docx' || file[1] == 'rtf')){
					alert('File types allowed include: .doc, .docx, .txt, .rtf, and .pdf.');
					return false;
				}
			}
		break;
	}
	return true;
}

function move_box(an, box) {
  var cleft = 125;
  var ctop = -300;
  var obj = an;
  while (obj.offsetParent) {
    cleft += obj.offsetLeft;
    ctop += obj.offsetTop;
    obj = obj.offsetParent;
  }
  box.style.left = cleft + 'px';
  ctop += an.offsetHeight + 8;
  if (document.body.currentStyle &&
    document.body.currentStyle['marginTop']) {
    ctop += parseInt(
      document.body.currentStyle['marginTop']);
  }
  box.style.top = ctop + 'px';
}

function show_hide_box(an, width, height, borderStyle) {
  var href = an.href;
  var boxdiv = document.getElementById(href);

  if (boxdiv != null) {
    if (boxdiv.style.display=='none') {
      move_box(an, boxdiv);
      boxdiv.style.display='block';
    } else
      boxdiv.style.display='none';
    return false;
  }

  boxdiv = document.createElement('div');
  boxdiv.setAttribute('id', href);
  boxdiv.style.display = 'block';
  boxdiv.style.margin = '0 auto';
  boxdiv.style.position = 'absolute';
  boxdiv.style.width = width + 'px';
  boxdiv.style.height = height + 'px';
  boxdiv.style.border = borderStyle;
  boxdiv.style.backgroundColor = 'transparent';

  var contents = document.createElement('iframe');
  contents.scrolling = 'no';
  contents.frameBorder = '0';
  contents.style.width = width + 'px';
  contents.style.height = height + 'px';
  contents.src = href;

  boxdiv.appendChild(contents);
  document.body.appendChild(boxdiv);
  move_box(an, boxdiv);

  return false;
}