function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function removeEvent( obj, type, fn )
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}

addEvent(window, 'load', getFaq);

//FAQ Page
function viewAnswer(e) {
	list = e.parentNode.parentNode;
	listElements = list.getElementsByTagName('dd');
	for(i = 0; i < listElements.length; i++) {
		if(listElements[i].style.display == "none")
			listElements[i].style.display = "block";
		else
			listElements[i].style.display = "none";
	}
	if(e.className.match("view"))
		e.className = "question close";
	else if(e.className.match("close"))
		e.className = "question view";
}


function getFaq() {
	if (document.getElementById('faq')) {
		var links = document.getElementById('faq').getElementsByTagName('a');
		for (var i = 0; i < links.length; i++) {
    		if (links[i].className.match("question")) {
				// Attach function to onclick event
				links[i].className = "question view";
				links[i].onclick = function() {
		        	viewAnswer(this);
					return false;
      			}
			}
		}
		var answers = document.getElementById('faq').getElementsByTagName('dd');
		for(i=0; i<answers.length; i++) {
			answers[i].style.display = "none";
		}
	}
}

function collapseAllFaq() {
	if (document.getElementById) {
		var links = document.getElementsByTagName('a');
		for (var i = 0; i < links.length; i++) {
    		if (links[i].className.match("question")) {
				links[i].className = "question view";
				list = links[i].parentNode.parentNode;
				listElements = list.getElementsByTagName('dd');
				for(j = 0; j < listElements.length; j++)
					listElements[j].style.display = "none";
			}
		}
	}
}

function expandAllFaq() {
	if (document.getElementById) {
		var links = document.getElementsByTagName('a');
		for (var i = 0; i < links.length; i++) {
    		if (links[i].className.match("question")) {
				links[i].className = "question close";
				list = links[i].parentNode.parentNode;
				listElements = list.getElementsByTagName('dd');
				for(j = 0; j < listElements.length; j++)
					listElements[j].style.display = "block";
			}
		}
	}
}

//show modal timeline window
function modalWin() {
	if (window.showModalDialog) {
		window.showModalDialog("timeline.html","Timeline of a Worker","dialogHeight: 500px; dialogWidth: 750px; dialogTop: px; dialogLeft: px; edge: sunken; center: Yes; resizable: No; status: No; unadorned: No;");
	} else {
		window.open('timeline.html','Timeline of a Worker', 'height=500,width=750,toolbar=no,directories=no,status=no, menubar=no,scrollbars=no,resizable=no ,modal=yes');
	}
} 

//contact form validation
function checkInput()
{

	if (document.contactform.name.value == ""){
		alert("Please enter your Name");
		document.contactform.name.focus();
		return;
	}
		
	if (document.contactform.company.value == ""){
		alert("Please enter your Company Name");
		document.contactform.company.focus();
		return;
	}
	
	if (document.contactform.email.value == ""){
		alert("Please enter your Email Address");
		document.contactform.email.focus();
		return;
	}
	
	if (document.contactform.email.value!=""){
		var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
		var check=/@[\w\-]+\./;
		var checkend=/\.[a-zA-Z]{2,4}$/;  
		if(((document.contactform.email.value.search(exclude) != -1) || (document.contactform.email.value.search(check)) == -1) || (document.contactform.email.value.search(checkend) == -1)){              
			alert("Invalid Email address!");   
			document.contactform.email.focus()
			return;   
		}       
	}
	
	if (document.contactform.phone.value == "0"){
		alert("Please enter a phone number");
		document.contactform.phone.focus();
		return;
	}			
	
	if (document.contactform.country.value == ""){
		alert("Please enter your Country");
		document.contactform.country.focus();
		return;
	}
	
	if (document.contactform.comments.value == ""){
		alert("Please enter your comments");
		document.contactform.comments.focus();
		return;
	}
	
	//alert("All good");
	document.contactform.submit();
}