function functionNull(){}

function is_array(input){
    return typeof(input)=='object'&&(input instanceof Array);
  }

function getLink(link) {
	window.location=link;
}
function imageRemove(image_id){
	$('#image_'+image_id).remove();
	$('#pic_'+image_id).val('');

	if(image_id>1) indexDecr = image_id-1;
	else indexDecr = 1;
	$('#imgCnt').val(indexDecr);
	
	$('#pic_del_'+$('#imgCnt').val()).show();
	if( parseInt($('#imgCnt').val()) <= parseInt($('#imgMax').val()) ){
		$('#uploadButton').show();
	}
}

function galleryShow(image_id){
	currentImage = $('#currShow').val();
	$('#mainThumb_'+currentImage).hide(); 
	$('#currShow').val(image_id); 
	$('#mainThumb_'+image_id).show();
}

function validatePUDays(){
	$('#validatePUDaysError').hide();
	var control=parseInt($('#shipPickUp').val());
	if(validateRange(control, '0', '14')!==true){
		$('#validatePUDaysError').show();
		$('#shipPickUp').val('');
	}
}

function validateRange(inputValue, minValue, maxValue) {
/*	inputValue = replaceAll(inputValue,',','.');*/
	if(minValue<=inputValue && inputValue<=maxValue) return true;
		else return false;
}

function isIntegerInRange (s, a, b) {
	if (isEmpty(s))
	if (isIntegerInRange.arguments.length == 1) return false;
	else return (isIntegerInRange.arguments[1] == true);
	if (!isInteger(s, false)) return false;
	var num = parseInt (s);
	return ((num >= a) && (num <= b));
}

function replaceAll(strChk, strFind, strReplace) {
	/**
	 * @param strChk      String to be cleaned
	 * @param strFind     String to replace
	 * @param strReplace  String to insert
	 * @return            String without unwanted characters/strings
	 */
	var strOut = strChk;
	while (strChk.indexOf(strFind) > -1) {
		strOut = strOut.replace(strFind, strReplace);
	}
  return strOut;
}

function validateCRange(fieldValue, fieldName,fieldIndex){
	fieldBef = fieldIndex-1;
	fieldNext = fieldIndex+1;

	for(i=1;i<=3;i++){
		$('#selectHlp_p'+i).hide();
		$('#selectHlp_t'+i).hide();
	}
	
	if(fieldName=='to'){
		$('#rng_price_'+fieldIndex).removeAttr('disabled');
		$('#rng_from_'+fieldNext).val(parseInt(fieldValue)+1);
		if(!$('#rng_price_'+fieldIndex).val()) $('#selectHlp_p'+fieldIndex).show();
	}
	if(fieldName=='price'){
		$('#rng_to_'+fieldNext).removeAttr('disabled');
		if($('#rng_to_'+fieldNext).val()=='') $('#selectHlp_t'+fieldNext).show();
	}

	
	if(fieldName=='to' && fieldIndex=='1' && (fieldValue==0 || fieldValue>999)) $('#error_1_minValH0').show();
	else
		$('#error_1_minValH0').hide();
	
	if(fieldName=='from' && fieldIndex>1){
		

		// from lower than previous to
		if( parseInt($('#rng_to_'+fieldBef).val()) >= fieldValue ){
			$('#error_'+ fieldIndex +'_minVal').show();
		}
		else {
			$('#error_'+ fieldIndex +'_minVal').hide();
		}
	}
	
	
    
    
	if(fieldName=='to' && fieldIndex>1){
		
		
		// to higher than from
		if( parseInt($('#rng_from_'+fieldIndex).val()) >= parseInt($('#rng_to_'+fieldIndex).val() ) ){
			$('#error_'+ fieldIndex +'_maxHiMinVal').show();
		} else {
			$('#error_'+ fieldIndex +'_maxHiMinVal').hide();
		}
		
		// to higher than allowed
		if( $('#rng_to_'+fieldIndex).val() && parseInt($('#rng_to_'+fieldIndex).val()) > 999 ) {
			$('#error_'+ fieldIndex +'_maxVal').show();
		}
		else {
			$('#error_'+ fieldIndex +'_maxVal').hide();
		}
	}
}

function validateCRangeForm(){
	/*
	for(i=1;i<=nextNo;i++) {
		validateRange($('#rng_from_'+i),'from',i);
		validateRange($('#rng_to_'+i),'to',i);
	}
	*/
	return true;
//	validateRange(fieldValue, fieldName,fieldIndex);
}


function keyMask(AEvent, AMaska) {
	if (window.Event) codeKey = AEvent.which;
	else codeKey = AEvent.keyCode;
	if (codeKey == 13) return true; // Enter
	if (codeKey == 8) return true; // backspace
	if (codeKey == 0) return true; // klawisze sterujace
	kkey = String.fromCharCode(codeKey);
	if (AMaska.indexOf(kkey) == -1) return false;
	else return true;
} 

