jQuery(function($){
	var previous_nr =0;
	var brochure_nr = 0;
	var general_color = "";
	$(".download-brochure-img").mouseover(function(){
		brochure_nr = this.id.substring(13, this.id.length);
		general_color = $("#" + this.id).attr('alt');
		
		$("#brochure-" + previous_nr).removeClass(general_color + "-color");
		$("#brochure-" + brochure_nr).addClass(general_color + "-color");
		
		previous_nr = brochure_nr;
	});
	
	$(".prepend-downloads").mouseout(function(){
		$("#brochure-" + brochure_nr).removeClass(general_color + "-color");
	});
	
	var img_nr = 0;
	var prev_img_nr = 0;
	$(".download-list a").mouseover(function(){
		img_nr = this.id.substring(9, this.id.length);
		general_color = $("#" + this.id).attr('rel');
		
		$("#img-brochure-" + prev_img_nr).removeClass("border-" + general_color);
		$("#img-brochure-" + img_nr).addClass("border-" + general_color);
		
		prev_img_nr = img_nr;
	});
	
	$(".download-list").mouseout(function(){
		$("#img-brochure-" + img_nr).removeClass("border-" + general_color);
	});
	
	$(".download-brochure-img").click(function(){
		brochure_id = this.id.substring(13, this.id.length);
		window.location=$("#brochure-" + brochure_id).attr("href");
	});
});

function check_subscribe_values()
{
	var sbName	  	= $('#sbName').val();
	var sbPosition	= $('#sbPosition').val();
	var sbCompany	= $('#sbCompany').val();
	var sbAddress     	= $('#sbAddress').val();
	var sbEmail     	= $('#sbEmail').val();
	var agreeTerm     	= $('#agreeTerm:checked').val();
	var code      		= $('#code').val();
	var returnVal 		= false;
	
	// Verify Name
		if (sbName == '' || sbName.length < 2 ) { inlineMsg('sbName','Please specify your Name!',3); return false; }
	
	// Verify Position
		if (sbPosition == '' || sbPosition.length < 2 ) { inlineMsg('sbPosition','Please specify your Position!',3); return false; }
		
	// Verify Company
		if (sbCompany == '' || sbCompany.length < 2 ) { inlineMsg('sbCompany','Please specify your Company!',3); return false; }
	
	// Verify Address
		if (sbAddress == '' || sbAddress.length < 2 ) { inlineMsg('sbAddress','Please specify your Address!',3); return false; }
	
	// Verify Email
		if (sbEmail == '' || sbEmail.length < 2 ) { inlineMsg('sbEmail','Please specify your Email!',3); return false; }
		
		if (validateEmail(sbEmail) ) { inlineMsg('sbEmail','Invalid email address!',3); return false; }
	
	// Verify Company
		if (agreeTerm == null ) { inlineMsg('agreeTerm','Please agree to our terms and conditions!',3); return false; }
	
	// Verify Security Code
		if (code == '' || code.length < 2 ) { inlineMsg('code','Please specify exactly the Security Code shown in the image!',3); return false; }
		
	// Verify captcha
	$.ajax
	({
		type: "POST",
		url: "ajax/ajax_security_code.php",
		data: "code="+escape(code)+"&rand="+Math.random(),
		async: false,
		success: function(msg)
		{		
			if ( msg == '1' )	
				returnVal = true;				
			else 
			{					
				inlineMsg('code','<b>Invalid code!</b> <br> Please specify exactly the Security Code shown in the image.',3);
			}
		},
		error: function(msg) 
		{
		        alert("Invalid request!\n"+msg);
		}
	});
	
	if(returnVal)
		$("#form-subscribe").submit();
		
	return returnVal;
}

function validateEmail(emailad) {
		
	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	var check=/@[\w\-]+\./;
	var checkend=/\.[a-zA-Z]{2,4}$/;

	if(((emailad.search(exclude) != -1)||(emailad.search(check)) == -1)||(emailad.search(checkend) == -1)){
		return true;
	}
	else {
		return false;
	}
}

function show_details(value)
{
	if(value == "Media" || value == "Other")
		$("#sbInterestDetails").slideDown('fast');
	else
		$("#sbInterestDetails").slideUp('fast');
}

