/*!
* Main Objects for working with jQuery
* Filename: va_main.js
* Version: 1.0.0 (2009-06-16)
* Website: http://virtualart.at/
* Author: typotemp.com Amri H. / Andreas S.
*/


//SHOWFORM - mainly used when clicking the EDIT button
function showform($id,$artist,$module,$item){
	var showText = 'Form is loading...';
	$('#list_header').removeClass('hide');
	$("div[id*='item_']").removeClass('hide');
	$('#add_form').remove();
	$('#loading').remove();
	$('#item_'+$item).after('<div id="loading" class="row update">'+showText+'</div><div id="form_'+$item+'"></div>'); //add a loging div
	$('#item_'+$item).addClass('hide'); // hide the item
	$('input[name=submitted]').after('<input type="hidden" name="search_exh" value="">');
	
	
	//alert('index.php?id='+$id+'&type=221&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi1['+$module+']='+$item);
	$('#form_'+$item).load('index.php?id='+$id+'&type=221&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi1['+$module+']='+$item, function() {
		onchange($id,$artist,$module,$item); // onchange by lit select
		$('#loading').remove(); // remove loading
		
		$("div[id*='item_']").addClass('secondary'); //blur all except the primary form
		$("div[id*='item_']").hover( function () {
			$(this).removeClass('secondary');
			}, function() {
				$(this).addClass('secondary');
 		});	
		
		
		$('.footer_info').addClass('hide');
		$("div[id*='form_']").not('#form_'+$item).addClass('hide').text(""); // hide and empty form div just one is acitve
		$('#form_'+$item).removeClass('hide');
	});
	return false;
	
	
 };
 
function onchange($id,$artist,$module,$item){
	
	$(".cat_lit").change(
			function()
			{
				var catsel = $('.cat_lit').fieldValue();
				$('#form_'+$item).load('index.php?id='+$id+'&type=221&tx_vawiz_pi2[catsel]='+catsel+'&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi1['+$module+']='+$item, function() {
					onchange($id,$artist,$module,$item); // onchange by lit select
					$('#loading').remove(); // remove loading
					$("div[id*='item_']").addClass('secondary'); //blur all except the primary form
					$("div[id*='item_']").hover( function () {
						$(this).removeClass('secondary');
						}, function() {
							$(this).addClass('secondary');
					});	
					$('.footer_info').addClass('hide');
					$("div[id*='form_']").not('#form_'+$item).addClass('hide').text(""); // hide and empty form div just one is acitve
					$('#form_'+$item).removeClass('hide');
				});
			}
		);
 };

function onchangeadd($id,$artist,$module){
	
	$(".cat_lit").change(
			function()
			{
				var catsel = $('.cat_lit').fieldValue();
				$('#add_form').load('index.php?id='+$id+'&type=221&tx_vawiz_pi2[catsel]='+catsel+'&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi2[add]='+$module, function() {
					onchangeadd($id,$artist,$module); // onchange by lit select
					//$('#loading').remove(); // remove loading
					$("div[id*='item_']").addClass('secondary'); //blur all except the primary form
					$("div[id*='item_']").hover( function () {
						$(this).removeClass('secondary');
						}, function() {
							$(this).addClass('secondary');
					});	
					$('.footer_info').addClass('hide');
					$("div[id*='form_']").not('#form_'+$item).addClass('hide').text(""); // hide and empty form div just one is acitve
					$('#form_'+$item).removeClass('hide');
				});
			}
		);
 };

function onchangesub($id,$artist,$mod1,$item1,$mod2,$item2,$mod3,$formid){
	
	$(".cat_lit").change(
			function()
			{
				
				//var formid = $formid || 'subform_';
				
				var catsel = $('.cat_lit').fieldValue();
				$('#subform_'+$item2).load('index.php?id='+$id+'&type=221&tx_vawiz_pi2[catsel]='+catsel+'&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi1['+$mod1+']='+$item1+'&tx_vawiz_pi1['+$mod2+']='+$item2+'&tx_vawiz_pi2[module]='+$mod3, function() {
				onchangesub($id,$artist,$mod1,$item1,$mod2,$item2,$mod3);
				$("div[id*='item_']").addClass('secondary'); //blur all except the primary form
				hide_edit();
	
				$('#loading').remove(); // remove loading
				
				$("div[id*='subitem_']").not('.selector_container').addClass('secondary'); //blur all except the primary form
				//$('.footer_info').addClass('hide');
				$("div[id*='subform_']").not('#subform_'+$item2).addClass('hide').text(""); // hide and empty form div just one is acitve
				$('#subform_'+$item2).removeClass('hide');
			});
			}
		);
 };
 
function showsubform($id,$artist,$mod1,$item1,$mod2,$item2,$mod3){
	var showText = 'Form is loading...';
	$("div[id*='subitem_']").removeClass('hide');
	$('#loading').remove();
	$('#subitem_'+$item2).after('<div id="loading" class="row update">'+showText+'</div><div id="subform_'+$item2+'" style="background:#999999"></div>'); //add a loging div
	$('#subitem_'+$item2).addClass('hide'); // hide the item
	
	//alert('index.php?id='+$id+'&type=221&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi1['+$mod1+']='+$item1+'&tx_vawiz_pi1['+$mod2+']='+$item2+'&tx_vawiz_pi2[module]='+$mod3);
	$('#subform_'+$item2).load('index.php?id='+$id+'&type=221&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi1['+$mod1+']='+$item1+'&tx_vawiz_pi1['+$mod2+']='+$item2+'&tx_vawiz_pi2[module]='+$mod3, function() {
		onchangesub($id,$artist,$mod1,$item1,$mod2,$item2,$mod3);
		if ($mod3=='form_docs') upload();
		$("div[id*='subitem_']").hover( function () {
			$(this).removeClass('secondary');
			}, function() {
				$(this).addClass('secondary');
		});	
		$("div[id*='item_']").addClass('secondary'); //blur all except the primary form
		$("div[id*='item_']").hover( function () {
			$(this).removeClass('secondary');
			}, function() {
				$(this).addClass('secondary');
 		});
		
		
		$('#loading').remove(); // remove loading
		
		$("div[id*='subitem_']").not('.selector_container').addClass('secondary'); //blur all except the primary form
		//$('.footer_info').addClass('hide');
		$("div[id*='subform_']").not('#subform_'+$item2).addClass('hide').text(""); // hide and empty form div just one is acitve
		$('#subform_'+$item2).removeClass('hide');
	});
	return false;
	
	
 };
 
