/*function SubmitForm(form_id, extra_1, extra_2, extra_3, extra_4, extra_5, extra_6, extra_7, extra_8) {
	advAJAX.submit(document.getElementById(form_id), {
		parameters : {
			"ajax" : 1,
			"extra_1" : extra_1 || '',
			"extra_2" : extra_2 || '',
			"extra_3" : extra_3 || '',
			"extra_4" : extra_4 || '',
			"extra_5" : extra_5 || '',
			"extra_6" : extra_6 || '',
			"extra_7" : extra_7 || '',
			"extra_8" : extra_8 || ''
		},
		onInitialization : function(obj) {
			RestoreFormFieldsBorder(form_id);
			if(document.getElementById("submitBtn")) {
				submit_value = document.getElementById("submitBtn").value;
				document.getElementById("submitBtn").value = "Wait...";
			}	
		},
		onComplete : function() {
		
		},
		onSuccess : function(obj) {
			if(document.getElementById("submitBtn")) {
				document.getElementById("submitBtn").value = submit_value;
			}
			var doc = document.getElementById('info_container');
			var doc_inner = document.getElementById('info_container_inner');
			var doc_message = document.getElementById('message_container');
			var message_inner = document.getElementById('message_container_inner');
			
			if (obj.responseText) {
				var xmlDoc = loadXMLString(obj.responseText);
				
				var root = xmlDoc.getElementsByTagName("ajax")[0];
				var url = xmlDoc.getElementsByTagName("url")[0];
				var mess = xmlDoc.getElementsByTagName("mess")[0];
				
				var message = '';
				var text = '';
				
				if (root) {
					for (var iNode = 0; iNode < root.childNodes.length; iNode++) {
						var node = root.childNodes.item(iNode);
						
						var item_id = node.nodeName;
						
						var type = '';
						if (node.attributes.getNamedItem("type"))
							type = node.attributes.getNamedItem("type").nodeValue;
						
						var msg = ''
						if (node.attributes.getNamedItem("msg"))
							msg = node.attributes.getNamedItem("msg").nodeValue;
						
						var button = '';
						if (node.attributes.getNamedItem("button")) {
							button = '&nbsp;&nbsp;&nbsp;<input type="button" name="modify" value="' + node.attributes.getNamedItem("button").nodeValue + ' " class="btn_extra_large" onclick="' + node.attributes.getNamedItem("button_link").nodeValue + '"/>';
						}
						
						if (type == "error") {
							var item = document.getElementById(item_id);
							if (item) {
								item.style.border = '2px solid #FF0000';
								item.style.backgroundColor = '#FFAFB4';
							}
						} 
						
						message = message + msg + button; 
						if (iNode < root.childNodes.length - 1)
							message += "<br/>";
					}
				}
				else if (url) {
					//alert(url.attributes.getNamedItem("pref").nodeValue);
					if(url.attributes.getNamedItem("scr").nodeValue != '') {
						document.location.href = 'javascript: ' + url.attributes.getNamedItem("scr").nodeValue;
					}
					if(url.attributes.getNamedItem("ref").nodeValue != '') {
						document.location.href = url.attributes.getNamedItem("ref").nodeValue;
					}
					if(url.attributes.getNamedItem("pref").nodeValue != '') {
						parent.document.location.href = url.attributes.getNamedItem("pref").nodeValue;
					}
				}
				else if (mess) {
					var doc_inner = document.getElementById('message_container_inner');
					for (var iNode = 0; iNode < mess.childNodes.length; iNode++) {
						var node = mess.childNodes.item(iNode);
						var item_id = node.nodeName;
						if (node.attributes.getNamedItem("msg"))
							text = node.attributes.getNamedItem("msg").nodeValue;
						
						if (node.attributes.getNamedItem("ref"))
							document.location.href =  node.attributes.getNamedItem("ref").nodeValue;
					
					}
				}
				else
					message = obj.responseText;
				
				if (message != '') {
					doc_inner.innerHTML = message;
					doc.style.display = 'block';
					doc_message.style.display = 'none';
					scroll(0,0);
				}
				
				if (text != '') {
					message_inner.innerHTML = text;
					doc.style.display = 'none';
					doc_message.style.display = 'block';
					scroll(0,0);
				}
			}
		},
		onError : function(obj) {
			alert("Connection cannot be established. Please try again later.");
		}
	});
}*/

