function fctShowDiv(div) {

	x = document.getElementById(div);
	if(navigator.appName!='Microsoft Internet Explorer'){
		if (x!=null){
			x.setAttribute('style',"visibility:visible;");
		}
	}
	else{
		x.style.visibility='visible';
	}
}

function fctHideDiv(div) {

	x = document.getElementById(div);
	if(navigator.appName!='Microsoft Internet Explorer'){
		if (x!=null){
			x.setAttribute('style',"visibility:hidden;");
		}
	}
	else{
		x.style.visibility='hidden';
	}
}

function fctShowDisplayDiv(div) {

	x = document.getElementById(div);
	if(navigator.appName!='Microsoft Internet Explorer'){
		if (x!=null){
			x.setAttribute('style',"display:block;");
		}
	}
	else{
		x.style.display='block';
	}
}

function fctHideDisplayDiv(div){

	x = document.getElementById(div);
	if(navigator.appName!='Microsoft Internet Explorer'){
		if (x!=null){
			x.setAttribute('style',"display:none;");
		}
	}
	else{
		x.style.display='none';
	}
}

//faq
function faq(n){

	$('.faq').each(function() {

		$(this).hide();
	});

	$('#faq_' + n).fadeIn('slow');
}

function fctChangeColor(div,cor){

	x = document.getElementById(div);

	if(navigator.appName!='Microsoft Internet Explorer'){

		if (x!=null){

			x.setAttribute('style',"color:"+cor+";");
		}
	}
	else{

		x.style.color=cor;
	}
}

// end faq

function validate_required(form, error_msg) {

	return validate_required_and_alert(form, false, error_msg);
}

function validate_required_and_alert(form, showAlert, error_msg) {

	return validate_required_and_alert_isSubmit(form, showAlert, error_msg, false);
}

function validate_required_and_alert_isSubmit(form, showAlert, error_msg, isSubmit) {

	var changed = false;
	$(form).children('.msg').fadeOut('fast');

	$(form).children('.required').each(function() {

		if(change_required($(this))) {

			changed = true;
			return;
		}
	});

	if(changed) {

		$(form).children('.msg').html(error_msg).fadeIn('slow');

		if(showAlert) {

			alert(error_msg);
		}

		return false;

	} else {

		if(!isSubmit) {

			$(form).children('.msg').fadeOut('slow');
			$(form).children('.msg').empty();
		}
	}

	return true;
}

function change_required(field) {

	var hasValue = false;

	var changed = false;

	if($(field).attr('type') == 'checkbox') {

		hasValue = ($(this).is(':checked'));

	} else if($(field).attr('nodeName') == 'FIELDSET') {

		$(field).children('.required').each(function() {

			hasValue = change_required($(this));
		});

	} else {

		if($(field).val() == '') {

			hasValue = false;

		} else {

			hasValue = true;
		}
	}


	if(hasValue == true) {

		$('#lbl_' + $(field).attr('name')).css("color", '');

	} else {

		changed = true;
		$('#lbl_' + $(field).attr('name')).css("color", "#dd4036");
	}

	return changed;
}

function validate_and_ajax_post(form, onSuccess) {

	return validate_and_alert_ajax_post(form, onSuccess, false);
}

function validate_and_alert_ajax_post(form, onSuccess, showAlert, error_msg) {

	if(validate_required_and_alert(form, showAlert, error_msg)) {

		postAndShowError(form, onSuccess);
	}
}

function register_and_alert(showAlert, error_msg, sucess_msg) {

	$('#registerForm').children('.msg').hide();

	if(validate_required_and_alert($('#registerForm'), true, error_msg)) {

		return postAndShowErrorShowAlert($('#registerForm'), function() {

			if(sucess_msg != null && sucess_msg != undefined && sucess_msg != '') {

				alert(sucess_msg);
			}
			$('#divEditProfile').fadeOut('slow');
			location.reload(true);
		},

		showAlert);	

	} else {

		return false;
	}
}

function postAndShowError(form, onSuccess) {

	postAndShowErrorShowAlert(form, onSuccess, false);
}

