$(document).ready(function() {

// LIGHTBOX EFFECT
	// To use the lightbox function, simplay add the class 'lightbox' to the link to the image.
	$('a.lightbox').lightBox();

// SORTABLE TABLES
	// To use the table sorting function, apply the class 'sortable' to the table in question. Ensure that all the TH elements are in a THEAD block
	// and that all the table's data rows are contained within a TBODY block for this to work.
	$('table.sortable').tablesorter();
	
// WINDOW POP UP
	$("a.popup").click( function() {
        window.open( $(this).attr('href') );
        return false;
    });
	
//Document table controls
	$(".recommended td:not(:first-child)").addClass("align");
	$(".recommended td:first-child").addClass("document");
	$(".recommended tr:first-child").addClass("recommended-header");
	
// Partners list controls
	$(".partners-list td:not(:first-child)").addClass("align");
	$(".partners-list td:first-child").addClass("document");
	$(".partners-list tr:first-child").addClass("partners-headers");
	
//Russian table controls
	$(".translated td:nth-child(2)").removeClass("align");
	$(".translated td:last-child").addClass("align");
	$(".translated td:first-child").addClass("ru-document");
	
	
//Show/Hide by industry sector
	$(".event td:first-child").addClass("title2");
	$(".event td:nth-child(2)").addClass("width");
	$(".event td:nth-child(3)").addClass("width2");
	
	$(".event th:first-child").addClass("title2");
	$(".event th:nth-child(2)").addClass("width");
	$(".event th:nth-child(3)").addClass("width2");
	

	$("#all").addClass("nolink");
	
	$("#all").click(function () {
		$("table.event tr").removeClass("background");		
		$("table.event:first tr:even").addClass("background");
		$("table.event:last tr:even").addClass("background");
		$(".sectors a").removeClass("nolink");
		$("table tr").show();
		$("#all").addClass("nolink");
	});
	
	$("#transmission").click(function () {					  
		$(".sectors a").removeClass("nolink");
		$("#transmission").addClass("nolink");
		$("table tr").hide();
		$("table tr.headers").show();
		$("table tr.all").show();
		$("table tr.trans-distrib").show();
		$("table tr.transmission").show();
	});
	
	$("#distribution").click(function () {					  
		$(".sectors a").removeClass("nolink");
		$("#distribution").addClass("nolink");
		$("table tr").hide();
		$("table tr.headers").show();
		$("table tr.all").show();
		$("table tr.trans-distrib").show();
		$("table tr.distribution").show();
	});
	
	$("#producer").click(function () {
		$(".sectors a").removeClass("nolink");
		$("#producer").addClass("nolink");
		$("table tr").hide();
		$("table tr.headers").show();
		$("table tr.all").show();
		$("table tr.proc-prod").show();
		$("table tr.producer").show();
	});
	
	$("#processor").click(function () {
		$(".sectors a").removeClass("nolink");
		$("#processor").addClass("nolink");
		$("table tr").hide();
		$("table tr.headers").show();
		$("table tr.all").show();
		$("table tr.proc-prod").show();
		$("table tr.processor").show();
	});
	
	$("#inter").click(function () {
		$(".sectors a").removeClass("nolink");
		$("#inter").addClass("nolink");
		$("table tr").hide();
		$("table tr.headers").show();
		$("table tr.all").show();
		$("table tr.inter").show();
	});
	
	$("#equip").click(function () {
		$(".sectors a").removeClass("nolink");
		$("#equip").addClass("nolink");
		$("table tr").hide();
		$("table tr.headers").show();
		$("table tr.all").show();
		$("table tr.equip").show();	
	});
	

// For Services Tables
	
	$("#firsttable").hide();
	$("#secondtable").hide();

	$("#equipments").change(function () {	
		$("#secondtable").hide();	
		$("#firsttable").show();
		var str = $("#equipments option:selected").val();		
		$("tr").not("."+str).hide();	
		$("thead tr").show();	
		$("."+str).show();
	});

	
	$("#services").change(function () {
		$("#firsttable").hide();	
		$("#secondtable").show();
		var str = $("#services option:selected").val();
		$("tr").not("."+str).hide();		
		$("thead tr").show();
		$("."+str).show();
	});

	$("#showAll2").click(function(){
		$("#secondtable tr").show();	
		$("#firsttable").hide();
	});
								  
	$("#showAll1").click(function(){
		$("#secondtable").hide();	
		$("#firsttable tr").show();
	});
	

	
});

function hideQuestion() {
	var techquestion;
	techquestion = document.getElementById('techcheck');  	
	techquestion.style.display = "none";
}

function showQuestion() {
	var techquestion;
	techquestion = document.getElementById('techcheck'); 
	if(techquestion.style.display == "none") 
		techquestion.style.display = "block";
	else if (techquestion.style.display == "block")
		techquestion.style.display = "none";
    } 