//ADDFORM - mainly used when clicking the ADD button
function addform($id,$artist,$module){
	var showText = 'Form is loading...';
	
	if ($module=='selbox_inst'||$module=='selbox_loc') {
			//$('#add_form').remove();
			$('.selector_container').empty();
		
			
			$('.selector_container').prepend('<div class="loading row add">'+showText+'</div><div class="selector_box_header"></div><div id="add_form" class="row add_form_sub"></div>');
			//alert('index.php?id='+$id+'&type=221&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi2[add]='+$module);
			$('.add_form_sub').load('index.php?id='+$id+'&type=221&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi2[add]='+$module, function() {
				$("#breadcrumb").children('.final').after('<li class="final_inst">Istitution</li>'); //add item in breadcrumb
				$(".form").children("div").not('.selector_container').addClass('secondary'); //blur all except the primary form
				if ($module=='addform_inst') {$('.selector_box_header').text('Add Institution');}
				if ($module=='addform_loc') {$('.selector_box_header').text('Add Location');}
				$('.loading').remove();
			
			});
		} else if ($module=='eid_sub') {
			$('#add_form').remove();
			$('.selector_container').empty();
		
			
			$('.addsub').after('<div class="loading row toremove add">'+showText+'</div><div class="selector_box_header toremove"></div><div id="add_form" class="row toremove"></div>');
			//alert('index.php?id='+$id+'&type=221&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi2[add]='+$module);
			$('#add_form').load('index.php?id='+$id+'&type=221&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi2[add]='+$module, function() {
				//alert('xx');
				$('.addsub').addClass('hide');
				$('.loading').text("Add Event");
				$("div[id*='subitem_']").addClass('secondary'); //blur all except the primary form				$('.loading').remove();
				$("div[id*='subitem_']").hover( function () {
					$(this).removeClass('secondary');
					}, function() {
						$(this).addClass('secondary');
				});
			});
		}  else if ($module=='tec_sub') {
			$('#add_form').remove();
			$('.selector_container').empty();
		
			
			$('.addsub').after('<div class="loading row toremove add">'+showText+'</div><div class="selector_box_header toremove"></div><div id="add_form" class="row toremove"></div>');
			
			$('#add_form').load('index.php?id='+$id+'&type=221&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi2[add]='+$module, function() {
				 
				$('.addsub').addClass('hide');
				$('.loading').text("Add Technology");
				$("div[id*='subitem_']").addClass('secondary'); //blur all except the primary form				$('.loading').remove();
				$("div[id*='subitem_']").hover( function () {
					$(this).removeClass('secondary');
					}, function() {
						$(this).addClass('secondary');
				});
			});
		} else if ($module=='docs') {
			$('.add_form').remove();
			$('.selector_container').empty();
		
			
			$('.addsub').after('<div class="loading row toremove add">'+showText+'</div><div class="selector_box_header toremove"></div><div id="add_form" class="row toremove"></div>');
			//alert('index.php?id='+$id+'&type=221&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi2[add]='+$module);
			$('#add_form').load('index.php?id='+$id+'&type=221&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi2[add]='+$module, function() {
				upload();
				$('.addsub').addClass('hide');
				$('.loading').text("Add Dokument");
				$("div[id*='subitem_']").addClass('secondary'); //blur all except the primary form				$('.loading').remove();
				$("div[id*='subitem_']").hover( function () {
					$(this).removeClass('secondary');
					}, function() {
						$(this).addClass('secondary');
				});
			});
		} else if ($module=='lid_sub') {
			$('#add_form').remove();
			$('.selector_container').empty();
		
			
			$('.addsub').after('<div class="loading row toremove">'+showText+'</div><div class="selector_box_header toremove"></div><div id="add_form" class="row toremove"></div>');
			$('#list_header').after('<div id="loading" class="row add">'+showText+'</div><div id="add_form" class="row"></div>');//add a loging div
			
			$('#add_form').load('index.php?id='+$id+'&type=221&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi2[add]='+$module, function() {
				onchangeadd($id,$artist,$module);
				$('.addsub').addClass('hide');
				$('.loading').text("ADD LITERATURE");
				$("div[id*='subitem_']").addClass('secondary'); //blur all except the primary form				$('.loading').remove();
				$('#loading').text("Add Literature"); // remove loading
				hide_edit();
			});
		} else if ($module=='lid') {
			$('#list_header').removeClass('hide');
			$('#add_form').remove();
			$('.selector_container').remove();
			
			$('#loading').remove();
			$('#list_header').after('<div id="loading" class="row add">'+showText+'</div><div id="add_form" class="row"></div>');//add a loging div
			$('#add_form').load('index.php?id='+$id+'&type=221&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi2[add]='+$module, function() {
 				$('#list_header').addClass('hideimp');
				onchangeadd($id,$artist,$module);
				$('#loading').text("Add Literature");
				$('.addsub').addClass('hide');
				$("div[id*='subitem_']").addClass('secondary'); //blur all except the primary form				$('.loading').remove();
				hide_edit();
			});
		} else if ($module=='eid_sid') {
			$('#list_header').removeClass('hide');
			$('#add_form').remove();
			$('.selector_container').remove();
			$module='eid_sub';
			$('#loading').remove();
			$('#list_header').after('<div id="loading" class="row add">'+showText+'</div><div id="add_form" class="row"></div>');//add a loging div
			$('#add_form').load('index.php?id='+$id+'&type=221&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi2[add]='+$module, function() {
 				$('#list_header').addClass('hideimp');
				onchangeadd($id,$artist,$module);
				$('#loading').text("Add Events");
				$('.addsub').addClass('hide');
				$("div[id*='subitem_']").addClass('secondary'); //blur all except the primary form				$('.loading').remove();
				hide_edit();
			});
		}  else {
		
			$("div[id*='form_']").addClass('hide').text("");
			$('#list_header').removeClass('hide');
			$('#add_form').remove();
			$('#loading').remove();
 			$('#list_header').after('<div id="loading" class="row add">'+showText+'</div><div id="add_form_wid" class="row"></div>');//add a loging div
			//alert('index.php?id='+$id+'&type=221&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi2[add]='+$module);
			$('#add_form_wid').load('index.php?id='+$id+'&type=221&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi2[add]='+$module, function() {
				$('#list_header').addClass('hide');
				
				if ($module=='aid') {
					$('#loading').text("Add Artist"); // remove loading
				} 
				else if ($module=='eid') {
					$('#loading').text("Add Exhibition"); // remove loading
				} else {
					$('#loading').text("Add item"); // remove loading
					}
			});
	}
	return false;
 }; 




function showhidsub() {
	$('.edit').addClass('hide');
	$("div[id*='subitem_']").hover( function () {
		$(this).children('.edit').removeClass('hide');
		}, function() {
			$(this).children('.edit').addClass('hide');
	});
	}