function postAndShowErrorShowAlert(form, onSuccess, showAlert) {

	post(form, function(data) {

			if(data != null && data != undefined != data.errors != null && data.errors != undefined) {

				var errors = '';

				if(showAlert) {

					errors = errorsInLine(data.errors);

				} else {

					errors = errorsToList(data.errors);
				}

				if(showAlert) {

					alert(errors);

				} else {

					$(form).children('.msg').each(function() {

						$(this).empty();

						$(this).html(errors);
						$(this).fadeIn('slow');						
					});
				}

			} else {

				if(onSuccess != null && onSuccess != undefined) {

					onSuccess();
				}
			}
		}
	);
}

function validate_and_post(form) {

	if(validate_required(form)) {

		$(form).submit();
	}
}

function sendContactMail(error_msg) {

	validate_and_alert_ajax_post($('#contactForm'), function() {

		$('#contactForm').hide();
		$('#divContactSuccess').fadeIn('slow');
	}, false, error_msg);
}

function post(form, onSuccess) {

	$.post($(form).attr('action'), $(form).serialize(), function (data){

			if(onSuccess != null && onSuccess != undefined){

				onSuccess(data);
			}

	}, "json");
};

function showModal(content) {

	var id = '#divModal';

	$(id).html($(content).html());

	$(content).empty();

	var maskHeight = $(document).height();
	var maskWidth = $(window).width();

	$('#mask').css({'width':maskWidth,'height':maskHeight});

	$('#mask').fadeIn(1000);	
	$('#mask').fadeTo("slow",0.5);	

	//Get the window height and width
	var winH = $(window).height();
	var winW = $(window).width();

	$(id).css('top',  winH/2-$(id).height()/2);
	$(id).css('left', winW/2-$(id).width()/2);

	$(id).fadeIn(2000);
}

function showDialog(content) {

	var id = '#divDialog';

	$(id).html($(content).html());

	$(content).empty();

	var maskHeight = $(document).height();
	var maskWidth = $(window).width();

	$('#mask').css({'width':maskWidth,'height':maskHeight});

	$('#mask').fadeIn(1000);	
	$('#mask').fadeTo("slow",0.5);	

	//Get the window height and width
	var winH = $(window).height();
	var winW = $(window).width();

	$(id).css('top',  winH/2-$(id).height()/2);
	$(id).css('left', winW/2-$(id).width()/2);

	$(id).fadeIn('slow');
}

function closeModal(content) {

	$(content).html($('#divModal').html());

	$('#divModal').empty();

	$('#mask').fadeOut('fast');
	$('.window').fadeOut('fast');
}

function closeDialog(content) {

	$(content).html($('#divDialog').html());

	$('#divDialog').empty();

	$('#mask').fadeOut('fast');
	$('.window').fadeOut('fast');
}

function displayModal(div, title) {

	$('body').qtip({
	      id: 'modal', // Since we're only creating one modal, give it an ID so we can style it
	      content: {
	         text: $(div),
	         title: {
	            text: title,
	            button: true
	         }
	      },
	      position: {
	         my: 'center', // ...at the center of the viewport
	         at: 'center',
	         target: $(window)
	      },
	      show: {
	    	 when: false,
	         solo: true, // ...and hide all other tooltips...
	         modal: true
	      },
	      hide: false,
	      style: 'ui-tooltip-light ui-tooltip-rounded'
	});
} 

function showToolTip(where, title, message, myCorner, atOppositeCorner) {
	
	$(where).qtip({
		
        content: {
           text: '<p style="line-height: 150%">' + message + '</p>', 
           title: {
              text: title,
              button: true
           }
        },
        position: {
           my: myCorner, // Use the corner...
           at: atOppositeCorner // ...and opposite corner
        },
        show: {
           event: false, // Don't specify a show event...
           ready: true, // ... but show the tooltip when ready
           effect: function(offset) { $(this).fadeIn('slow'); } // "this" refers to the tooltip
        },
        hide:  false,
        style: {
           classes: 'ui-tooltip-shadow ui-tooltip-plain'
        }
	});
}

//people

/* 	function changeLanguage(str) {
		document.getElementById('divLanguageLog').innerHTML = '<a href="javascript:fctShowDiv(\'divLanguageLogOptions\');">'+str+' &nbsp;<img src="_img/setaMenuLog.gif" alt="English" align="absmiddle" /></a>';
		fctHideDiv('divLanguageLogOptions');
	}
 */

