/* ***************************************
Javascript developed by input 9 interactive
Link: http://www.input9.com

(c) 2010

Author: Bill Hanff

Last Modified: June 14, 2010
*************************************** */


// Global variables
var isFirefox;
var isIE;

var cellSize = 430;
var cellCount = 4;
var currentDiv = 0;
var slideDiv = 'panestrip';
var slideDivButtons = Array('smLinkFacebook', 'smLinkTwitterAt', 'smLinkTwitterPnd', 'smLinkFlickr');
var slideDivPanels = Array('paneFacebook', 'paneTwitterAt', 'paneTwitterPound', 'paneFlickr');

function sniff() {
		
			var ff = "Netscape";
			var ie = "Microsoft Internet Explorer";
			
			isFirefox = ( navigator.appName == ff );
			isIE = (navigator.appName == ie ); 
		}

function fadeIn(objID, opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objID);
		if (opacity < 100) {
			opacity += 10;
			setOpacity(obj, opacity);
			window.setTimeout("fadeIn('"+objID+"',"+opacity+")", 50);
			}
		}
	}

function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.99:opacity; 
	obj.style.filter = "alpha(opacity:"+opacity+")"; // IE/Win
	obj.style.KHTMLOpacity = opacity/100; // Safari<1.2, Konqueror
	obj.style.MozOpacity = opacity/100; // Older Mozilla and Firefox
	obj.style.opacity = opacity/100;	// Safari 1.2, newer Firefox and Mozilla, CSS3
	}
	
	
function showhide(divID){
		var node = document.getElementById(divID);
		if(node.className == "hide"){
			node.className = "show";
			fadeIn(divID, 0);
		} else {
			node.className = "hide";
		}
	}
	
	
function externalLinks() {
			var links = document.getElementsByTagName('a');// Fetch all the anchor elements in the document.
			for (var i = links.length; i != 0; i--) { // Loop through the a elements
				var a = links[i-1]; // Pull out the element for this iteration.
				if (!a.href) continue; // If the element doesn't have an href, skip it.
				if (a.className && a.className.indexOf('external') != -1){
						a.target = '_blank';
				}
			}
		}
	
function init(){
	sniff();
	externalLinks();
	}

function smPos(pos){
	currentDiv = pos;
	for(i=0; i<slideDivButtons.length; i++){
		document.getElementById(slideDivButtons[i]).className = '';
		document.getElementById(slideDivPanels[i]).className = 'hide';
		}
	document.getElementById(slideDivButtons[pos]).className = 'active';
	document.getElementById(slideDivPanels[pos]).className = 'show';
	//$("#"+slideDiv).animate( { marginLeft: '-'+(cellSize*pos)+'px'}, 250);
	//$("#"+slideDiv).css('marginLeft', '-'+(cellSize*pos)+'px');
	$("#"+slideDiv).css('display', 'none');
	$("#"+slideDiv).fadeIn();
	}

function smPosNext(){
	currentDiv++;
	if(currentDiv==cellCount){ currentDiv = 0; }
	smPos(currentDiv);
	}

function smPosLast(){
	if(currentDiv==0){ currentDiv = cellCount; }
	currentDiv--;
	smPos(currentDiv);
	}






	function validateEmail(email) {
		//email = email.toString();
		if (! allValidChars(email)) {  // check to make sure all characters are valid
			return false;
			}
		if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
			return false;
		} else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
			return false;
		} else if (email.indexOf("@") == email.length) {  // @ must not be the last character
			return false;
		} else if (email.indexOf("..") >=0) { // two periods in a row is not valid
			return false;
		} else if (email.indexOf(".") == email.length) {  // . must not be the last character
			return false;
			}
		return true;
		}

	function addMessage(){
				/*
				
				name
				
				
				email
				
				
				fakecomment
				*/
				var errVal = false;
				if(document.getElementById('name').value == ""){
					document.getElementById('lblname').className = 'error';
					$('#name').focus(function() { $('#lblname').removeClass('error'); });
					errVal = true;
				}
				
				var mailVal = document.getElementById('email').value;
				if(mailVal == "" || validateEmail(mailVal)==false){
					document.getElementById('lblemail').className = 'error';
					$('#email').focus(function() { $('#lblemail').removeClass('error'); });
					errVal = true;
				}
				
				if(document.getElementById('fakecommentarea').value == ""){
					document.getElementById('lblcomment').className = 'error';
					$('#fakecommentarea').focus(function() { $('#lblcomment').removeClass('error'); });
					errVal = true;
				}
				
				if(errVal == false){
					procEntry();
				} else {
					document.getElementById('errormessage').innerHTML = 'Please fix the highlighted fields below.';
				}
			}
	
	function allValidChars(email) {
		var parsed = true;
		var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
		for (var i=0; i < email.length; i++) {
			var letter = email.charAt(i).toLowerCase();
			if (validchars.indexOf(letter) != -1)
			continue;
			parsed = false;
			break;
		}
		return parsed;
	}

	
	function procEntry(){
			var processFile = $('#contactform').attr('action');
			
			document.getElementById('messagethanks').className = 'show';
			fadeIn('messagethanks', 0);
			document.getElementById('contactform').className = 'hide';
			
			var params = "name=" + document.getElementById('name').value;
			params += "&company=" + document.getElementById('company').value;
			params += "&position=" + document.getElementById('position').value;
			params += "&email=" + document.getElementById('email').value;
			params += "&phone=" + document.getElementById('phone').value;
			params += "&reason=" + document.getElementById('reason').value;
			params += "&fakemessage=" + document.getElementById('fakecommentarea').value;
			
			//alert(params);
			
			if (window.XMLHttpRequest) {
				req = new XMLHttpRequest();
				req.onreadystatechange = processEntryComplete;
				req.open("POST", processFile, true);
				req.setRequestHeader("Content-length", params.length);
				req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				req.send(params);	
			} else if (window.ActiveXObject) {
				req = new ActiveXObject("Microsoft.XMLHTTP");
				if (req) {
					req.onreadystatechange = processEntryComplete;
					req.open("POST", processFile, true);
					req.setRequestHeader("Content-length", params.length);
					req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
					req.send(params);
				}
			}
	}
	
	function processEntryComplete(){
		if (req.readyState == 4) {
			if (req.status == 200) {
				//document.getElementById('queueItem'+currentProc).className = 'hide';
				//alert('returned!');
			}
		}
	}	






window.onload = init;