//LISTWORKS - mainly used in works area
function listworks($id,$artist,$work,$module,$func){
	var showText = 'Form is loading...';
 
	if ($module=='list_info') {
			 
			var wid = $('.sel_work').text();
			$('.toremove').remove();
			$('.update').remove();
			if (!wid) $('.select_work_header_second').after('<div class="sel_work hide">'+$work+'</div>');
			
			$('.tohide').addClass('hide').removeClass('tohide'); 
			$('.menu_act').children().removeClass('act');
			$('.menu_act').children('.one').addClass('act');
			//alert('index.php?id='+$id+'&type=221&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi1[wid]='+$work);
			 $('#form_'+$work).load('index.php?id='+$id+'&type=221&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi1[wid]='+$work, function() {
				showhidsub();
				//$('.works_main').addClass('hide');
				$('.loading').remove();
				$('.menu_act').children().removeClass('act');
				$('.menu_act').children('.one').addClass('act');
			});
			
			
		} 
	if ($module=='list_docs') { 
			$('.toremove').remove();
			$('.sel_work').text($work);
			var wid = $('.sel_work').text();
			if (!wid) $('.select_work_header_second').after('<div class="sel_work hide">'+$work+'</div>');
			
			$('.sel_work').after('<div class="active_module toremove hide">docs</div>');
			$('.works_main').after('<div class="loading row add toremove">'+showText+'</div><div class="works_modules toremove row"></div>');
			 
			$('.works_modules').load('index.php?id='+$id+'&type=221&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi1[wid]='+$work+'&tx_vawiz_pi2[module]='+$module, function() {
				showhidsub();
				$('.works_main').addClass('hide');
				$('.loading').remove();
				$('.menu_act').children().removeClass('act');
				$('.menu_act').children('.two').addClass('act');
				$("#breadcrumb").children('.final').after('<li class="toremove">Documents</li>'); //add item in breadcrumb
				
 				
			});
		} 
	
	if ($module=='list_keys') {
			$('.toremove').remove();
			$('.tohide').addClass('hide').removeClass('tohide');
			$('.sel_work').after('<div class="active_module toremove hide">key</div>');
			$('.works_main').after('<div class="loading row add toremove">'+showText+'</div><div class="works_modules toremove row"></div>');
			$('.works_modules').load('index.php?id='+$id+'&type=221&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi1[wid]='+$work+'&tx_vawiz_pi2[module]='+$module, function() {
				showhidsub();
				$('.works_main').addClass('hide');
				$('.loading').remove();
				$('.menu_act').children().removeClass('act');
				$('.menu_act').children('.three').addClass('act');
				$("#breadcrumb").children('.final').after('<li class="toremove">Keywords</li>'); //add item in breadcrumb
				toggle_keys();
				
				
				$('.'+formid).find('.req').each(function(){ 
		if ($(this).fieldValue() == '') {
			checkval = 1;
			$(this).addClass('showreq');
		} else {
			$(this).removeClass('showreq');
			}
	});
				
				
			});
		} 
	
	if ($module=='list_tec') { 
			$('.toremove').remove();
			$('.tohide').addClass('hide').removeClass('tohide');
			$('.sel_work').after('<div class="active_module toremove hide">tec</div>');
			$('.works_main').after('<div class="loading row add toremove">'+showText+'</div><div class="works_modules toremove row"></div>');
			$('.works_modules').load('index.php?id='+$id+'&type=221&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi1[wid]='+$work+'&tx_vawiz_pi2[module]='+$module, function() {
				showhidsub();
				$('.works_main').addClass('hide');
				$('.loading').remove();
				$('.menu_act').children().removeClass('act');
				$('.menu_act').children('.four').addClass('act');
				//$('.works_main').remove();
				$("#breadcrumb").children('.final').after('<li class="toremove">Technology</li>'); //add item in breadcrumb
				 
			});
		} 
		
	
	if ($module=='list_exh') { 
			$('.toremove').remove();
			$('.tohide').addClass('hide').removeClass('tohide');
			var wid = $('.sel_work').text();
			$('.sel_work').after('<div class="active_module toremove hide">list_exh</div>');
			$('.works_main').after('<div class="loading row add toremove">'+showText+'</div><div class="works_modules toremove row"></div>');
			$('.works_modules').load('index.php?id='+$id+'&type=221&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi1[wid]='+$work+'&tx_vawiz_pi2[module]='+$module, function() {
				showhidsub();
				$('.select_work_header_second').children().removeClass('hide');
				$('.select_work_header_second').children().addClass('tohide');
				$('.works_main').addClass('hide');
				$('.loading').remove();
				$('.menu_act').children().removeClass('act');
				$('.menu_act').children('.five').addClass('act');
				$('.menu_act').children('.six').addClass('act');
				$("#breadcrumb").children('.final').after('<li class="toremove">Events</li>'); //add item in breadcrumb
			});
		} 
	if ($module=='list_lid') { 
			$('.toremove').remove();
			$('.tohide').addClass('hide').removeClass('tohide');
			$('.sel_work').after('<div class="active_module toremove hide">lid</div>');
			$('.works_main').after('<div class="loading row add toremove">'+showText+'</div><div class="works_modules toremove row"></div>');
			$('.works_modules').load('index.php?id='+$id+'&type=221&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi1[wid]='+$work+'&tx_vawiz_pi2[module]='+$module, function() {
				showhidsub();
				$('.select_work_header_second').children().removeClass('hide');
				$('.select_work_header_second').children().addClass('tohide');
				$('.works_main').addClass('hide');
				$('.loading').remove();
				$('.menu_act').children().removeClass('act');
				$('.menu_act').children('.seven').addClass('act');
				$("#breadcrumb").children('.final').after('<li class="toremove">Literature</li>'); //add item in breadcrumb
			});
		} 
	
	
	
	return false;
 }; 

 
function vasearch($id,$artist,$module,$func){
	var showText = 'Form is loading...';
	$('.selector_container').remove();
	//$("div[id*='item_']").removeClass('secondary'); 
	//$('.update').remove();
	//DO INSTITUTIION SEARCH
	if ($module=='selbox_inst'||$module=='selbox_loc') {
		if ($module=='selbox_inst') {
			
			$('.inst').after('<div class="loading row add">'+showText+'</div><div class="selector_container"></div>'); }
		if ($module=='selbox_loc') {
			$('.loc').after('<div class="loading row add">'+showText+'</div><div class="selector_container"></div>'); }
	//alert('index.php?id='+$id+'&type=222&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi2[add]='+$module);
		$('.selector_container').load('index.php?id='+$id+'&type=222&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi2[add]='+$module, function() {
			
			$('.loading').remove();
		
				$('.selector_box_header').text('Search/Select Institution');
				$('.selector_link_inst').addClass('hide');
		
			
		});
	}
	if ($module=='selbox_lit') {
		var addtag = 'count';
		if ($func==2 ) addtag = 'addsub';
		//$('.addsub').after('<div class="loading row toremove add">'+showText+'</div><div class="selector_box_header toremove"></div><div id="add_form" class="row toremove"></div>');
				 
		$('.'+addtag).append('<div class="loading row add">'+showText+'</div><div class="selector_container"></div>');  
		$('.selector_container').load('index.php?id='+$id+'&type=222&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi2[add]='+$module, function() {
			//alert('index.php?id='+$id+'&type=222&tx_vawiz_pi1[aid]='+$artist+'&tx_vawiz_pi2[add]='+$module);
			
 
			
			$('.loading').remove();
		
				$('.selector_box_header').text('Search/Add Literature');
				$('.selector_link_inst').addClass('hide');
		
			
		});
	}
	return false;
 }; 


//searchbox
function vasubmit(form,id,aid,module,func){
 		if (func=='func_add') {
	
			if (validate('selbox_item')) {
						
					var queryString = $(".selbox_item :input").fieldSerialize();
					$.post('index.php?id='+id+'&tx_vawiz_pi1[aid]='+aid+'&type=222&tx_vawiz_pi2[table]=2&tx_vawiz_pi2[add]='+module, queryString,
						function(data){
						$(".form").children("div").removeClass('secondary'); //blur all except the primary form
						if (data!='') {
							if (module=='selbox_inst') {
								$('.form [name=inst]').replaceWith(data);
								$('.form [name=loc]').replaceWith(data);
							}
							if (module=='selbox_loc') {
								$('.form [name=loc]').replaceWith(data);
								$('.form [name=inst]').replaceWith(data);
							}
						}
						$('.selector_container').remove();
						$('.selector_link_inst').removeClass('hide');
					}); 
				} 
		}
		
		if (module=='selbox_inst'||module=='selbox_loc'||module=='selbox_lit') {
			var search_box_val = $('input[name=selector_box_val]').val();
			if (search_box_val == "") { 
				alert('Please use a search value!');
				return false;
			} else {
					//alert('index.php?id='+id+'&tx_vawiz_pi1[aid]='+aid+'&type=222&tx_vawiz_pi2[add]='+module+'&tx_vawiz_pi2[submit]='+search_box_val);
					$('.selector_results').load('index.php?id='+id+'&tx_vawiz_pi1[aid]='+aid+'&type=222&tx_vawiz_pi2[add]='+module+'&tx_vawiz_pi2[submit]='+search_box_val, function() {
					});
				}
		}
		
		if (module=='close_inst') {
			$('.selector_container').remove();
			$('.selector_link_inst').removeClass('hide');
			$(".form").children("div").removeClass('secondary'); //blur all except the primary form
		}
		if (module=='lid') {
					if (validate()==true) {
						var data_lit = $(".form_lit :input").fieldSerialize();
						var field1 = $('.form [name=author]').fieldValue(); 
						var sel_item = $('.sel_work').text();
						$.post('index.php?id='+id+'&tx_vawiz_pi1[aid]='+aid+'&type=222&tx_vawiz_pi1[wid]='+sel_item+'&tx_vawiz_pi2[add]='+module, data_lit,
							function(data){
							
							$(".form").children("div").removeClass('secondary'); //blur all except the primary form
							if (data!='') {
								$('.form_lit').remove();
								$('.list_lid').replaceWith(data);
							}
							$('.selector_container').remove();
							$('.selector_link_inst').removeClass('hide');
						}); 
					} 
							
		}
	return true;
	
};
	

