jQuery.noConflict();

jQuery(document).ready(function() {
	
	//hide all tab contents
	jQuery(".webpdf_options").hide()

	//display fist tab
	jQuery("#webpdf-online-service .configurations .tabs li:first").addClass("current").show();
	jQuery(".webpdf_options:first").show();
	
	jQuery("#webpdf-online-service .configurations .tabs li.tab").click(function() {
		jQuery("#webpdf-online-service .configurations .tabs li").removeClass("current");
		jQuery(this).addClass("current");
		
		element = jQuery(this);
		
		jQuery(".webpdf_options").hide();
		
		//get active tab
		var activeTab = element.find("a").attr("href");
		jQuery(activeTab).fadeIn(400);
		
		return false;
		
	});
	
	// reset errors after click on convert
	jQuery("#convertButton").click(function() {
		//remove error class
		jQuery("#webPDFConverter #webpdf-online-service *").removeClass("f3-form-error");

		//remove div with errors
		jQuery("#webPDFConverter .error").remove();

		//check file extension
		return check_file(jQuery("#fileField").attr("value"));
	});

});


function check_file(file_name) {
    // Die erlaubten Dateiendungen
    var allowed_extensions = new Array(
  
        //Word Processing Documents
        'sam', 'doc', 'cwk', 'wpf', 'mif', 'fw3', 'fw4', 'hpp', 'htm', 'html', 'nvo',
        'txt', 'wks', 'wp', 'odt', 'ott', 'dot', 'qw', 'rtf', 'sw4', 'sxw', 'stw', 'sdw',
        'wri', 'wpd', 'wsd', 'xif', 'xyw', 'xml', 'docx', 'docm', 'dotx', 'dotm', 'uot', 'uof',
        //Spreadsheet Documents
        'ods', 'ots', 'sxc', 'stc', 'sdc', 'vor', 'xls', 'xlw', 'xlt', 'slk', 'wb2', 'xlsb',
        'xlsx', 'xslm', 'xltx', 'xstm', 'uos', 'uof',
        //Presentation Documents
        'odp', 'otp', 'sxi', 'sti', 'sdd', 'sdp', 'vor', 'ppt', 'pps', 'pot', 'pptx', 'pptm',
        'potx', 'potm', 'uop', 'uof',
        //Drawing Documents
        'jpg','gif','png', 'odg', 'otg', 'sxd', 'std', 'sda', 'sdd', 'vor', 'cgm',
        'emf', 'eps', 'met', 'pct', 'sgf', 'sgv', 'svm', 'wmf', 'bmp', 'jpeg', 'jfif',
        'jif', 'jpe', 'pbm', 'pcx', 'pgm', 'ppm', 'psd', 'ras', 'tga', 'tif', 'tiff',
        'xbm', 'xpm', 'pcd', 'dxf',
        //Formula Documents
        'odf', 'sxm', 'smf', 'mml'
        );

    // Dateiendung der Datei
    var extension = file_name.split('.');
    extension = extension[extension.length - 1];
    extension = extension.toLowerCase();

    var match = false;
  
    for (var k in allowed_extensions) {
        if (allowed_extensions[k] == extension) {
            match = true;
            break;
        }
    }
    if (match == false) {
    	jQuery("#fileField").addClass("f3-form-error");
    	alert(jQuery("#webPDFConverter #fileTypeError").html());
    }

    return match;
}