function getCountry(countryLabel, target, loader, error){
	$('#' + error).html('');
	$('#' + target).html('');
	if(loader){
		$('#' + loader).ajaxStart(function(){
			$(this).show();
		});
		$('#' + loader).ajaxStop(function(){
			$(this).hide();
		});
	}
	$.ajax({
		type: "POST",
		url: "ajax/a_getCountryCompanyType.php",
		data: "countryLabel=" + countryLabel,
		dataType: "html",
		async: true,
		error: function(){
			$('#' + error).html('Error loading XML document');
		},
		success: function(data){
			$('#' + target).html(data);
/*			$("#countrySpecificCompanyType").jqTransform();*/
		}
	});
	
}

function registrationForm(step){
	var $tabs = $('#registrationTabs').tabs(); // first tab selected
	$tabs.tabs('enable' , step-1);
	$tabs.tabs('select', step-1); // switch to third tab
//	return false;
	if(step==3){
		$tabs.tabs('disable' , 0);
		$tabs.tabs('disable' , 1);
		$('#registerLoader').show();
		$.ajax({
			type: "POST",
			url: "ajax/a_sendRegistration.php",
			data: "mst_country="+ $('#mst_country').val() 
			+"&mst_countrySpecificCompanyType="+ $('#mst_countrySpecificCompanyType').val() 
			+"&mst_name="+ $('#mst_name').val() 
			+"&mst_address="+ $('#mst_address').val() 
			+"&mst_zip="+ $('#mst_zip').val() 
			+"&mst_city="+ $('#mst_city').val() 
			+"&mst_email="+ $('#mst_email').val() 
			+"&mst_pass="+ $('#mst_pass').val()
			+"&mst_phone1="+ $('#mst_phone1').val() 
			+"&mst_phone2="+ $('#mst_phone2').val() 
			+"&mst_contact_name="+ $('#mst_contact_name').val() 
			+"&mst_contact_sname="+ $('#mst_contact_sname').val()
			+"&mst_cReg="+ $('#mst_registration_no').val() 
			+"&mst_cVat="+ $('#mst_vat_id').val()
			+"&mst_iLanguage="+ $('#iLanguage').val() 
			+"&mst_epalCertMan="+ $("input[name='add_epalCertMan']:checked").val()
			+"&mst_epalCertRepair="+ $("input[id='add_epalCertRepair']:checked").val() 
			+"&add_ipsReference="+ $("#add_ipsReference").val()
			+"&add_marketReference="+ $('#add_marketReference').val() +"&add_volume="+ $('#add_volume').val(),
			dataType: "html",
			async: false,
			error: function(){
				$('#registerLoader').hide();
				$('#registerSendDebug').html('Error loading XML document');
			},
			success: function(data){
				$('#registerLoader').hide();
				$('#registerFinal').show();
				$('#registerSendDebug').html(data);
			}
		});
	}
}

var currentPreviewVal = '';
function showPreviewPallet(currentVal){
	$('#preview_default').hide();
	if(currentPreviewVal) $('#preview_'+currentPreviewVal).hide();
	currentPreviewVal=currentVal;
	$('#preview_'+currentVal).show();
	
}


function geocodeView(target, street, town){
}

function addNewRange(target, nextNo){
	$.ajax({
		type: "POST",
		url: "ajax/f_rangeNew.php",
		data: "nextNo="+ nextNo, 
		dataType: "html",
		async: false,
		error: function(){
		},
		success: function(data){
			$('#'+target).append(data);
			$("#rng_from_" + nextNo).jqTransform();
			$("#rng_to_" + nextNo).jqTransform();
			$("#rng_price_" + nextNo).jqTransform();
		}
	});
	nextNo++;
}

function locIndFreightRates(option){
	if(option=='yes') $('#individualRates').hide();
	if(option=='no') $('#individualRates').show();
}

function feedb(type){
	$('#negativeHint').hide();
	if(type=='pos'){
	}
	if(type=='neu' || type=='neg'){
		$('#negativeHint').show();
	}
	$('#feedbackTextI').show();
	$('#feedbackSave').show();
}


function findOnMap(town, address){
    if(!town || !address) return false;
    else{
    	address_full = address +', '+ town;
    }
    
    jQuery('#addressError').val('');
    
    jQuery('#map1').jmap('SearchAddress', {
        'query': address_full,
        'returnType': 'getLocations'
    }, function(result, options) {
        
        var valid = Mapifies.SearchCode(result.Status.code);
        if (valid.success) {
        	
	        jQuery.each(result.Placemark, function(i, point){
	            jQuery('#map1').jmap(
		                	'AddMarker',{
	    	                	'pointLatLng':[point.Point.coordinates[1], point.Point.coordinates[0]],
	    	                	'centerMap':true,
	    	                	'pointHTML':point.address
	    	                });
	            $('#geo_lat').val(point.Point.coordinates[1]);
	            $('#geo_lon').val(point.Point.coordinates[0]);
	            
	        });
        } else {
            jQuery('#addressError').val(valid.message);
        }
    });
    return false;	
}