function changeLanguage(locale) {

	$.post($('#formChangeLanguage').attr('action'), {to:locale}, 

		function (result) {

			if(result != null && result.errors != null && result.errors != undefined) {

				var errors = '';
				for(var i = 0; i < result.errors.length; i++) {

					errors += '' + result.errors[i] + ';';
				}
				errors += '';

				alert(errors);

			} else {

				location.reload(true);
			}
		}, 

	'json');
}

function addContact(contactId) {

	$.post($('#addContactForm').attr('action'), {id:contactId},

		function (result) {

			if(result != null && result.errors != null && result.errors != undefined) {

				var errors = '';
				for(var i = 0; i < result.errors.length; i++) {

					errors += '' + result.errors[i] + ';';
				}
				errors += '';

				alert(errors);

			} else {

				alert('Contact has added in your connections successfully!');
				$('#addContactOptions').fadeOut();
			}
		}

	, 'json');
}

function showForwardProfileBox(div, email, msg) {

	showMailBox($(div));

	$(div).find('.form').find('.message').val(msg);
	$(div).find('.form').find('.to').val(email);
}

function showPersonalContactRequest(div, msg) {

	showMailBox($(div));

	$(div).find('.form').find('.message').val(msg);
}

function showMailBox(div) {

	$(div).find('.form').children('.required').each(function() {

		$(this).val('');
	});
	$(div).find('.msg').hide();
	$(div).find('.success').hide();
	$(div).find('.form').show();

	$(div).fadeIn('slow');
}

function peopleSendEmail(form, divSuccess, divModal, onSuccess) {

	postAndShowErrorShowAlert($(form), function() {

		$(form).hide();
		$(divSuccess).fadeIn('slow');

		window.setTimeout(function() {

			$(divModal).fadeOut('slow');

		}, 3000);

		if(onSuccess != null && onSuccess != undefined) {

			onSuccess();
		}
	}, true);
}

function visit(type, id) {

	if($.cookie("visited_" + type + "_" + id) != 'true') {

		$.cookie("visited_" + type + "_" + id, "true");

		$.post($('#visitForm').attr('action'), {type:type, id:id}, function(data) {

			if(data != null && data != undefined && data.errors != null && data.errors != undefined) {

				alert(errorsInLine(data.errors));

				return false;
			}
		});
	}
}

//end people

//classification

function addOrRemoveClassification(form, type, id) {

	$.post($(form).attr('action'), {type: type, classificationId: id}, 

		function (result) {

			if(result.errors != null && result.errors != undefined) {

				var errors = '';
				for(var i = 0; i < result.errors.length; i++) {

					errors += '' + result.errors[i] + ';';
				}
				errors += '';

				alert(errors);

			} else {

				var div = '';
				if(type == 'areaOfInterest') {

					div = '#divAreasOfInterest';

				} else {

					div = '#divEconomicClassifications';
				}

				$(div).hide();
				$(div).empty();
				$(div).html(result);
				$(div).fadeIn();
			}
		}
	);
}

function specifyClassification(form, id) {

	$.post($(form).attr('action'), {classificationId: id}, 

		function (result) {

			if(result != null && result != undefined) {

				$('#divSpecify').hide();
				$('#divSpecifyClassification').empty();
				$('#divSpecifyClassification').html(result.treeviewSpecifyClassification);
				$('#divSpecify').fadeIn();
			}
		}

	, 'json');
}

function showUserClassification(form, to) {

	$.post($(form).attr('action'), 

		function (result) {

			if(result != null && result != undefined) {

				$(to).hide();
				$(to).find('.contem').empty();
				$(to).find('.contem').html(result.treeviewClassification);
				$(to).fadeIn();
			}
		}

	, 'json');
}

function saveClassification() {

	$.post($('#saveClassificationForm').attr('action'), function (result) {

			if(result.errors != null && result.errors != undefined) {

				var errors = '';
				for(var i = 0; i < result.errors.length; i++) {

					if(errors.length > 0) {

						errors += '; ';
					}

					errors += '' + result.errors[i];
				}
				errors += '';

				alert(errors);

			} else {

				showDialog($('#divClassificationDefined'));
			}
		}
	);
}

// end classification

//cliqToFind