//update on wid
function update_wid(form,func){
 	
	var id = $.url.param("id");
	var aid = $.url.param("tx_vawiz_pi1[aid]");
	var wid = $('.sel_work').text();
	//var edit_item = $('.edit_item').text();
	var module = $('.active_module').text();
	//if (!module) $('.sel_work').after('<div class="active_module toremove hide">wid</div>');
	var form_data = $('form[name='+module+'] :input').fieldSerialize();
	var add = $('#add_form').text() + $('#add_form_wid').text();
	var updateadd = 'update';
	if (add) updateadd = 'add';
	if (validate()==true) {
		if (func==1) var works_header = $("input[name=title]").val();
		//alert(aid);
		//alert('index.php?id='+id+'&tx_vawiz_pi1[aid]='+aid+'&type=221&tx_vawiz_pi1[wid]='+wid+'&type=221&tx_vawiz_pi2['+updateadd+']=1&tx_vawiz_pi2[module]='+module);
		$.post('index.php?id='+id+'&tx_vawiz_pi1[aid]='+aid+'&type=221&tx_vawiz_pi1[wid]='+wid+'&type=221&tx_vawiz_pi2['+updateadd+']=1&tx_vawiz_pi2[module]='+module, form_data,
			function(data){
			$(".form").children("div").removeClass('secondary'); //blur all except the primary form
			 //$('.works_main').replaceWith(data);
				
				if (module=='wid') {
					if (add) wid = data;
					listworks(id,aid,data,'list_docs',1);
					$('.update').wrap('<div id="form_'+data+'"></div>');
					$('.works_header').html('<div class="col space_l act"><h2><span class="gray">'+works_header+'</span></h2></div>');
					if (add) change_onclick(id,aid,data);
				}
			if (data!='') {
				 $('.listinfo_wrap').replaceWith(data);
				  if (module=='key')toggle_keys();
				 hide_edit();
			} 
		}); 
		return false;
	} 
	return false;
}; 

//change_onclick
function change_onclick(id,aid,data){
	$(".select_work_header").children(".one").children("a").attr("onClick", 'listworks('+id+','+aid+','+data+',\'list_info\'); return false;');
	$(".select_work_header").children(".two").children("a").attr("onClick", 'listworks('+id+','+aid+','+data+',\'list_docs\'); return false;');
	$(".select_work_header").children(".three").children("a").attr("onClick", 'listworks('+id+','+aid+','+data+',\'list_keys\'); return false;'); 
	$(".select_work_header").children(".four").children("a").attr("onClick", 'listworks('+id+','+aid+','+data+',\'list_tec\'); return false;'); 
	$(".select_work_header").children(".five").children("a").attr("onClick", 'listworks('+id+','+aid+','+data+',\'list_exh\'); return false;'); 
	$(".select_work_header_second").children(".six").children("a").attr("onClick", 'listworks('+id+','+aid+','+data+',\'list_exh\'); return false;'); 
	$(".select_work_header_second").children(".seven").children("a").attr("onClick", 'listworks('+id+','+aid+','+data+',\'list_lid\'); return false;'); 
	$(".select_work_footer").children(".one").children("a").attr("onClick", 'listworks('+id+','+aid+','+data+',\'list_info\'); return false;');
	$(".select_work_footer").children(".two").children("a").attr("onClick", 'listworks('+id+','+aid+','+data+',\'list_docs\'); return false;');
	$(".select_work_footer").children(".three").children("a").attr("onClick", 'listworks('+id+','+aid+','+data+',\'list_keys\'); return false;'); 
	$(".select_work_footer").children(".four").children("a").attr("onClick", 'listworks('+id+','+aid+','+data+',\'list_tec\'); return false;'); 
	$(".select_work_footer").children(".five").children("a").attr("onClick", 'listworks('+id+','+aid+','+data+',\'list_exh\'); return false;'); 
	$(".select_work_footer").children(".six").children("a").attr("onClick", 'listworks('+id+','+aid+','+data+',\'list_exh\'); return false;'); 
	$(".select_work_footer").children(".seven").children("a").attr("onClick", 'listworks('+id+','+aid+','+data+',\'list_lid\'); return false;'); 
}

//update
function update(form,field){
	
	if (field=='bid') { // check biography form
		return validate();
	}
	if (field=='aid') { // check biography form
		var text = $('input[name=last_name]').val();
		$('input[name=submitted]').after('<input type="hidden" name="search_art" value="'+text+'">'); //add search_exh with value
		$('input[name=search_art]').val(text);
		return validate();
		
	}
	if (field=='eid'||field=='sid') { // check events form 
			var text = $('textarea[name=title]').val();
			$('input[name=submitted]').after('<input type="hidden" name="search_exh" value="'+text+'">'); //add search_exh with value
			return validate();
		}  
	if (field=='lid') { // check events form 
			var text = $('textarea[name=title]').val();
			$('input[name=submitted]').after('<input type="hidden" name="search_lit" value="'+text+'">'); //add search_exh with value
			return validate();
		} else {
			return validate();
			}

	return true;
	
}; 

//add req
function addreq(){
		
		$('.req_l').each(function(i){
			$(this).append('<span class="red">*</span>');
	});	 
};

//select field
function vaselect(type,formtag,itemid){
		 if (formtag=='selbox_lit' && type!='select_artist') {
			 	var data_lit = 'uid_foreign='+itemid;
				var aid = $.url.param("tx_vawiz_pi1[aid]");
				var id = $.url.param("id");
				var wid = $('.sel_work').text();
				//alert('index.php?id='+id+'&tx_vawiz_pi1[aid]='+aid+'&type=221&tx_vawiz_pi2[module]='+formtag+'&tx_vawiz_pi2[wid]='+wid+'&tx_vawiz_pi2[add]='+itemid);
				 
				$.post('index.php?id='+id+'&tx_vawiz_pi1[aid]='+aid+'&type=221&tx_vawiz_pi2[module]='+formtag+'&tx_vawiz_pi1[wid]='+wid+'&tx_vawiz_pi2[add]='+itemid, data_lit,
					function(data){
					$(".form").children("div").removeClass('secondary'); //blur all except the primary form
					if (data!='') {
						$('.selector_container').remove();
						$('.list_lid').replaceWith(data);
					}
					$('.selector_container').remove();
					$('.selector_link_inst').removeClass('hide');
				}); 
			 } else if (type=='select_artist') {
				var data_lit = 'uid_foreign='+itemid;
				var aid = $.url.param("tx_vawiz_pi1[aid]");
				var id = $.url.param("id");
				var wid = $('.sel_work').text();
				//alert('index.php?id='+id+'&tx_vawiz_pi1[aid]='+aid+'&type=221&tx_vawiz_pi2[module]='+type+'&tx_vawiz_pi2[wid]='+wid+'&tx_vawiz_pi2[add]='+itemid);
				$.post('index.php?id='+id+'&tx_vawiz_pi1[aid]='+aid+'&type=221&tx_vawiz_pi2[module]='+type+'&tx_vawiz_pi1[wid]='+wid+'&tx_vawiz_pi2[add]='+itemid, data_lit,
					function(data){
					$(".form").children("div").removeClass('secondary'); //blur all except the primary form
					if (data!='') {
						$('.selector_container').remove();
						$('.header_lit').replaceWith(data);
						hide_edit();
					}
					$('.selector_container').remove();
					$('.selector_link_inst').removeClass('hide');
				}); 
				 } else {
				 //$(".form [name='" + formtag + "']").selectOptions(itemid,true);
				 if (formtag=='selbox_inst') $(".form [name=inst]").selectOptions(itemid,true);
				 if (formtag=='selbox_loc') $(".form [name=loc]").selectOptions(itemid,true);
				 //$(".form [name='" + formtag + "']").selectOptions(itemid,true);
				 $('.selector_container').remove();
				 $('.selector_link_inst').removeClass('hide');
		 
				 }
 	
};

