    // block for variables
	var json_ext = 'html';
	var ajax_script_path = 'test2.php';
	//var jsonok = '';
	
	
	$(function() {
		$('.bottom-bg input').each(function(i){
			if ($('#'+this.id+'-auto').length){
				if ($(this).parent().find('a.flag-img').length || $(this).hasClass("type-your-artist")){// is city field
					var tbl = $('#'+this.id).autobox({'isCity':true}).get(0);
					$.getJSON(this.alt+'', function(json) {
						$.each(json, function(idx,str) { tbl.autoFeed(str); });
					});
				}
				else{											// default auto field
					var tbl = $('#'+this.id).autobox().get(0);
					
					
					//$.each(myvar, function(idx,str) { tbl.autoFeed(str); });
					
					$.getJSON(this.alt+'', function(json) {
						$.each(json, function(idx,str) { tbl.autoFeed(str); });
					});
				}
			}				
		});
		$('.input-holder .flag-img').each(function(i, flag){
			// init countries opener
			$(flag).click(function(){
				// open countries
				$(this).parents('.row:first').css('position', 'relative').find('.drop-countries').show();
				return false;
			});
			// init countreis selector
			$(flag).parents('.row:first').find('.drop-countries li a').each(function(i, country){
				$(country).click(function(){
					// set new flag
					$(flag).find('img').attr('src', $(this).parent().find('img').attr('src'));
					// resret if exist
					$(flag).parents('.row:first').find('.input-area').remove();
					$(flag).parents('.row:first').find('.drop-select-countries').empty().html('<ul></ul>');
					// new auto feed
					var tbl = $('#'+$(flag).parents('.row:first').find('.bottom-bg input:hidden').attr('id')).autobox({'isCity':true}).get(0);
					$.getJSON($(this).attr('rel'), function(json) {
						$.each(json, function(idx,str) { tbl.autoFeed(str); });
					});
					// close countries
					$(flag).parents('.row:first').css('position', 'static').find('.drop-countries').hide();
					return false;
				})	
			})
		});		
    });
function initAutocomplete(){
	//validate
	/*var validateinput = function(_holder){
		var isvalid = true;
		$(_holder).find('input:text').each(function(){
			if (this.value == '' && !($(this).hasClass('maininput'))){
				isvalid = false;
				$(this).parents('.row').css('position', 'relative').find('.input-alert:first').click(function(){
					$(this).parents('.row').css('position', 'static');
					$(this).hide();
				}).show();
			}
		})
		if (isvalid) return true;
		return false;
	}*/
	//init submit button
	$('.column-2 .btn-save').each(function(i){
		$(this).attr('href', 'javascript:;').click(function(){
			if (!$(this).hasClass("dizabled")){
				if ($(this).parents('form').length){
					//if (validateinput($(this).parents('form').get(0))){
						$(this).parents('form').get(0).submit();
					//}
				}	
			}
		});
	});
	//init drop-down
	$('.bottom-bg input').each(function(i){
		if ($(this.parentNode).hasClass('custom-drop-down')){
			if ($(this.parentNode.parentNode).find('.btn-drop').length){
				initCustomDropDown($(this), $(this.parentNode.parentNode).find('.btn-drop a:first'));
			}
		}				
	});	
}
var _body = document.body || document.documentElement;
function winOpn(){
	$('.column-2 .link-add-artist').click(function(){
			var myWidth = 0, myHeight = 0, _offset = 0;
			if( typeof( window.innerWidth ) == 'number' ) {
			  //Non-IE
			  myWidth = window.innerWidth;
			  myHeight = window.innerHeight;
			} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			  //IE 6+ in 'standards compliant mode'
			  myWidth = document.documentElement.clientWidth;
			  myHeight = document.documentElement.clientHeight;
			} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			  //IE 4 compatible
			  myWidth = document.body.clientWidth;
			  myHeight = document.body.clientHeight;
			}
			if (document.body && document.body.scrollTop) _offset =  document.body.scrollTop;
			else if (document.documentElement && document.documentElement.scrollTop) _offset = document.documentElement.scrollTop;
			else if (window.pageYOffset) _offset =  window.pageYOffset;
			
		var _top = _offset + myHeight/2 - $('.global-popup')
													.css('left', '0')
													.css('display', 'block')
													.css('visibility', 'visible')
													.css('zIndex', 1000)
													.get(0).offsetHeight/2;
		var _left = _body.scrollLeft + myWidth/2 -$('.global-popup').get(0).offsetWidth/2;
		var _height = $('#main').outerHeight();
		if(_height < document.body.offsetHeight) _height = document.body.offsetHeight;
		if(_height < window.innerHeight) _height = window.innerHeight;
		if(_height < document.documentElement.clientHeight) _height = document.documentElement.clientHeight;
		try{hideSelectOptions()}catch(e){};	
		
		var fader = $('<div id="fader"></div>')
					.css('height', _height)
					.css('width', '100%')
					.css('min-width', '944px')
					.css('top', 0)
					.css('left', 0)
					.css('zIndex', 500)
					.css('opacity', 0.6)
					.css('position', 'absolute')
					.css('background', '#000').click(function(){
						$('#fader').remove();
						$('.global-popup').css('display', 'none');
					});
		initNewPopup(this.parentNode);
		document.body.appendChild(fader.get(0));
		$('.global-popup')
			.css('opacity', 0)
			.css('top', _top)
			.css('left', _left)
			.removeClass('filter-none')
			.animate(
					{'opacity':1},1000,"linear",
					function(){
					   //alert("all done");
					   $('.global-popup').addClass('filter-none');
					   }
				   );		
		return false;
	});
	$('.global-popup .popup-title a').click(function(){
		$('#fader').remove();
		$('.global-popup').css('display', 'none');
	});
}
// function: validate input text
	function validateinput(_holder){
		var isvalid = true;
		$(_holder).find('input:text').each(function(){
			if (this.value == '' && !($(this).hasClass('maininput')) && !($(this).hasClass('crew-inpt')) && $(this).attr('id') != 'crew'){
				isvalid = false;
				$(this).parents('.row').css('position', 'relative').find('.input-alert:first').click(function(){
					$(this).parents('.row').css('position', 'static');
					$(this).hide();
				}).show();
			}
		})
		if (isvalid) return true;
		return false;
	}
	function validateinputcrew(_holder){
		var isvalid = true;
		$(_holder).find('input:text').each(function(){
			
			// I MODIFIED THE LINE BELOW
			if (this.value == '' && ($(this).hasClass('crew-inpt')) && ($(this).attr("name") != 'meaning')  ){
				isvalid = false;
				$(this).parents('.row').css('position', 'relative').find('.input-alert:first').click(function(){
					$(this).parents('.row').css('position', 'static');
					$(this).hide();
				}).show();
			}
		})
		if (isvalid) return true;
		return false;
	}