function cliqToFind(form, query, text, divResult) {

	var queryString = '';

	if(query != null && query != undefined) {

		if($(query).val() == text) {

			$(query).val('');
		}

		queryString = '&query=' + $(query).val();
	}

	$.post($(form).attr('action'), $(form).serialize() + queryString, 

		function (result) {

			if(result.errors != null && result.errors != undefined) {

				var errors = '';
				for(var i = 0; i < result.errors.length; i++) {

					errors += '' + result.errors[i] + '; ';
				}
				errors += '';

				alert(errors);

			} else {

				closeAddQueryOptions();

				$(divResult).empty();
				$(divResult).html(result);
				$(divResult).fadeIn('slow');
			}
		}
	);

	if(query != null && query != undefined) {

		if($(query).val() == '') {

			$(query).val(text);
		}
	}
}

function closeAddQueryOptions() {

	closeDiv($('#expandAddToQuery'), $('#divAddQueryExpandable'));
}

function closeDiv(expandable, div) {

	if($(div).css("display") == 'block') {

		$(div).slideUp('slow', toogleBullet(expandable, div));
	}
}

function toogleDiv(expandable, div) {

	$(div).slideToggle('slow', toogleBullet(expandable, div));
}

function toogleBullet(expandable, div) {

	if($(div).css("display") == 'block') {

		if($(expandable).hasClass('bulletDown')) {

			$(expandable).removeClass('bulletDown');
			$(expandable).addClass('bulletRight');
		}

	} else {

		if($(expandable).hasClass('bulletRight')) {
		
			$(expandable).removeClass('bulletRight');
			$(expandable).addClass('bulletDown');
		}
	}
}

function toogleCliqToFindMore() {

	$('#divAddQueryExpandable').hide();

	if($('#divMore').css("display") == 'block') {

		//hide
		$('#divAddQuaeryContent').children('.classAQContent').each(function() {

			$(this).removeClass('show');

			$(this).children('.contemShow').each(function() {

				$(this).removeClass('contemShow');
				$(this).addClass('contem');
			});
		});

		$('#less').hide();
		$('#more').show();

		$('#divMore').hide();

	} else {

		//show
		$('#divAddQuaeryContent').children('.classAQContent').each(function() {

			$(this).addClass('show');

			$(this).children('.contem').each(function() {

				$(this).removeClass('contem');
				$(this).addClass('contemShow');
			});
		});

		$('#less').show();
		$('#more').hide();

		$('#divMore').show();
	}

	showAddToQuery($('#divAQLink1'), $('#divIndustryAndEconomy'));

	$('#divAddQueryExpandable').show('slow');
}

function showAddToQuery(menu, div) {

	$('.classAQContent').each(

		function() {

			$(this).hide();
		}
	);
	$(div).fadeIn('slow');

	$('.addToQueryLink').each(

		function() {

			$(this).children('.link').css('display', '');
			$(this).children('.label').css('display', 'none');
		}
	);
	if(menu != undefined && menu != null) {

		$(menu).children('.link').css('display', 'none');
		$(menu).children('.label').css('display', '');
	}
}

function showCliqToFindResult(form, engine, divResult) {

	$.post($(form).attr('action'), {engine: engine}, 

		function (result) {

			if(result.errors != null && result.errors != undefined) {

				var errors = '';
				for(var i = 0; i < result.errors.length; i++) {

					errors += '' + result.errors[i] + '; ';
				}
				errors += '';

				alert(errors);

			} else {

				$(divResult).empty();
				$(divResult).html(result);
				$(divResult).fadeIn('slow');
			}
		}
	);
}

function treeviewSelectItem(treeviewId, id, msg) {

	if(treeviewId == 'treeviewSpecifyClassification') {

		addOrRemoveClassification($('#addClassificationForm'), 'economicClassification', id);

	} else if (treeviewId == 'treeviewClassification') {

		$('#divSpecify').fadeOut('fast', function() {

		$.get($('#loadClassificationForm').attr('action') + id + '/',

				function (data) {

					$('#classificationId').val(id);
					$('#classification').hide();
					$('#classification').empty();
					$('#classification').html(data);
					$('#classification').fadeIn('slow');
			});
		});

	} else {

		var dictionaryId = getDictionaryId(treeviewId);

		addToQuery(dictionaryId, id, msg);
	}
}