function RestoreFormFieldsBorder(form_name)
{
	form = document.getElementById(form_name);
	
	for (var iNode = 0; iNode < form.elements.length; iNode++) {
		var node = form.elements[iNode];
		if (node.type != "submit" && node.type != "button") {
			node.style.border = '1px solid #A6A6A6';
			node.style.backgroundColor = '#E8E8E8';
			node.style.backgroundColor = '#FFFFFF';
		}
	}
}

/*function userLogin(user_id) {
	advAJAX.post({
		url: "/user.php",
		parameters : {
		  "uid" : user_id,
		  "front" : 1
		},
		onLoading : function(obj) { 
		
		},
		onComplete : function(obj) { 
			
		},
		onSuccess : function(obj) { 
			var doc = parent.document.getElementById('login_box');
			doc.innerHTML = obj.responseText;
		},
		onError : function(obj) { alert("Error: " + obj.status); },
		"blad" : "blad"
	});
}*/

function TabsContent(action, extra_1, extra_2, extra_3, extra_4, extra_5, extra_6, extra_7, extra_8) {
	advAJAX.get({
		url: "/manage-profile.php",
		parameters : {
		  "act" : action,
		  "extra_1" : extra_1 || '',
		  "extra_2" : extra_2 || '',
		  "extra_3" : extra_3 || '',
		  "extra_4" : extra_4 || '',
		  "extra_5" : extra_5 || '',
		  "extra_6" : extra_6 || '',
		  "extra_7" : extra_7 || '',
		  "extra_8" : extra_8 || ''
		},
		onLoading : function(obj) {
			
			document.getElementById('tab_1').className = '';
			document.getElementById('tab_2').className = '';
			document.getElementById('tab_3').className = '';
			document.getElementById('tab_4').className = '';
			document.getElementById('tab_5').className = '';
			document.getElementById('tab_6').className = '';
			if (document.getElementById('tab_7') != null)
				document.getElementById('tab_7').className = '';
			if (document.getElementById('tab_8') != null)
				document.getElementById('tab_8').className = '';
			
			document.getElementById('tab_' + action).className = 'tabs-selected';
			var doc = document.getElementById('my-profile');
			doc.innerHTML = "<img src='/_d/loading.gif'/>";
		},
		onComplete : function(obj) { 
			
		},
		onSuccess : function(obj) { 
			var doc = document.getElementById('my-profile');
			doc.innerHTML = obj.responseText;
		},
		onError : function(obj) { alert("Error: " + obj.status); },
		"blad" : "blad"
	});
}

/*function Redirect(ref, scr) {
	advAJAX.post({
		url: "/user.php",
		parameters : {
		  "login" : 1,
		  "ref" : ref,
		  "scr" : scr
		},
		onLoading : function(obj) { 
		
		},
		onComplete : function(obj) { 
			
		},
		onSuccess : function(obj) {
			var xmlDoc = loadXMLString(obj.responseText);
			var url = xmlDoc.getElementsByTagName("url")[0];
			if (url) {
				
				if(url.attributes.getNamedItem("log").nodeValue == 1) {
					if(url.attributes.getNamedItem("scr").nodeValue != '') {
						document.location.href = 'javascript: ' + url.attributes.getNamedItem("scr").nodeValue;
					} else if(url.attributes.getNamedItem("ref").nodeValue != '') {
						document.location.href = url.attributes.getNamedItem("ref").nodeValue;
					}
				} else {
				   tb_show('Login', '/login.html?ret=' + ref + '&scr=' + scr + '&keepThis=true&TB_iframe=true&height=auto&width=640', '');
				}
			}
		},
		onError : function(obj) { alert("Error: " + obj.status); },
		"blad" : "blad"
	});
}*/