// function: save button
	function saveButtonNA(_element){
		if (global_parent){
			if (validateinput($(_element).parents('form').get(0))){
				saveNewArtist(global_parent, $(_element).parents('form').get(0));
			}
		}
	}
var global_parent = {};
function initNewPopup(parent){
	global_parent = parent;
// hide crew description
	$('.global-popup .new-crew-desscription').hide();
	$('#popup-btn-save').css('opacity', 1).attr('href', 'javascript:;');
// init add new crew link
	$('.global-popup .link-add-artist').unbind('click').bind('click', function(){
		$('.global-popup .new-crew-desscription').show();
		$('#popup-btn-save').css('opacity', 0.5).unbind('click');
	}).attr('href', 'javascript:;');
// init save button to new crew
	$('#popup-btn-save-crew').unbind('click').bind('click', function(){
		if (validateinputcrew($(this).parents('form').get(0))){
			saveNewCrew(parent, $(this).parents('form').get(0));// save
		}
	}).attr('href', 'javascript:;');
// init save button
	$('#popup-btn-save').unbind('click').bind('click', function(){saveButtonNA($('#popup-btn-save').get(0));return false;});// save
// clean old autofeed
	$('#crew').parents('.row:first').find('.input-area').remove();
	$('#crew').parents('.row:first').find('.drop-select-countries').empty().html('<ul></ul>');
// init new autofeed
	var tbl = $('#crew').autobox().get(0);
	$.getJSON($('#crew').attr('alt')+'', function(json) {
		$.each(json, function(idx,str) { tbl.autoFeed(str); });
	});
}
function saveNewArtist(elrow, _form){
	var _data = '';
	var separator = '';
	$(_form).find('input').each(function(){
		if (!$(this).hasClass('maininput')){
			_data += separator+$(this).attr('name')+'='+$(this).attr('value');
			separator = '&';
		}
	})
	//alert(_data);
	$.ajax({
		type: "POST",
		url: _form.action,//ajax_script_path,
		data: _data+"&addnewartist=1", //special variable for the kind of request determination
		success: function(msg){
		
				//-- Added this to prevent multiple insertion
				if (msg == 'exists'){
					$("#name").parents('.row').find(".input-alert p").text("This artist already exists.");
					$("#name").parents('.row').css('position', 'relative').find('.input-alert:first').click(function(){
						$(this).parents('.row').css('position', 'static');
						$(this).parents('.row').find(".input-alert p").text("Please enter an artist");
						$(this).hide();
					}).show();
					
					return false;
				}
				
				// re-initialisation artist autofeed.
				var _inp = $(elrow).find("input[class != 'maininput']:first");
				var _id = _inp.attr('id');
				var _lis = '';
				var _objs = [];
				var _val_id = _inp.attr('value').split(",");
				$('#'+_id).parents('.row:first').find('.input-area li em').each(function(i, el){
					var _obj = {};
					_lis += '<li>'+$(this).html()+'</li>';
					_obj.value = _val_id[i];
					_obj.caption = $(this).html();
					_objs.push(_obj);
				});
				$('#'+_id).parents('.row:first').find('.input-area').remove();
				$('#'+_id).parents('.row:first').find('.drop-select-countries').empty().html('<ul></ul>');
				var tbl = $('#'+_id).autobox().get(0);
				$.getJSON($('#'+_id).attr('alt')+'', function(json) {
					$.each(json, function(idx,str) { tbl.autoFeed(str); });
				});
				$(_objs).each(function(){
					tbl.add(this);
				});
				tbl.add(eval(msg)[0]);
				
		  $('.global-popup .popup-title a').click();// close popup
		}
	});
}
function saveNewCrew(elrow, _form){
	var _data = $('#crew_name').attr('name')+'='+$('#crew_name').attr('value')+'&'+$('#meaning').attr('name')+'='+$('#meaning').attr('value')
	$.ajax({
		type: "POST",
		url: _form.action,//ajax_script_path,
		data: _data+"&addnewcrew=1", //special variable for the kind of request determination
		success: function(msg){
			
			//-- Added this to prevent multiple insertion
			if (msg == 'exists'){
				$("#crew_name").parents('.row').find(".input-alert p").text("This crew already exists.");
				$("#crew_name").parents('.row').css('position', 'relative').find('.input-alert:first').click(function(){
					$(this).parents('.row').css('position', 'static');
					$(this).parents('.row').find(".input-alert p").text("Please enter a crew");
					$(this).hide();
				}).show(); 
				
				return false;
			}
			
			//-- 28 March 2010 - Added to avoid endless descriptions
			else if (msg == 'toolong') 
			{
				$("#meaning").parents('.row').css('position', 'relative').find('.input-alert:first').click(function(){
					$(this).parents('.row').css('position', 'static');
					$(this).hide();
				}).show();
				
				return false;
			}
			
			
				var _objs = [];
				var _val_id = $('#crew').attr('value').split(",");
				$('#crew').parents('.row:first').find('.input-area li em').each(function(i, el){
					var _obj = {};
					_obj.value = _val_id[i];
					_obj.caption = $(this).html();
					_objs.push(_obj);
				});
				// re-initialisation crew autofeed.
				// clean old autofeed
					$('#crew').parents('.row:first').find('.input-area').remove();
					$('#crew').parents('.row:first').find('.drop-select-countries').empty().html('<ul></ul>');
				// init new autofeed
					var tbl = $('#crew').autobox().get(0);
					$.getJSON($('#crew').attr('alt')+'', function(json) {
						$.each(json, function(idx,str) { tbl.autoFeed(str); });
					});
					$(_objs).each(function(){
						tbl.add(this);
					});
					tbl.add(eval(msg)[0]);
				
			$('#popup-btn-save').css('opacity', 1).bind('click', function(){saveButtonNA($('#popup-btn-save').get(0));return false;});// close fields
			$('.global-popup .new-crew-desscription').hide();
		}
	});
}
function setPopUpPosition(){
	if ($('#fader').css('display') == 'block') {
			var myWidth = 0, myHeight = 0, _offset = 0;
			//var _body = document.body || document.documentElement;
			if( typeof( window.innerWidth ) == 'number' ) {
			  //Non-IE
			  myWidth = window.innerWidth;
			  myHeight = window.innerHeight;
			} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			  //IE 6+ in 'standards compliant mode'
			  myWidth = document.documentElement.clientWidth;
			  myHeight = document.documentElement.clientHeight;
			} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			  //IE 4 compatible
			  myWidth = document.body.clientWidth;
			  myHeight = document.body.clientHeight;
			}
			if (document.body && document.body.scrollTop) _offset =  document.body.scrollTop;
			else if (document.documentElement && document.documentElement.scrollTop) _offset = document.documentElement.scrollTop;
			else if (window.pageYOffset) _offset =  window.pageYOffset;
			
		var _top = _offset + myHeight/2 - $('.global-popup').get(0).offsetHeight/2;
		var _left = /*_body.scrollLeft */+ myWidth/2 - $('.global-popup').get(0).offsetWidth/2;
		$('.global-popup').css('top', _top).css('left', _left);
	}
}
function initAllFunction(){
	initAutocomplete();
	winOpn();
}
if (window.addEventListener) {
	window.addEventListener("load", initAllFunction, false);
	window.addEventListener("resize", setPopUpPosition, false);
	window.addEventListener("scroll", setPopUpPosition, false);
}
else if (window.attachEvent) {
	window.attachEvent("onload", initAllFunction);
	window.attachEvent("onresize", setPopUpPosition);
	window.attachEvent("onscroll", setPopUpPosition);
}