function closeit(closetag,showtag){
		 $('.'+closetag).remove();
		 $('.'+showtag).removeClass('hide');
};

//upload
function upload(){
	$('#swfupload-control').swfupload({
		upload_url: "http://www.virtualart.at/typo3conf/ext/va_wiz/pi1/res/js/upload_1.php",
		file_size_limit : "102400",
		file_types : "*.jpg;*.gif;*.jpeg;*.tif*.png",
		file_types_description : "All Files",
		file_upload_limit : "0",
		flash_url : "http://www.virtualart.at/typo3conf/ext/va_wiz/pi1/res/js/swfupload.swf",
		button_image_url : 'typo3conf/ext/va_wiz/pi1/res/js/upload.png',
		button_width : 61,
		button_height : 22,
		button_placeholder : $('#fileField')[0],
		debug: false,
		custom_settings : {something : "here"}
	})
		.bind('swfuploadLoaded', function(event){
			$('#log').html('<li>Select Image</li>');
		})
		.bind('fileQueued', function(event, file){
			$('#log').html('<li>File queued - '+file.name+'</li>');
			// start the upload since it's queued
			$(this).swfupload('startUpload');
		})
		.bind('fileQueueError', function(event, file, errorCode, message){
			$('#log').html('<li>File queue error - '+message+'</li>');
		})
		.bind('fileDialogStart', function(event){
			$('#log').html('<li>File dialog start</li>');
		})
		.bind('fileDialogComplete', function(event, numFilesSelected, numFilesQueued){
			$('#log').html('<li>File dialoge completed</li>');
			
		})
		.bind('uploadStart', function(event, file){
			$('#log').html('<li>Upload start - '+file.name+'</li>');
		})
		.bind('uploadProgress', function(event, file, bytesLoaded){
			$('#log').html('<li>Upload progress - '+bytesLoaded+'</li>');
		})
		.bind('uploadSuccess', function(event, file, serverData){
			$('#log').html('<li>Upload success - '+file.name+'</li>');
		})
		.bind('uploadComplete', function(event, file){
			$('#log').html('<li>Image-Upload complete - '+file.name+'</li>');
			// upload has completed, lets try the next one in the queue
			$('input[name=file]').attr('value', file.name); 
			$(this).swfupload('startUpload');
			//update_wid();
		})
		.bind('uploadError', function(event, file, errorCode, message){
			$('#log').html('<li>Upload error - '+message+'</li>');
		});
		
		
		
		$('#swfupload-control-vid').swfupload({
		upload_url: "http://www.virtualart.at/typo3conf/ext/va_wiz/pi1/res/js/upload_2.php",
		file_size_limit : "102400",
		file_types : "*.mov",
		file_types_description : "Only .mov Files are allowed.<a href=#>help</a>",
		file_upload_limit : "0",
		flash_url : "http://www.virtualart.at/typo3conf/ext/va_wiz/pi1/res/js/swfupload.swf",
		button_image_url : 'typo3conf/ext/va_wiz/pi1/res/js/upload.png',
		button_width : 61,
		button_height : 22,
		button_placeholder : $('#fileField')[0],
		debug: false,
		custom_settings : {something : "here"}
	})
		.bind('swfuploadLoaded', function(event){
			$('#log-vid').html('<li>Select Mov-File</li>');
		})
		.bind('fileQueued', function(event, file){
			$('#log-vid').html('<li>File queued - '+file.name+'</li>');
			// start the upload since it's queued
			$(this).swfupload('startUpload');
		})
		.bind('fileQueueError', function(event, file, errorCode, message){
			$('#log-vid').html('<li>File queue error - '+message+'</li>');
		})
		.bind('fileDialogStart', function(event){
			$('#log-vid').html('<li>File dialog start</li>');
		})
		.bind('fileDialogComplete', function(event, numFilesSelected, numFilesQueued){
			$('#log-vid').html('<li>File dialoge completed</li>');
			
		})
		.bind('uploadStart', function(event, file){
			$('#log-vid').html('<li>Upload start - '+file.name+'</li>');
		})
		.bind('uploadProgress', function(event, file, bytesLoaded){
			$('#log-vid').html('<li>Upload progress - '+bytesLoaded+'</li>');
		})
		.bind('uploadSuccess', function(event, file, serverData){
			$('#log-vid').html('<li>Upload success - '+file.name+'</li>');
		})
		.bind('uploadComplete', function(event, file){
			$('#log-vid').html('<li>Video-Upload complete - '+file.name+'</li>');
			// upload has completed, lets try the next one in the queue
			$('input[name=vid]').attr('value', file.name); 
			$(this).swfupload('startUpload');
			//update_wid();
		})
		.bind('uploadError', function(event, file, errorCode, message){
			$('#log-vid').html('<li>Upload error - '+message+'</li>');
		});
	
};	




//delete
function deleteit($href,$type){
 		var wid = $('.sel_work').text();
		var module = $('.active_module').text();
		
		if ($type == 1 || !$type) {
			 if (confirm('Are you sure to delete this item')) {
				window.open($href, '_top');
				}
		} else {
			  
			 if (confirm('Are you sure to delete this item')) {
				
				if (module=='wid') {
					$('.works').load($href+'&type=221', function() {
						 hide_edit();
					});
				} else {
					
					$('.listinfo_wrap').load($href+'&type=221&tx_vawiz_pi1[wid]='+wid, function() {
						 hide_edit();
					});
					}
			 }
			}

        return true;
};

//cancleit
function cancelit(){
	var $item2 = $('input[name=uid]').val();
	
	$('#subform_'+$item2).remove();
	$('#subitem_'+$item2).removeClass('hide');
	$('.addsub').removeClass('hide');
	
	$('.selector_box_header').remove();
	$('#add_form').remove();
	$('.loading').remove();
	
	$(".listinfo_wrap").children("div").removeClass('secondary'); //blur all except the primary form
	
	hide_edit();	
}

//toggle_keys
function toggle_keys() {
	$(".selected_keys input[type=checkbox][checked]").each(function(){ 
	$(this).parents().removeClass('hide');
	});
	$("a.toggle").click(function() {
	$(this).next("ul").toggle();
	  });
 
	$("input[name*=keysel]").click(function() {
		var uid = $(this).val();
		var check = $(this).is(':checked');
		
		$('.select_keys input[value='+uid+']').attr('checked', check);
	  });
	$("input[name*=key]").click(function() {
		var uid = $(this).val();
		var check = $(this).is(':checked');
		$('.selected_keys input[value='+uid+']').attr('checked', check);
	  });
}