function Redirect(ref, scr) {
	jQuery.post("/user.php", { 
			login: 1,
			ref: ref,
			scr: scr
		},
		function(data) {
			if(data.log == '1') {
				if(data.scr != '') {
					document.location.href = 'javascript: ' + data.scr;
				} else if(data.ref != '') {
					document.location.href = data.ref;
				}
			} else {
				//open login box with re and scr added to the url
				var href = jQuery('#login_link').attr("href");
				href = href + "&ret=" + data.ref + "&scr=" + data.scr;
				jQuery('#login_link').attr("href", href);
				jQuery('#login_link').trigger('click');
			}
		}
	, "json");
	
	/*
	advAJAX.post({
		url: "/user.php",
		parameters : {
		  "login" : 1,
		  "ref" : ref,
		  "scr" : scr
		},
		onLoading : function(obj) { 
		
		},
		onComplete : function(obj) { 
			
		},
		onSuccess : function(obj) {
			var xmlDoc = loadXMLString(obj.responseText);
			var url = xmlDoc.getElementsByTagName("url")[0];
			if (url) {
				
				if(url.attributes.getNamedItem("log").nodeValue == 1) {
					if(url.attributes.getNamedItem("scr").nodeValue != '') {
						document.location.href = 'javascript: ' + url.attributes.getNamedItem("scr").nodeValue;
					} else if(url.attributes.getNamedItem("ref").nodeValue != '') {
						document.location.href = url.attributes.getNamedItem("ref").nodeValue;
					}
				} else {
				   tb_show('Login', '/login.html?ret=' + ref + '&scr=' + scr + '&keepThis=true&TB_iframe=true&height=auto&width=640', '');
				}
			}
		},
		onError : function(obj) { alert("Error: " + obj.status); },
		"blad" : "blad"
	});*/
}

/*function ReloadSearchResults() {
	current_page = document.getElementById('page').value;

	jQuery.fn.repaginate_images = function(page, offset, query){
		page = parseInt(page);
		offset = parseInt(offset);

		if (offset != 0) {
			limit = parseInt(jQuery('#results_limit').val());
			count = parseInt(jQuery('#results_count').val());
			if (page * limit > count)
				offset = 0;
		}
		
		if (page + offset <= 0)
			page = 1;
		else {
			page = page + offset;
		}
			
		current_page = page;
		
		jQuery.ajax({
			type: "GET",
			url: "search-results.html",
			data: 'ajax=1&page='+current_page+'&q='+query,
			beforeSend: function(XMLHttpRequest) {
				jQuery('.sr_title').html('<h1>Searching ...</h1>');
			},
			success: function(data) {
				jQuery('#main_view').html(data);
				
				limit = parseInt(jQuery('#results_limit').val());
				count = parseInt(jQuery('#results_count').val());
				
				start = (current_page - 1) * limit;
				end = start + limit;
				
				if (start > count) start = count;
				if (start <= 0)	start = 1;
				if (end > count) end = count;
					
				jQuery('.sr_title').html("<h1 id=\"sr_header_title\">Search results for \""+query+"\"</h1>("+start+" - "+end+" from "+count+" results)");
				jQuery('#page').val(current_page)
			}
		});
	};
	
	jQuery.fn.repaginate_images(current_page, 0, jQuery('#search_q').val());
	
	jQuery('.sr_paging button').bind('click', function() {
		jQuery('.sr_paging button').repaginate_images(jQuery('#page').val(), jQuery(this).val(), jQuery('#search_q').val());
	});
	
	jQuery('#page').bind('keyup', function(key) {
		if (key.which == 13)
			jQuery('#page').repaginate_images(jQuery(this).val(), 0, jQuery('#search_q').val());
	});
	
	jQuery('#search_form').bind('submit', function() {
		jQuery('#search_form').repaginate_images(1, 0, jQuery('#search_q').val());
		return false;
	})
}*/

function ManageBasket(action, id, value) {
	advAJAX.get({
		url: "/manage-basket.php",
		parameters : {
		  "act" : action,
		  "id" : id,
		  "value" : value
		},
		onLoading : function(obj) { 
		
		},
		onComplete : function(obj) { 
			
		},
		onSuccess : function(obj) { 
			
		},
		onError : function(obj) { alert("Error: " + obj.status); },
		"blad" : "blad"
	});
}

function ManageLightbox(action, id, type) {
	advAJAX.get({
		url: "/manage-lightbox.php",
		parameters : {
		  "act" : action,
		  "id" : id,
		  "type" : type
		},
		onLoading : function(obj) { 
		
		},
		onComplete : function(obj) { 
			
		},
		onSuccess : function(obj) {
			if(action != 'delete') {
				var doc = document.getElementById('lightbox_'+id);
				doc.innerHTML = obj.responseText;
				ReloadSearchResults();
			}	
		},
		onError : function(obj) { alert("Error: " + obj.status); },
		"blad" : "blad"
	});
}
										  
