// JavaScript Document

//VARIABLES
var slideTime = 400;
var shortHeight = "130";


$(document).ready(function() {
						   
	$('#featLeft').hover(function() {
		if(typeof document.body.style.maxHeight != "undefined") {
			$('#btn_play').css({ backgroundPosition: '115px 0'  });
		}
	}, function() {
		if(typeof document.body.style.maxHeight != "undefined") {
			$('#btn_play').css({ backgroundPosition: '0 0'  });
		}
	});
	
	
	//SET ACTIVE STATE
	$('.active').children('a').css({ backgroundPosition: '0 -32px' });

	
	
	//DROPDOWN
	$('.subNav').hide();
	
	$('#mainNav ul').children('li').hover(function() {
		if (!$(this).hasClass('active')) {
			$(this).children('a').css({ backgroundPosition: '0 -32px' });	
		}
		
		//SHOW DROPDOWN
		$(this).children('.subNav').slideDown(400);
	}, function() {
		if (!$(this).hasClass('active')) {
			$(this).children('a').stop(true, true).css({ backgroundPosition: '0 0' });	
		}
		
		//HIDE DROPDOWN
		$(this).children('.subNav').stop(true, true).slideUp(400);
	});
	
	
	$('.subNav ul').children('li').hover(function() {
		thisIndx = $(this).parent('ul').children('li').index($(this));
		totalItems = $(this).parent('ul').children('li').length - 1;
		
		
		if (thisIndx == 0) {
			$(this).css({ backgroundPosition: '0 -31px' });		
		}else if (thisIndx == totalItems) {
			$(this).css({ backgroundPosition: '0 -40px' });		
		}else {
			$(this).css({ backgroundPosition: '0 -25px' });	
		}
	}, function() {
		$(this).css({ backgroundPosition: '0 0' });		
	});
	
	
	
	
	/* CASE STUDY */
	$('.csMore').hide();
	
	$('.csNav1').bind({
		click: function() {
			if (!$(this).hasClass('csMore')) {
				$(this).parent().parent().parent().prev('.csMore').slideDown(400);
				$(this).addClass('csMore');	
			}else {
				$(this).parent().parent().parent().prev('.csMore').slideUp(400);
				$(this).removeClass('csMore');		
			}
			
			
			return false;
		},
		mouseenter: function() {
			if (!$(this).hasClass('csMore')) {
				$(this).css({ backgroundPosition: '0 -32px' });	
			}else {
				$(this).css({ backgroundPosition: '0 -96px' });		
			}
		},
		mouseleave: function(){
			if (!$(this).hasClass('csMore')) {
				$(this).css({ backgroundPosition: '0 0' });	
			}else {
				$(this).css({ backgroundPosition: '0 -64px' });		
			}	
		}
	});

//POPUP WINDOW AND CLOSE
function popuponclick(openUrl) {
	my_window = window.open(openUrl,
	"_blank","status=1,scrollbars=1,toolbar=0");
}

function closepopup() {
	if(false == my_window.closed) {
		my_window.close();
	}else {
		alert('Window already closed!');
	}
}



//VALIDATION FUNCTIONS
function validateEmpty(fld, efld, emptyFiller, errorMsg) {
    if (fld.value == emptyFiller || fld.value == "") {
        emptyFields=true;
		error += errorMsg;
		document.getElementById(efld).style.color="#d20017";
    } else {
		document.getElementById(efld).style.color="#000000";
    }
}

function validateCompare(fld1, efld1, fld2, efld2) {
	if (fld1.value != '' || fld2.value != '') {
		if (fld1.value != fld2.value) {
			compareFields=true;
			document.getElementById(efld1).style.color="#d20017";
			document.getElementById(efld2).style.color="#d20017";
		} else {
			document.getElementById(efld1).style.color="#000000";
			document.getElementById(efld2).style.color="#000000";
		}	
	}
}

function trim(s){
  return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld, efld, emptyFiller, errorMsg) {
   // var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
	
   	if (fld.value == emptyFiller) {
		 document.getElementById(efld).style.color="#d20017";
		 error += errorMsg;
	}else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        document.getElementById(efld).style.color="#d20017";
		 error += "Invalid E-mail Address.<br />";
    } else if (fld.value.match(illegalChars)) {
        document.getElementById(efld).style.color="#d20017";
		 error += "Invalid E-mail Address.<br />";
    } else {
        document.getElementById(efld).style.color="#000000";
    }
}

function validateNumeric(field, efld, emptyFiller) {
	var check = true;
	var value = field.value; //get characters
	//check that all characters are digits, ., -, or ""
	for(var i=0;i < field.value.length; ++i) {
	   var new_key = value.charAt(i); //cycle through characters
	   if(((new_key < "0") || (new_key > "9")) &&
			!(new_key == ""))
	   {
			check = false;
			break;
	   }
	}
	
	//apply appropriate colour based on value
	if(!check || value == "") {
	   numericError = true;
	   document.getElementById(efld).style.color="#d20017";
	}
	else {
	   document.getElementById(efld).style.color="#000000";
	}
}


function validateRadio(radioGroup) {
	myOption = -1;
	for (i=radioGroup.length-1; i > -1; i--) {
		if (radioGroup[i].checked) {
			myOption = i; i = -1;
		}
	}
	if (myOption == -1) {
		radioError = true;
	}
}
                  
function validateCheck(fld, efld, emptyFiller) {
    if (!fld.checked) {
        unChecked=true;
		document.getElementById(efld).style.color="#d20017";
    } else {
		document.getElementById(efld).style.color="#000000";
    }
}
});