//PUBLISH
function publish($id,$userid,$aid,$item,$table,$pub){
		
		if ($pub) {
					 var text_promt = 'REQUEST PUBLISHING - Fill in a message for the virtualart editors and press "Ok". Please note: Message has to be filled in.';
					 var text_publish = 'Change the publish state to: ';
					 var text_confirm = 'Message sent. Publish state: ';
					 var text_confirm_private = 'New publish state: ';
					if (validate()==true) {
							var data_pub = $(".form_lit :input").fieldSerialize();
							var sent_email = '';
							var sent_mission = '';
						 if ($pub=='-1') var publish_state = '"REQUEST PUBLISHING"';
						 if ($pub=='-2') var publish_state = '"REMIND PUBLISHING"';
						 if ($pub=='1') var publish_state = '"PUBLISH ITEM"';
						 if ($pub=='3') var publish_state = '"FEATURE ITEM"';
						 if ($pub=='-5') var publish_state = '"MAKE PRIVAT"';
						 if ($pub=='-1' || $pub=='-2') var message = prompt(text_promt);
						 if (message!=null && message!="") var sent_email = 1;
						 if  ($pub == '-1' || $pub == '-2') var sent_mission = 1;
						 if (!sent_email && !sent_mission) var confirm_val = confirm(text_publish+publish_state);
						 if ($pub=='-5') var message = 'Sent since Editor report is enabled'; 
						 if(sent_mission && sent_email  || $pub!='-1' && confirm_val) {
							if ($pub=='-1' || $pub=='-2') send_email(message,$userid,$id,$aid,$table,$item,$pub);
							if ($pub=='-5') send_email(message,$userid,$id,$aid,$table,$item,$pub);
							$.post('index.php?id='+$id+'&tx_vawiz_pi1[aid]='+$aid+'&type=223&tx_vawiz_pi2['+$table+']='+$item+'&tx_vawiz_pi2[pub]='+$pub, data_pub,
								function(data){
								$(".form").children("div").removeClass('secondary'); //blur all except the primary form
								if (data!='') {
									$('#publish_buttons').replaceWith(data);
								} 
							}); 
							
							if ($pub=='-1' && sent_email || $pub=='-2' && sent_email) alert(text_confirm+publish_state);
							if ($pub=='-5' && sent_email) alert(text_confirm_private);

						 }  
							
						 
					} 
							
		}
        return true;
};

function show_prompt($message,$userid,$id,$aid,$table,$item,$pub) {
	var message=prompt($message);
	if (message!=null && message!="") {
	  
	   send_email(message,$userid,$id,$aid,$table,$item,$pub);
	  }
}

function send_email(message,$userid,$id,$aid,$table,$item,$pub) {
	if(message!='') {
			 
			 var data_pub = {
				aid : $aid,
				userID : $userid,
				email_content : message,
				item_id : $item
			}
			$.post('index.php?id='+$id+'&tx_vawiz_pi1[aid]='+$aid+'&type=223&tx_vawiz_pi2['+$table+']='+$item+'&tx_vawiz_pi2[email]='+$pub, data_pub,
																						 
				function(data){
					$(".form").children("div").removeClass('secondary'); //blur all except the primary form
					if (data!='') {
						$('#publish_buttons').replaceWith(data);
					}
			});
		} 
}





// validate forms with class form and fields with class req
function validate(formid){
	var req_message = 'Please fill out the required fields! The requred fields are marked in red.';
	var checkval = 0;
	if (!formid) formid = 'form';
	$('.'+formid).find('.req').each(function(){ 
		if ($(this).fieldValue() == '') {
			checkval = 1;
			$(this).addClass('showreq');
		} else {
			$(this).removeClass('showreq');
			}
	});
	if (checkval==1) {
		alert(req_message);
		return false;
		} else {
			return true;
			}
};
 


//hideedit
function hide_edit(){
	//hide edit buttons just shown when hover
	$('.edit').addClass('hide');
	$('.docs').children('.edit').addClass('hide');
	$("div[id*='item_']").hover( function () {
		$(this).children('.edit').removeClass('hide');
		$(this).removeClass('secondary');
		}, function() {
  			$(this).children('.edit').addClass('hide');
	});
	$("div[id*='subitem_']").hover( function () {
		$(this).children('.edit').removeClass('hide');
		$(this).removeClass('secondary');
		}, function() {
			$(this).children('.edit').addClass('hide');
			$(this).removeClass('secondary');
	});
}

$(window).load(function () {
	
	
	var update_item = $.url.param("tx_vawiz_pi2[update]");
	var add_item = $.url.param("tx_vawiz_pi2[add]");
	if (update_item) {
		$('#item_'+update_item).addClass('updated');
	}
	if (add_item) {
		$('.last_item').addClass('added');
	}
	if (add_item=='ada') {
			var id = $.url.param("id");
			$('#add_form').load('index.php?id='+id+'&type=221&&tx_vawiz_pi2[add]=ada', function() {
			$('.noartist').addClass('hide');
		});
		return false;
	}
	
	//hide edit buttons just shown when hover
	hide_edit();
	
	 
	// stops auto submit with return key
	$('input').live("keypress", function(e) {
                /* ENTER PRESSED*/
                if (e.keyCode == 13) {
                    /* FOCUS ELEMENT */
                    var inputs = $(this).parents("form").eq(0).find(":input");
                    var idx = inputs.index(this);
					
					
					
                    if (idx == inputs.length - 1) {
                        inputs[0].select();
						
                    } else {
                      	
					  
							
						inputs[idx + 1].focus(); //  handles submit buttons
                        inputs[idx + 1].select();
						
						// if (inputs[idx].className == 'submit') { }
                    }
					//submit if next input field has class 'submit'
					if (inputs[idx + 1].className == 'submit') {
							inputs[idx].submit();
							return true;
					}
                    return false;
                }
            });
      

});						   



/*!
* Various jQuery Plugins
*/