function Manage_Free_Download(horizontal, img_id) {
	//parent.document.location.href='/download_FreeRM_'+horizontal+'_'+img_id+'.zip';
	advAJAX.post({
		url: "/user.php",
		parameters : {

		},
		onLoading : function(obj) { 
		
		},
		onComplete : function(obj) { 
			
		},
		onSuccess : function(obj) { 
			var doc = parent.document.getElementById('login_box');
			doc.innerHTML = obj.responseText;
			document.location.href='/download_FreeRM_'+horizontal+'_'+img_id+'.zip';
		},
		onError : function(obj) { alert("Error: " + obj.status); },
		"blad" : "blad"
	});
}
/*function LicenseCalculator(step, id, field_id) {
	if(id == 0) {
		Clear_License_Fields();
		Update_License_Cost();
	} else {
		jQuery.ajax({
			type: "GET",
			url: "single-image.html",
			data: 'ajax=1&step='+step+'&licr_id='+id,
			dataType: "xml",
			success: function(xml) {
				// licr_circulation
				licr_circulation_select = document.getElementById('licr_circulation');
				licr_circulation_select.options.length = 0;
				jQuery(xml).find("licr_circulation").each(function()
				{
					jQuery(this).find("option").each(function()
					{
					  licr_circulation_select.options[licr_circulation_select.options.length] = new Option(jQuery(this).attr("name"), jQuery(this).attr("value"));
					  var  current = licr_circulation_select.options.length - 1;
					  licr_circulation_select.options[current].id = jQuery(this).attr("id");
					});
				});
				
				// licr_countries
				licr_countries_select = document.getElementById('licr_countries');
				licr_countries_select.options.length = 0;
				jQuery(xml).find("licr_countries").each(function()
				{
					jQuery(this).find("option").each(function()
					{
					  licr_countries_select.options[licr_countries_select.options.length] = new Option(jQuery(this).attr("name"), jQuery(this).attr("value"));
					  var  current = licr_countries_select.options.length - 1;
					  licr_countries_select.options[current].id = jQuery(this).attr("id");
					});
				});
				
				//licr_start_date
				document.getElementById('licr_start_license_day').disabled = false;
				document.getElementById('licr_start_license_month').disabled = false;
				document.getElementById('licr_start_license_year').disabled = false;
				
				// licr_duration
				licr_duration_select = document.getElementById('licr_duration');
				licr_duration_select.options.length = 0;
				jQuery(xml).find("licr_duration").each(function()
				{
					jQuery(this).find("option").each(function()
					{
					  licr_duration_select.options[licr_duration_select.options.length] = new Option(jQuery(this).attr("name"), jQuery(this).attr("value"));
					  var  current = licr_duration_select.options.length - 1;
					  licr_duration_select.options[current].id = jQuery(this).attr("id");
					});
				});
				
				// licr_industry
				licr_industry_select = document.getElementById('licr_industry');
				licr_industry_select.options.length = 0;
				jQuery(xml).find("licr_industry").each(function()
				{
					jQuery(this).find("option").each(function()
					{
					  licr_industry_select.options[licr_industry_select.options.length] = new Option(jQuery(this).attr("name"), jQuery(this).attr("value"));
					  var  current = licr_industry_select.options.length - 1;
					  licr_industry_select.options[current].id = jQuery(this).attr("id");
					});
				});
				
				//license button
				document.getElementById('submitBtn').disabled = false;
				
				
				//license costs
				Update_License_Cost();
			}
		});
	}	
}

function License_Calc(step, id, field_id) {
	jQuery.ajax({
		type: "GET",
		url: "single-image.html",
		data: 'ajax=1&step='+step+'&licr_id='+id,
		dataType: "xml",
		success: function(xml) {
			Clear_License_Fields();
			licr_usage_select = document.getElementById('licr_usage');
			licr_usage_select.options.length = 0;
			jQuery(xml).find("licr_usage").each(function()
			{
				jQuery(this).find("option").each(function()
				{
				  licr_usage_select.options[licr_usage_select.options.length] = new Option(jQuery(this).text(), jQuery(this).attr("value"));
				  var  current = licr_usage_select.options.length - 1;
				  licr_usage_select.options[current].id = jQuery(this).attr("id");
				});
			});
			Update_License_Cost();
		}
	});		
}

function Clear_License_Fields() {
	// licr_circulation
	licr_circulation_select = document.getElementById('licr_circulation');
	licr_circulation_select.options.length = 0;
	licr_circulation_select.options[0] = new Option('-- Please select a licensing model and area of usage first', 0);
	licr_circulation_select.options[0].id = 1;
	
	// licr_countries
	licr_countries_select = document.getElementById('licr_countries');
	licr_countries_select.options.length = 0;
	licr_countries_select.options[0] = new Option('-- Please select a licensing model and area of usage first', 0);
	licr_countries_select.options[0].id = 1;
	
	//licr_start_date
	document.getElementById('licr_start_license_day').disabled = true;
	document.getElementById('licr_start_license_month').disabled = true;
	document.getElementById('licr_start_license_year').disabled = true;
	
	// licr_duration
	licr_duration_select = document.getElementById('licr_duration');
	licr_duration_select.options.length = 0;
	licr_duration_select.options[0] = new Option('-- Please select a licensing model and area of usage first', 0);
	licr_duration_select.options[0].id = 1;
	
	// licr_industry
	licr_industry_select = document.getElementById('licr_industry');
	licr_industry_select.options.length = 0;
	licr_industry_select.options[0] = new Option('-- Please select a licensing model and area of usage first', 0);
	licr_industry_select.options[0].id = 1;
	
	//license button
	document.getElementById('submitBtn').disabled = true;
}
*/
function Update_License_Cost() {
	var based_price = 63;
	var model = 1;
	var usage = 1;
	var circulation = 1;
	var countries = 1;
	var duration = 1;
	var industry = 1;
	
	var model_select = document.getElementById('licr_model');
	for (var i = 0; i < model_select.options.length; i++){
		 if(model_select.options[i].selected == true){
			 model = model_select.options[i].id;
			 break;
		 }
	}
	
	var usage_select = document.getElementById('licr_usage');
	for (var i = 0; i < usage_select.options.length; i++){
		 if(usage_select.options[i].selected == true){
			 usage = usage_select.options[i].id;
			 break;
		 }
	}
	
	var circulation_select = document.getElementById('licr_circulation');
	for (var i = 0; i < circulation_select.options.length; i++){
		  if(circulation_select.options[i].selected == true){
			 circulation = circulation_select.options[i].id;
			 break;
		 }
	}
	
	var countries_select = document.getElementById('licr_countries');
	for (var i = 0; i < countries_select.options.length; i++){
		 if(countries_select.options[i].selected == true){
			 countries = countries_select.options[i].id;
			 break;
		 }
	}
	
	var duration_select = document.getElementById('licr_duration');
	for (var i = 0; i < duration_select.options.length; i++){
		 if(duration_select.options[i].selected == true){
			 duration = duration_select.options[i].id;
			 break;
		 }
	}
	
	var industry_select = document.getElementById('licr_industry');
	for (var i = 0; i < industry_select.options.length; i++){
		 if(industry_select.options[i].selected == true){
			 industry = industry_select.options[i].id;
			 break;
		 }
	}
	
	var total = based_price*model*usage*circulation*countries*duration*industry;
	document.getElementById('total_license_cost').value = formatCurrency(total);
	
	Licence_Preview();	
}