function acceptSaleOffers(offer_id, language){
	$('#selectSomething_' + offer_id).hide();
	var checked_id = Array();
	var a = 0;
	
/*	jQuery(":checkbox[name='selectResponse_"+offer_id+"[]']").each(function(){	*/
	$("input[@type=checkbox][name='selectResponse_"+offer_id+"[]'][@checked]").each(function(){	
		if(this.checked) checked_id[a] = this.value;
		a++;
	});

	if(checked_id.length<1) {
		$('#selectSomething_' + offer_id).show();
		return false;
	}
	tested = checked_id.join("-");
	
	$('#acceptError_' + offer_id).hide();
	$('#submit_' + offer_id).hide();
	
	$('#loader_' + offer_id).ajaxStart(function(){
		$(this).show();
	});
	$('#loader_' + offer_id).ajaxStop(function(){
		$(this).hide();
	});

	$.ajax({
		type: 	"POST",
		url: 	"ajax/a_acceptSaleOffers.php",
		data:	  "askOffer=" + offer_id 
				+ "&selectedOffers=" + tested
				+ "&lang=" + language
		,
		dataType: "html",
		error: function(){
			$('#acceptError_' + offer_id).show();
			$('#submit_' + offer_id).show();
		},
		success: function(data){
			$('#detail_' + offer_id).html(data);
		}
	});	
}


function contactForm(target){
	$('#contact_main').hide();
	for(i=1;i<=3;i++){
	$('#contact_sales' + i).hide();
	}
/*	$('#contact_sales2').hide();
	$('#contact_sales3').hide();
*/	$('#contact_' + target).show();
	$('#contact_target').val(target);
}

function loadHelp(chapter,section,language){
	$('#helpContent').ajaxStart(function(){
		$(this).hide();
	});
	$('#loader').ajaxStart(function(){
		$(this).show();
	});
	
	$('#loader').ajaxStop(function(){
		$(this).hide();
	});
	$('#helpContent').ajaxStop(function(){
		$(this).show();
	});

	$.ajax({
		type: 	"POST",
		url: 	"http://palettenring.de/ajax/a_helpLoader.php",
		data:	  "chapter=" + chapter 
				+ "&section=" + section
				+ "&lang=" + language,
		dataType: "html",
		error: function(){
			
		},
		success: function(data){
			$('#helpContent').html(data);
			Cufon.refresh('h3','h4');
		}
	});	
}

function helpMessage(title, string, lang, clt, firma, telefon, email){
	$('#helpForm').ajaxStart(function(){
		$(this).hide();
	});
	$('#helpMessageLoader').ajaxStart(function(){
		$(this).show();
	});
	
	$('#helpMessageLoader').ajaxStop(function(){
		$(this).hide();
	});
	/*
	$('#helpSent').ajaxStop(function(){
		$(this).show();
	});
*/
	$.ajax({
		type: 	"POST",
		url: 	"http://palettenring.de/ajax/a_helpMessage.php",
		data:	  "title=" + title 
				+ "&firma=" + firma
				+ "&telefon=" + telefon
				+ "&email=" + email
				+ "&string=" + string
				+ "&lang=" + lang
				+ "&clt=" + clt,
		dataType: "html",
		error: function(){
			
		},
		success: function(data){
			$('#helpSent').show();
			$('#tester').html(data);
			Cufon.refresh('h3','h4');
		}
	});	
}


function sendMessage(to, name, company, phone, mail, message, cfL, cfClt){
	if($("#contactFormForm").validate().form()==true){
		$('#contactFormContent').ajaxStart(function(){
			$(this).html('');
		});
		$('#messageLoader').ajaxStart(function(){
			$(this).show();
		});
		
		$('#messageLoader').ajaxStop(function(){
			$(this).hide();
		});
		/*
		$('#helpSent').ajaxStop(function(){
			$(this).show();
		});
	*/
		$.ajax({
			type: 	"POST",
			url: 	"http://palettenring.de/ajax/a_contactMessage.php",
			data:	"to=" + to
					+ "&name=" + name
					+ "&company=" + company
					+ "&mail=" + mail
					+ "&phone=" + phone
					+ "&message=" + message
					+ "&cfL=" + cfL
					+ "&cfClt=" + cfClt,
			dataType: "html",
			error: function(){
				
			},
			success: function(data){
				$('#messageSent').show();
				$('#contactFormContent').html(data);
				Cufon.refresh('h3','h4');
			}
		});	
	}
}