/* Copyright (c) 2006-2008 Sam Collett (http://www.texotela.co.uk) */
;(function(h){h.fn.addOption=function(){var j=function(a,f,c,g){var d=document.createElement("option");d.value=f,d.text=c;var b=a.options;var e=b.length;if(!a.cache){a.cache={};for(var i=0;i<e;i++){a.cache[b[i].value]=i}}if(typeof a.cache[f]=="undefined")a.cache[f]=e;a.options[a.cache[f]]=d;if(g){d.selected=true}};var k=arguments;if(k.length==0)return this;var l=true;var m=false;var n,o,p;if(typeof(k[0])=="object"){m=true;n=k[0]}if(k.length>=2){if(typeof(k[1])=="boolean")l=k[1];else if(typeof(k[2])=="boolean")l=k[2];if(!m){o=k[0];p=k[1]}}this.each(function(){if(this.nodeName.toLowerCase()!="select")return;if(m){for(var a in n){j(this,a,n[a],l)}}else{j(this,o,p,l)}});return this};h.fn.ajaxAddOption=function(c,g,d,b,e){if(typeof(c)!="string")return this;if(typeof(g)!="object")g={};if(typeof(d)!="boolean")d=true;this.each(function(){var f=this;h.getJSON(c,g,function(a){h(f).addOption(a,d);if(typeof b=="function"){if(typeof e=="object"){b.apply(f,e)}else{b.call(f)}}})});return this};h.fn.removeOption=function(){var d=arguments;if(d.length==0)return this;var b=typeof(d[0]);var e,i;if(b=="string"||b=="object"||b=="function"){e=d[0];if(e.constructor==Array){var j=e.length;for(var k=0;k<j;k++){this.removeOption(e[k],d[1])}return this}}else if(b=="number")i=d[0];else return this;this.each(function(){if(this.nodeName.toLowerCase()!="select")return;if(this.cache)this.cache=null;var a=false;var f=this.options;if(!!e){var c=f.length;for(var g=c-1;g>=0;g--){if(e.constructor==RegExp){if(f[g].value.match(e)){a=true}}else if(f[g].value==e){a=true}if(a&&d[1]===true)a=f[g].selected;if(a){f[g]=null}a=false}}else{if(d[1]===true){a=f[i].selected}else{a=true}if(a){this.remove(i)}}});return this};h.fn.sortOptions=function(e){var i=h(this).selectedValues();var j=typeof(e)=="undefined"?true:!!e;this.each(function(){if(this.nodeName.toLowerCase()!="select")return;var c=this.options;var g=c.length;var d=[];for(var b=0;b<g;b++){d[b]={v:c[b].value,t:c[b].text}}d.sort(function(a,f){o1t=a.t.toLowerCase(),o2t=f.t.toLowerCase();if(o1t==o2t)return 0;if(j){return o1t<o2t?-1:1}else{return o1t>o2t?-1:1}});for(var b=0;b<g;b++){c[b].text=d[b].t;c[b].value=d[b].v}}).selectOptions(i,true);return this};h.fn.selectOptions=function(g,d){var b=g;var e=typeof(g);if(e=="object"&&b.constructor==Array){var i=this;h.each(b,function(){i.selectOptions(this,d)})};var j=d||false;if(e!="string"&&e!="function"&&e!="object")return this;this.each(function(){if(this.nodeName.toLowerCase()!="select")return this;var a=this.options;var f=a.length;for(var c=0;c<f;c++){if(b.constructor==RegExp){if(a[c].value.match(b)){a[c].selected=true}else if(j){a[c].selected=false}}else{if(a[c].value==b){a[c].selected=true}else if(j){a[c].selected=false}}}});return this};h.fn.copyOptions=function(g,d){var b=d||"selected";if(h(g).size()==0)return this;this.each(function(){if(this.nodeName.toLowerCase()!="select")return this;var a=this.options;var f=a.length;for(var c=0;c<f;c++){if(b=="all"||(b=="selected"&&a[c].selected)){h(g).addOption(a[c].value,a[c].text)}}});return this};h.fn.containsOption=function(g,d){var b=false;var e=g;var i=typeof(e);var j=typeof(d);if(i!="string"&&i!="function"&&i!="object")return j=="function"?this:b;this.each(function(){if(this.nodeName.toLowerCase()!="select")return this;if(b&&j!="function")return false;var a=this.options;var f=a.length;for(var c=0;c<f;c++){if(e.constructor==RegExp){if(a[c].value.match(e)){b=true;if(j=="function")d.call(a[c],c)}}else{if(a[c].value==e){b=true;if(j=="function")d.call(a[c],c)}}}});return j=="function"?this:b};h.fn.selectedValues=function(){var a=[];this.selectedOptions().each(function(){a[a.length]=this.value});return a};h.fn.selectedTexts=function(){var a=[];this.selectedOptions().each(function(){a[a.length]=this.text});return a};h.fn.selectedOptions=function(){return this.find("option:selected")}})(jQuery);



//read url params // http://ajaxcssblog.com/jquery/url-read-request-variables/
;(function($){$.url={};$.extend($.url,{_params:{},init:function(){var paramsRaw="";try{paramsRaw=(document.location.href.split("?",2)[1]||"").split("#")[0].split("&")||[];for(var i=0;i<paramsRaw.length;i++){var single=paramsRaw[i].split("=");if(single[0])this._params[single[0]]=unescape(single[1]);}}catch(e){alert(e);}},param:function(name){return this._params[name]||"";},paramAll:function(){return this._params;}});$.url.init();})(jQuery);


/*
 * jQuery Form plugin at: http://malsup.com/jquery/form/ compressed by http://www.creativyst.com/Prod/3/
 */