// count 600 characters and check format of data of service directory contact form
function validate() {
	var form1 = document.forms.servdirect;
	var c_Email = form1.c_Email.value;
	var msg = "";
	if(form1.a_First_Name.value == "") msg += "* First Name\n";
	if(form1.b_Last_Name.value == "") msg += "* Last Name\n";
	if(c_Email.indexOf('@') < 0 || c_Email.indexOf('@') !=c_Email.lastIndexOf('@') || c_Email.indexOf('.') < 0 || c_Email.lastIndexOf('.') < c_Email.indexOf('@')) msg += "* Email\n";
	if(form1.d_Company.value == "") msg += "* Company-Organization\n";
	if(form1.e_Address.value == "") msg += "* Address\n";
	if(form1.f_City.value == "") msg += "* City\n";
	if(form1.g_State.value == "") msg += "* State\n";
	if(form1.h_Zip.value == "") msg += "* Zip\n";
	if(form1.i_Country.value == "") msg += "* Country\n";
	if(form1.j_Phone.value == "") msg += "* Phone\n";
	if(form1.m_Description.value == "") msg += "* Product-Service Description\n";
	var total = "";
	for(var i=0; i < form1.n_Category.length; i++){
	if(form1.n_Category[i].checked)
	total +=form1.n_Category[i].value + "\n"
	}
	if(total=="")
	msg += "* Service Category\n";
	var total = "";
	for(var i=0; i < form1.r_Sector.length; i++){
	if(form1.r_Sector[i].checked)
	total +=form1.r_Sector[i].value + "\n"
	}
	if(total=="")
	msg += "* Applicable Sector\n";

	if (msg == "") {
			return true; 
		} else {
		alert('Please fill in the following info:\n' + msg);
		return false;
	}
}

function validate2(form) {
	var msg="";
	if (form.a_name.value == "") msg += "* Name\n";
	if(form.b_email.value.indexOf('@') < 0 || form.b_email.value.indexOf('@') !=form.b_email.value.lastIndexOf('@') || form.b_email.value.indexOf('.') < 0 || form.b_email.value.lastIndexOf('.') < form.b_email.value.indexOf('@')) msg += "* Email\n";
	if (form.k_comments.value == "") msg += "* Comments\n";
	if (form.UserWord.value == "") msg += "* Keyword\n";
	if (msg == "") {
		return true;
	} else {
		alert("Please enter in the following information in order to submit this form:\n" + msg);
		return false;
	}
}

function validate3(form) {
	var msg="";
	if (form.a_name.value == "") msg += "* Name\n";
	if(form.b_email.value.indexOf('@') < 0 || form.b_email.value.indexOf('@') !=form.b_email.value.lastIndexOf('@') || form.b_email.value.indexOf('.') < 0 || form.b_email.value.lastIndexOf('.') < form.b_email.value.indexOf('@')) msg += "* Email\n";
	if (form.f_topics.value == "") msg += "* Suggested Topics\n";
	if (form.UserWord.value == "") msg += "* Keyword\n";
	if (msg == "") {
		return true;
	} else {
		alert("Please enter in the following information in order to submit this form:\n" + msg);
		return false;
	}
}


	var MaximumCharacters = "600";
	var MaximumWords = "0";
	var FormName = "servdirect";
	var TextFieldName = "m_Description";
	var CharactersLeftFieldName = "CharsLeft";
	var WordsMonitor = 0;
	var MaxWords = parseInt(MaximumWords);
	var MaxChars = parseInt(MaximumCharacters);
	var textfield = 'document.' + FormName + '.' + TextFieldName + '.value';
	
	function CharLengthCheck(s,l) {
	if(s.length > l) { s = s.substring(0,l); }
	return s;
	} // function CharLengthCheck()
	
	function InputCharacterLengthCheck() {
	if(MaxChars <= 0) { return; }
	var currentstring = new String();
	eval('currentstring = ' + textfield);
	var currentlength = currentstring.length;
	eval('currentstring = CharLengthCheck(' + textfield + ',' + MaxChars + ')');
	if(CharactersLeftFieldName.length > 0) {
		var left = 0;
		eval('left = ' + MaxChars + ' - ' + textfield + '.length');
		if(left < 0) { left = 0; }
		eval('document.' + FormName + '.' + CharactersLeftFieldName + '.value = ' + left);
		if(currentstring.length < currentlength) { eval(textfield + ' = currentstring.substring(0)'); }
		}
	if(CharactersTypedFieldName.length > 0) {
		eval('document.' + FormName + '.' + CharactersTypedFieldName + '.value = ' + textfield + '.length');
		if(currentstring.length < currentlength) { eval(textfield + ' = currentstring.substring(0)'); }
		}
	} // function InputCharacterLengthCheck()
	
	function InputLengthCheck() {
	InputCharacterLengthCheck();
	}