function formatCurrency(num){
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for ( i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function Licence_Preview() {
	if(document.getElementById('licr_start_license_day').disabled == false) { 
		var date_day = document.getElementById('licr_start_license_day').value;
		var date_month = document.getElementById('licr_start_license_month').value;
		var date_year = document.getElementById('licr_start_license_year').value;
	} else {
		var date_day = 0;
		var date_month = 0;
		var date_year = 0;
	}
	
	advAJAX.get({
		url: "/single-image.html",
		parameters : {
		  "ajax" : 1,
		  "step" : 'preview',
		  "licr_model" : document.getElementById('licr_model').value ,
		  "licr_usage" : document.getElementById('licr_usage').value,
		  "licr_circulation" : document.getElementById('licr_circulation').value,
		  "licr_countries" : document.getElementById('licr_countries').value,
		  "licr_start_license_day" : date_day,
		  "licr_start_license_month" : date_month,
		  "licr_start_license_year" : date_year,
		  "licr_duration" : document.getElementById('licr_duration').value,
		  "licr_industry" : document.getElementById('licr_industry').value
		},
		onLoading : function(obj) { 
		
		},
		onComplete : function(obj) { 
			
		},
		onSuccess : function(obj) {
			var doc = document.getElementById('license_receipt');
			doc.value = obj.responseText;
		},
		onError : function(obj) { alert("Error: " + obj.status); },
		"blad" : "blad"
	});
}

function Subscribe(asset_id, asset_type, asset_price_id) {
	advAJAX.get({
		url: "/subscription.php",
		parameters : {
		  "act" : "add",
		  "asset_id" : asset_id,
		  "asset_price_id" : asset_price_id,
		  "asset_type" : asset_type
		},
		onLoading : function(obj) { 
		
		},
		onComplete : function(obj) { 
			
		},
		onSuccess : function(obj) {
			var docImg = document.getElementById('subscription');
			var docAnim = document.getElementById('subscriptionAnim');
			if(docImg != null)
				docImg.innerHTML = obj.responseText;
			else if(docAnim != null)
				docAnim.innerHTML = obj.responseText;
		},
		onError : function(obj) { alert("Error: " + obj.status); },
		"blad" : "blad"
	});
}

function ShowSubscribtion(user_id) {
	advAJAX.get({
		url: "/subscription.php",
		parameters : {
		  "act" : "check",
		  "user_id" : user_id
		},
		onLoading : function(obj) { 
		
		},
		onComplete : function(obj) { 
			
		},
		onSuccess : function(obj) {
			if(obj.responseText == 1) {
				var doc = document.getElementById('subscription');
				if(doc != null)
					doc.style.display = '';
			}
			if(obj.responseText == 2) {
				var doc = document.getElementById('subscriptionAnim');
				if(doc != null)
					doc.style.display = '';
			}
			if(obj.responseText == 3) {
				var doc = document.getElementById('subscription');
				if(doc != null)
					doc.style.display = '';
				
				var doc = document.getElementById('subscriptionAnim');
				if(doc != null)
					doc.style.display = '';
			}
		},
		onError : function(obj) { alert("Error: " + obj.status); },
		"blad" : "blad"
	});
}

function AddToBasket(asset_type, asset_id, asset_price_id) {
	switch(asset_type) {
		case 1:
			SubmitForm('addToBasketForm');
		break;
		case 2:
			SubmitForm('addToBasketForm', asset_id, asset_price_id);
		break;	
	}
}

function LicenseCalculator(next_select_id, step,  value) {
	jQuery.ajax({
		type: "GET",
		url: "single-image.html",
		data: 'ajax=1&next_select_id='+next_select_id+'&selected_licr_id='+value+'&step='+step,
		dataType: "xml",
		success: function(xml) {
			Clear_License_Fields(next_select_id);
			
			if(next_select_id == 'licr_duration') {
				document.getElementById('licr_start_license_day_check').innerHTML = "<img src='/_d/buttons/btn_lightbox_add.gif'/>";
				document.getElementById('licr_start_license_day').disabled = false;
				document.getElementById('licr_start_license_month').disabled = false;
				document.getElementById('licr_start_license_year').disabled = false;
			}
						
			var select_id = document.getElementById(next_select_id);
			select_id.disabled = false;
			select_id.options.length = 0;
			jQuery(xml).find(next_select_id).each(function()
			{
				jQuery(this).find("option").each(function()
				{
				  select_id.options[select_id.options.length] = new Option(jQuery(this).text(), jQuery(this).attr("value"));
				  var  current = select_id.options.length - 1;
				  select_id.options[current].id = jQuery(this).attr("id");
				});
			});
			Update_License_Cost();
		}
	});	
}

function ActivateButton(value) {
		if(value != 0) {
			document.getElementById('submitBtn').disabled = false;
			document.getElementById('submitBtn').className = 'btn_large fright';
		} else {
			document.getElementById('submitBtn').disabled = true;
			document.getElementById('submitBtn').className = 'btn_large_inactive fright';
		}
}

function Clear_License_Fields(next_select_id) {
	switch(next_select_id) {
		case 'licr_usage':

		case 'licr_circulation':
			licr_circulation_select = document.getElementById('licr_circulation');
			licr_circulation_select.options.length = 0;
			licr_circulation_select.options[0] = new Option('-- Please select an appriopriate value', 0);
			licr_circulation_select.options[0].id = 1;
			document.getElementById('licr_circulation').disabled = true;
			document.getElementById('licr_circulation_check').innerHTML = "<img src='/_d/0.gif' width='20'/>";
			
		case 'licr_countries':
			licr_countries_select = document.getElementById('licr_countries');
			document.getElementById('licr_countries_check').innerHTML = "<img src='/_d/0.gif' width='20'/>";
			licr_countries_select.options.length = 0;
			licr_countries_select.options[0] = new Option('-- Please select an appriopriate value', 0);
			licr_countries_select.options[0].id = 1;
			document.getElementById('licr_countries').disabled = true;
			document.getElementById('licr_start_license_day').disabled = true;
			document.getElementById('licr_start_license_month').disabled = true;
			document.getElementById('licr_start_license_year').disabled = true;
			document.getElementById('licr_start_license_day_check').innerHTML = "<img src='/_d/0.gif' width='20'/>";
			
		case 'licr_duration':
			licr_duration_select = document.getElementById('licr_duration');
			licr_duration_select.options.length = 0;
			licr_duration_select.options[0] = new Option('-- Please select an appriopriate value', 0);
			licr_duration_select.options[0].id = 1;
			document.getElementById('licr_duration').disabled = true;
			document.getElementById('licr_duration_check').innerHTML = "<img src='/_d/0.gif' width='20'/>";
			
		case 'licr_industry':
			licr_industry_select = document.getElementById('licr_industry');
			licr_industry_select.options.length = 0;
			licr_industry_select.options[0] = new Option('-- Please select an appriopriate value', 0);
			licr_industry_select.options[0].id = 1;
			document.getElementById('licr_industry').disabled = true;
			document.getElementById('licr_industry_check').innerHTML = "<img src='/_d/0.gif' width='20'/>";
	}
	//license button
	document.getElementById('submitBtn').disabled = true;
	document.getElementById('submitBtn').className = 'btn_large_inactive fright';
}

function showTickbox(id, value) {
	if(value != 0)
		document.getElementById(id+'_check').innerHTML = "<img src='/_d/buttons/btn_lightbox_add.gif'/>";
}

function CloseLightBox() {
	jQuery('.jquery-lightbox-button-close').trigger('click');
}

function Register() {
	jQuery('#register_link').trigger('click');
}

function flashlink2(app_id) {
	jQuery.ajax({
		type: "GET",
		url: "applications.html",
		data: 'ajax=1&app_id='+app_id,
		dataType: "xml",
		success: function(xml) {
			var app_usr_status = jQuery(xml).find('app_usr_status').attr("value")
			var app_flash_link_url = jQuery(xml).find('app_flash_link_url').attr("value")
			var app_flash_link_message = jQuery(xml).find('app_flash_link_message').attr("value")
			var app_software_url = jQuery(xml).find('app_software_url').attr("value")
			return app_usr_status;
		}
	});	
}

function Advanced_Search_Filters(fltc_filter_type) {
	advAJAX.post({
		url: "/advanced-search.html",
		parameters : {
			'ajax' : 1,
			'fltc_filter_type' : fltc_filter_type
		},
		onLoading : function(obj) { 
		
		},
		onComplete : function(obj) { 
			
		},
		onSuccess : function(obj) { 
			var doc = document.getElementById('filters');
			doc.innerHTML = obj.responseText;
		},
		onError : function(obj) { alert("Error: " + obj.status); },
		"blad" : "blad"
	});
}

function Share(asset_id, asset_type) {
	if(asset_id == -1)
		tb_show('Share Entire Lightbox with Others', '/share.html?asset_id=' + asset_id + '&asset_type=' + asset_type + '&keepThis=true&TB_iframe=true&height=500&width=640', '');
	else
		tb_show('Share with Others', '/share.html?asset_id=' + asset_id + '&asset_type=' + asset_type + '&keepThis=true&TB_iframe=true&height=500&width=640', '');
}

function AddBasket(asset_id, asset_type) {
	switch(asset_type) {
		case 1:
			tb_show('Add an Image to the Shopping Basket', '/license-calculator.html?asset_id=' + asset_id + '&asset_type=' + asset_type + '&keepThis=true&TB_iframe=true&height=610&width=720', '');
		break;
		case 2:
			tb_show('Add an Animation to the Shopping Basket', '/license-calculator.html?asset_id=' + asset_id + '&asset_type=' + asset_type + '&keepThis=true&TB_iframe=true&height=300&width=750', '');
		break;
	}	
}