;(function($){$.fn.ajaxSubmit=function(options){if(!this.length){log('ajaxSubmit: skipping submit process - no element selected');return this;}
if(typeof options=='function')
options={success:options};var url=$.trim(this.attr('action'));if(url){url=(url.match(/^([^#]+)/)||[])[1];}
url=url||window.location.href||''
options=$.extend({url:url,type:this.attr('method')||'GET'},options||{});var veto={};this.trigger('form-pre-serialize',[this,options,veto]);if(veto.veto){log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');return this;}
if(options.beforeSerialize&&options.beforeSerialize(this,options)===false){log('ajaxSubmit: submit aborted via beforeSerialize callback');return this;}
var a=this.formToArray(options.semantic);if(options.data){options.extraData=options.data;for(var n in options.data){if(options.data[n]instanceof Array){for(var k in options.data[n])
a.push({name:n,value:options.data[n][k]});}
else
a.push({name:n,value:options.data[n]});}}
if(options.beforeSubmit&&options.beforeSubmit(a,this,options)===false){log('ajaxSubmit: submit aborted via beforeSubmit callback');return this;}
this.trigger('form-submit-validate',[a,this,options,veto]);if(veto.veto){log('ajaxSubmit: submit vetoed via form-submit-validate trigger');return this;}
var q=$.param(a);if(options.type.toUpperCase()=='GET'){options.url+=(options.url.indexOf('?')>=0?'&':'?')+q;options.data=null;}
else
options.data=q;var $form=this,callbacks=[];if(options.resetForm)callbacks.push(function(){$form.resetForm();});if(options.clearForm)callbacks.push(function(){$form.clearForm();});if(!options.dataType&&options.target){var oldSuccess=options.success||function(){};callbacks.push(function(data){$(options.target).html(data).each(oldSuccess,arguments);});}
else if(options.success)
callbacks.push(options.success);options.success=function(data,status){for(var i=0,max=callbacks.length;i<max;i++)
callbacks[i].apply(options,[data,status,$form]);};var files=$('input:file',this).fieldValue();var found=false;for(var j=0;j<files.length;j++)
if(files[j])
found=true;var multipart=false;if(options.iframe||found||multipart){if(options.closeKeepAlive)
$.get(options.closeKeepAlive,fileUpload);else
fileUpload();}
else
$.ajax(options);this.trigger('form-submit-notify',[this,options]);return this;function fileUpload(){var form=$form[0];if($(':input[name=submit]',form).length){alert('Error: Form elements must not be named "submit".');return;}
var opts=$.extend({},$.ajaxSettings,options);var s=$.extend(true,{},$.extend(true,{},$.ajaxSettings),opts);var id='jqFormIO'+(new Date().getTime());var $io=$('<iframe id="'+id+'" name="'+id+'" src="about:blank" />');var io=$io[0];$io.css({position:'absolute',top:'-1000px',left:'-1000px'});var xhr={aborted:0,responseText:null,responseXML:null,status:0,statusText:'n/a',getAllResponseHeaders:function(){},getResponseHeader:function(){},setRequestHeader:function(){},abort:function(){this.aborted=1;$io.attr('src','about:blank');}};var g=opts.global;if(g&&!$.active++)$.event.trigger("ajaxStart");if(g)$.event.trigger("ajaxSend",[xhr,opts]);if(s.beforeSend&&s.beforeSend(xhr,s)===false){s.global&&$.active--;return;}
if(xhr.aborted)
return;var cbInvoked=0;var timedOut=0;var sub=form.clk;if(sub){var n=sub.name;if(n&&!sub.disabled){options.extraData=options.extraData||{};options.extraData[n]=sub.value;if(sub.type=="image"){options.extraData[name+'.x']=form.clk_x;options.extraData[name+'.y']=form.clk_y;}}}
setTimeout(function(){var t=$form.attr('target'),a=$form.attr('action');form.setAttribute('target',id);if(form.getAttribute('method')!='POST')
form.setAttribute('method','POST');if(form.getAttribute('action')!=opts.url)
form.setAttribute('action',opts.url);if(!options.skipEncodingOverride){$form.attr({encoding:'multipart/form-data',enctype:'multipart/form-data'});}
if(opts.timeout)
setTimeout(function(){timedOut=true;cb();},opts.timeout);var extraInputs=[];try{if(options.extraData)
for(var n in options.extraData)
extraInputs.push($('<input type="hidden" name="'+n+'" value="'+options.extraData[n]+'" />').appendTo(form)[0]);$io.appendTo('body');io.attachEvent?io.attachEvent('onload',cb):io.addEventListener('load',cb,false);form.submit();}
finally{form.setAttribute('action',a);t?form.setAttribute('target',t):$form.removeAttr('target');$(extraInputs).remove();}},10);var nullCheckFlag=0;function cb(){if(cbInvoked++)return;io.detachEvent?io.detachEvent('onload',cb):io.removeEventListener('load',cb,false);var ok=true;try{if(timedOut)throw'timeout';var data,doc;doc=io.contentWindow?io.contentWindow.document:io.contentDocument?io.contentDocument:io.document;if((doc.body==null||doc.body.innerHTML=='')&&!nullCheckFlag){nullCheckFlag=1;cbInvoked--;setTimeout(cb,100);return;}
xhr.responseText=doc.body?doc.body.innerHTML:null;xhr.responseXML=doc.XMLDocument?doc.XMLDocument:doc;xhr.getResponseHeader=function(header){var headers={'content-type':opts.dataType};return headers[header];};if(opts.dataType=='json'||opts.dataType=='script'){var ta=doc.getElementsByTagName('textarea')[0];xhr.responseText=ta?ta.value:xhr.responseText;}
else if(opts.dataType=='xml'&&!xhr.responseXML&&xhr.responseText!=null){xhr.responseXML=toXml(xhr.responseText);}
data=$.httpData(xhr,opts.dataType);}
catch(e){ok=false;$.handleError(opts,xhr,'error',e);}
if(ok){opts.success(data,'success');if(g)$.event.trigger("ajaxSuccess",[xhr,opts]);}
if(g)$.event.trigger("ajaxComplete",[xhr,opts]);if(g&&!--$.active)$.event.trigger("ajaxStop");if(opts.complete)opts.complete(xhr,ok?'success':'error');setTimeout(function(){$io.remove();xhr.responseXML=null;},100);};function toXml(s,doc){if(window.ActiveXObject){doc=new ActiveXObject('Microsoft.XMLDOM');doc.async='false';doc.loadXML(s);}
else
doc=(new DOMParser()).parseFromString(s,'text/xml');return(doc&&doc.documentElement&&doc.documentElement.tagName!='parsererror')?doc:null;};};};$.fn.ajaxForm=function(options){return this.ajaxFormUnbind().bind('submit.form-plugin',function(){$(this).ajaxSubmit(options);return false;}).each(function(){$(":submit,input:image",this).bind('click.form-plugin',function(e){var form=this.form;form.clk=this;if(this.type=='image'){if(e.offsetX!=undefined){form.clk_x=e.offsetX;form.clk_y=e.offsetY;}else if(typeof $.fn.offset=='function'){var offset=$(this).offset();form.clk_x=e.pageX-offset.left;form.clk_y=e.pageY-offset.top;}else{form.clk_x=e.pageX-this.offsetLeft;form.clk_y=e.pageY-this.offsetTop;}}
setTimeout(function(){form.clk=form.clk_x=form.clk_y=null;},10);});});};$.fn.ajaxFormUnbind=function(){this.unbind('submit.form-plugin');return this.each(function(){$(":submit,input:image",this).unbind('click.form-plugin');});};$.fn.formToArray=function(semantic){var a=[];if(this.length==0)return a;var form=this[0];var els=semantic?form.getElementsByTagName('*'):form.elements;if(!els)return a;for(var i=0,max=els.length;i<max;i++){var el=els[i];var n=el.name;if(!n)continue;if(semantic&&form.clk&&el.type=="image"){if(!el.disabled&&form.clk==el){a.push({name:n,value:$(el).val()});a.push({name:n+'.x',value:form.clk_x},{name:n+'.y',value:form.clk_y});}
continue;}
var v=$.fieldValue(el,true);if(v&&v.constructor==Array){for(var j=0,jmax=v.length;j<jmax;j++)
a.push({name:n,value:v[j]});}
else if(v!==null&&typeof v!='undefined')
a.push({name:n,value:v});}
if(!semantic&&form.clk){var $input=$(form.clk),input=$input[0],n=input.name;if(n&&!input.disabled&&input.type=='image'){a.push({name:n,value:$input.val()});a.push({name:n+'.x',value:form.clk_x},{name:n+'.y',value:form.clk_y});}}
return a;};$.fn.formSerialize=function(semantic){return $.param(this.formToArray(semantic));};$.fn.fieldSerialize=function(successful){var a=[];this.each(function(){var n=this.name;if(!n)return;var v=$.fieldValue(this,successful);if(v&&v.constructor==Array){for(var i=0,max=v.length;i<max;i++)
a.push({name:n,value:v[i]});}
else if(v!==null&&typeof v!='undefined')
a.push({name:this.name,value:v});});return $.param(a);};$.fn.fieldValue=function(successful){for(var val=[],i=0,max=this.length;i<max;i++){var el=this[i];var v=$.fieldValue(el,successful);if(v===null||typeof v=='undefined'||(v.constructor==Array&&!v.length))
continue;v.constructor==Array?$.merge(val,v):val.push(v);}
return val;};$.fieldValue=function(el,successful){var n=el.name,t=el.type,tag=el.tagName.toLowerCase();if(typeof successful=='undefined')successful=true;if(successful&&(!n||el.disabled||t=='reset'||t=='button'||(t=='checkbox'||t=='radio')&&!el.checked||(t=='submit'||t=='image')&&el.form&&el.form.clk!=el||tag=='select'&&el.selectedIndex==-1))
return null;if(tag=='select'){var index=el.selectedIndex;if(index<0)return null;var a=[],ops=el.options;var one=(t=='select-one');var max=(one?index+1:ops.length);for(var i=(one?index:0);i<max;i++){var op=ops[i];if(op.selected){var v=op.value;if(!v)
v=(op.attributes&&op.attributes['value']&&!(op.attributes['value'].specified))?op.text:op.value;if(one)return v;a.push(v);}}
return a;}
return el.value;};$.fn.clearForm=function(){return this.each(function(){$('input,select,textarea',this).clearFields();});};$.fn.clearFields=$.fn.clearInputs=function(){return this.each(function(){var t=this.type,tag=this.tagName.toLowerCase();if(t=='text'||t=='password'||tag=='textarea')
this.value='';else if(t=='checkbox'||t=='radio')
this.checked=false;else if(tag=='select')
this.selectedIndex=-1;});};$.fn.resetForm=function(){return this.each(function(){if(typeof this.reset=='function'||(typeof this.reset=='object'&&!this.reset.nodeType))
this.reset();});};$.fn.enable=function(b){if(b==undefined)b=true;return this.each(function(){this.disabled=!b;});};$.fn.selected=function(select){if(select==undefined)select=true;return this.each(function(){var t=this.type;if(t=='checkbox'||t=='radio')
this.checked=select;else if(this.tagName.toLowerCase()=='option'){var $sel=$(this).parent('select');if(select&&$sel[0]&&$sel[0].type=='select-one'){$sel.find('option').selected(false);}
this.selected=select;}});};function log(){if($.fn.ajaxSubmit.debug&&window.console&&window.console.log)
window.console.log('[jquery.form] '+Array.prototype.join.call(arguments,''));};})(jQuery);