function treeviewToggle(treeviewId, id) {

	var dictionaryId = getDictionaryId(treeviewId);

	var ul = '#ul_' + treeviewId + '_' + id;

	var li = '#li_' + treeviewId + '_' + id;

	var div = '#div_' + treeviewId + '_' + id;

	if($(li).hasClass('expandable')) {

		$(li).removeClass('expandable');
		$(li).addClass('collapsable');

		$(div).removeClass('expandable-hitarea');
		$(div).addClass('collapsable-hitarea');

		if($(li).hasClass('lastExpandable')) {

			$(li).removeClass('lastExpandable');
			$(li).addClass('lastCollapsable');

			$(div).removeClass('lastExpandable-hitarea');
			$(div).addClass('lastCollapsable-hitarea');
		}

		if ($(ul).hasClass('unloaded')) {

			$.post($('#treeviewExpandForm').attr('action'), {dictionaryId: dictionaryId, treeviewId: treeviewId, dictionariableId: id},

				function (data) {

					$(ul).append(data.childrens);

					$(ul).removeClass('unloaded');

			}, "json");
		}

		$(ul).show('fast');

	} else if($(li).hasClass('collapsable')) {

		$(li).removeClass('collapsable');
		$(li).addClass('expandable');

		$(div).removeClass('collapsable-hitarea');
		$(div).addClass('expandable-hitarea');

		if($(li).hasClass('lastCollapsable')) {

			$(li).removeClass('lastCollapsable');
			$(li).addClass('lastExpandable');

			$(div).removeClass('lastCollapsable-hitarea');
			$(div).addClass('lastExpandable-hitarea');
		}

		$(ul).hide('fast');
	}
}

function getDictionaryId(treeviewId) {

	var dictionaryId = null;

	if(treeviewId.indexOf('treeViewIndustryAndEconomy') >= 0) {

		dictionaryId = 0;

	} else if(treeviewId.indexOf('treeViewProductsAndServicesClassification') >= 0 || treeviewId.indexOf('treeviewClassification') >= 0) {

		dictionaryId = 1;

	} else if(treeviewId.indexOf('treeViewTechnicalTerminology') >= 0) {

		dictionaryId = 2;
	}

	return dictionaryId;
}

function addToQuery(dictionaryId, id, msg) {

	$.post($('#addToQueryForm').attr('action'), $('#addToQueryForm').serialize() + '&dictionaryId=' + dictionaryId + '&dictionariableId=' + id,

		function (selectedTerms) {

			var show = $('#divSelectedTermsList').css("display") == 'block';

			$('#divSelectedTermsList').hide();
			$('#divSelectedTermsList').empty();
			$('#divSelectedTermsList').html(selectedTerms);

			if(show) {

				$('#divSelectedTermsList').fadeIn('fast');
			}

			alert(msg);
		}
	);
}

function removeFromQuery(dictionaryId, id) {

	$.post($('#removeFromQueryForm').attr('action'), {dictionaryId: dictionaryId, dictionariableId: id},

		function (selectedTerms) {

			$('#divSelectedTermsList').hide();
			$('#divSelectedTermsList').empty();
			$('#divSelectedTermsList').html(selectedTerms);
			$('#divSelectedTermsList').fadeIn('fast');
		}
	);
}

function selectAnLetter(dictionaryId, letter) {

	$.post($('#selectAnLetterForm').attr('action'), {dictionaryId: dictionaryId, letter: letter},

		function (selectedTerms) {

			var div = null;

			if(dictionaryId == 4) {

				div = '#divForeignTradeTerminologiesList';

			} else if(dictionaryId == 5) {

				div = '#divLegalTermsList';
			}
		
			$(div).hide();
			$(div).empty();
			$(div).html(selectedTerms);
			$(div).show('fast');
		}
	);
}

function clearCliqToFind() {

	post($('#clearSearchForm'), function() {

		location.reload(true);
	});
}

//end cliqToFind

//matchMaking

function matchMaking() {

	$.post($('#matchMakerForm').attr('action'), $('#matchMakerForm').serialize(), 

		function (result) {

			if(result.errors != null && result.errors != undefined) {

				var errors = '';
				for(var i = 0; i < result.errors.length; i++) {

					errors += '' + result.errors[i] + ';';
				}
				errors += '';

				alert(errors);

			} else {

				$('#matchMakingResult').hide();
				$('#matchMakingResult').empty();
				$('#matchMakingResult').html(result);
				$('#matchMakingResult').fadeIn('slow');
			}
		}
	);
}

//end matchMaking

function showForgotPassword(defaultMessage) {

	$('#forgotPasswordMessage').empty();
	$('#forgotPasswordMessage').html('&nbsp;');
	var login = $('#formForgotPassword').attr('login');
	$(login).val('');
	restoreDefault(login, defaultMessage);
	$('#forgotPassword').show();
	$('#formForgotPassword').show();
	$('#divForgotPasswordSusscess').hide();
	$('#divEForgotPassword').fadeIn('slow');
}

function sendForgotPassword(form, errors, divSuccess, boxFadeOut) {

	var login = $(form).attr('login');
	if($(login).val() == 'Enter your e-mail:') {

		$(login).val('');
	}

	$.get($(form).attr('action'), $(form).serialize(), function (data) {

		if(data != null && data != undefined && data.errors != null && data.errors != undefined) {

			$(errors).html(errorsToLiList(data.errors));
			$(errors).fadeIn();

		} else {

			$(form).hide();
			$(divSuccess).fadeIn('fast');

			if(boxFadeOut != undefined && boxFadeOut != null) {
				
				window.setTimeout(function() {
	
					$(boxFadeOut).fadeOut('slow');
	
				}, 3000);
			}
		}

	}, 'json');

	if($(login).val() == '') {

		$(login).val('Enter your e-mail:');
	}
}

function definePassword(form) {

	post(form, function(data) {

		if(data == null || data == '' || data == undefined) {

			$('#definePasswordStatus').empty();
			$('#definePasswordStatus').hide();
			$('#formDefinePassword').hide();
			$('#definePasswordSuccess').fadeIn('slow');

		} else {

			var errors = errorsToList(data.errors);

			$('#definePasswordStatus').empty();
			$('#definePasswordStatus').html(errors);
			$('#definePasswordStatus').fadeIn('slow');
			$('#definePasswordSuccess').hide();
		}
	});
}

function is_array(mixed_var) {  


    // Returns true if variable is an array    
    //   
    // version: 901.1623  
    // discuss at: http://phpjs.org/functions/is_array  
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)  
    // +   improved by: Legaev Andrey  
    // +   bugfixed by: Cord  
    // +   bugfixed by: Manish  
    // +   improved by: Onno Marsman  
    // %        note 1: In php.js, javascript objects are like php associative arrays, thus JavaScript objects will also  
    // %        note 1: return true  
    // *     example 1: is_array(['Kevin', 'van', 'Zonneveld']);  
    // *     returns 1: true  
    // *     example 2: is_array('Kevin van Zonneveld');  
    // *     returns 2: false  
    // *     example 3: is_array({0: 'Kevin', 1: 'van', 2: 'Zonneveld'});  
    // *     returns 3: true  
    // *     example 4: is_array(function tmp_a(){this.name = 'Kevin'});  
    // *     returns 4: false  
    var key = '';  
  
    if (!mixed_var) {  
        return false;  
    }  
  
    if (typeof mixed_var === 'object') {  
  
        if (mixed_var.hasOwnProperty) {  
            for (key in mixed_var) {  
                // Checks whether the object has the specified property  
                // if not, we figure it's not an object in the sense of a php-associative-array.  
                if (false === mixed_var.hasOwnProperty(key)) {  
                    return false;  
                }  
            }  
        }  
  
        // Uncomment to enable strict JavsScript-proof type checking  
        // This will not support PHP associative arrays (JavaScript objects), however  
        // Read discussion at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_is_array/  
        //  
        //  if (mixed_var.propertyIsEnumerable('length') || typeof mixed_var.length !== 'number') {  
        //      return false;  
        //  }  
  
        return true;  
    }  
  
    return false;  
}

function buy(product, paymentType) {

	var form = $('#paypalForm');

	$($(form).attr('product')).attr('value', product);
	$($(form).attr('type')).attr('value', paymentType);

	postAndShowErrorShowAlert(form, null, true);
}

function addCatalogItem(message) {

	$('#catalogForm').submit();
}

function choosePayment(menu, paymentType) {

	if($('.payment_choose').find('div:visible').attr('id') != $(paymentType).attr('id')) {

		$('.payment_choose').find('span').each(function() {

			$(this).removeClass('selected');
		});

		$(menu).addClass('selected');

		$('.payment_choose').find('.type').each(function() {

			$(this).hide();
		});

		$(paymentType).fadeIn('slow');
	}
}

//end catalog

function showLanguages() {

	if($('#divLanguageLogOptions').is(':hidden')) {

		$('#divLanguageLogOptions').fadeIn('slow');

	} else {

		$('#divLanguageLogOptions').fadeOut('slow');		
	}
}

function showHowItWorks(id) {	

	$('.howItWorks').each(function() {

		$(this).hide();
	});

	$('#howItWorks_' + id).fadeIn('slow');
}

function loadCaptcha(iFrameCaptcha, theURL) {

	var cal = new Date();
	$(iFrameCaptcha).attr('src', theURL + '?cache=' + cal.getTime());
}

function showRequestInfo(catalogItemId, name) {

	$('#catalogItemId').val(catalogItemId);
	$('#about').html(name);
	$('#commentary').val('');
	$('#divRequestCatalogInfo').fadeIn('slow');
}

function comment() {

	$('.msg').empty();
	$('.msg').hide();

	$.post($('#commentaryForm').attr('action'), $('#commentaryForm').serialize(), function (data) {

			if(data == null) {

				alert("Unexpected error!");

			} else if (data.errors != null && data.errors != undefined) {

				var errors = errorsToList(data.errors);

				$('.msg').html(errors);
				$('.msg').fadeIn('slow');

			} else {

				$('#commentaries').hide();
				$('#commentaries').html(data);
				$('#commentaries').fadeIn('slow');
			}
		}
	);
}

function loadLastActivity() {

	var id = $('#activitylist').find('li').first().attr('id');
	if(id != '' && id != null && id != undefined) {
		
		id = id.substring(id.indexOf('_')+1);

		$.get($("#loadLastActivity").attr('action'), {id:id, max:3}, function(data) {
	
			if(data != null && data != undefined && data != '') {
	
				var quantity = data.split('activity_').length - 1;
	
				var html = data.replace(/(?:(?:\r\n|\r|\n)\s*)/gi, '');
	
				$(html).hide().prependTo("#activitylist").fadeIn("slow");
	
				for(i = 0; i < quantity; i++) {
	
					$('#activitylist').find('li').last().fadeOut('fast').remove();
				}
			}
		});

		setTimeout(loadLastActivity, 20000);
	}
}

function alternateCatalogItem() {

	var first = $('.catalogitems').find('li').first();
	var last = $('.catalogitems').find('li').first().next().next().next();

	if($(last).hasClass('last')) {

		$(last).removeClass('last');

		$.get($("#loadCatalogItems").attr('action'), function(data) {

			if(data != null && data != undefined && data != '') {

				var html = data.replace(/(?:(?:\r\n|\r|\n)\s*)/gi, '');

				$('.catalogitems').append(html);
			}
		});
	}

	$(first).fadeOut('slow', function() { $(first).remove(); });

	setTimeout(alternateCatalogItem, 5000);
}

function expandSpec(expad, spec) {

	$(spec).css('height', '');
	$(expad).fadeOut('fast');
}

function selectPaymentToConfirm() {

	$('.payment_selected_instructions').each(function() {

		$(this).hide();
	});

	$('#payment_selected_' + $("input[name='type']:checked").val()).fadeIn('slow');
}

function selectPaymentToConfirmPaypal() {

	$('.payment_selected_instructions').each(function() {

		$(this).hide();
	});

	$('#payment_selected_paypal').fadeIn('slow');
}

function alternatePaymentOptionsOrConfirmation(expand) {

	if($(expand).attr('id') == 'payment_options') {

		toogleDiv($(expand), $('#paymentOptionsExpandable'));

		if($('#paymentNotificationExpandable').css("display") == 'block') {

			$('#paymentNotificationExpandable').slideToggle('slow');
		}

	} else {

		toogleDiv($(expand), $('#paymentNotificationExpandable'));

		if($('#paymentOptionsExpandable').css("display") == 'block') {

			$('#paymentOptionsExpandable').slideToggle('slow');
		}
	}
}
