/*---------- registrierung ----------*/
$(document).ready(function() {


	$("#regFirmcode").keyup(firmCodeCheck);

	$("#regNewFirmcode").click(function(){
		if( $('#regNewFirmcode').attr('checked')){
			$("#regFirmcode").val("").attr('disabled', true);
		}else{
			$("#regFirmcode").removeAttr('disabled');
		}
	});

});


/**
 *  prueft den firmencode auf zugehoerigkeit
 */
function firmCodeCheck(){

   formField = $(this);

	if($("#regFieldFirm").val() == ""){
		formField.parent().prepend("<div id='regErrorMsg'>Sie m&uuml;ssen eine Firma eintragen!</div>");
		setTimeout('$("#regErrorMsg").remove();',3000);
	}else{

		if($(this).length > 0){



			formField.css({'background-color':'#FFFFFF'});

		    if(formField.val().length >= 6){

		        ajaxurl = "wk=reg.001&firmcode="+formField.val()+"&firm="+$("#regFieldFirm").val();
				$.ajax({type: "GET",url: "/ecs/ajax.php",data: ajaxurl,cache: false, success: function(result){



					if(result == "\n-1"){
					   $("#regFirmcode").css({"background-color":"#993300"});
					   formField.parent().prepend("<div id='regErrorMsg'>Der eingegebene Firmencode existiert bei uns nicht!</div>");
						setTimeout('$("#regErrorMsg").remove();',3000);
					}
					if(result == "\n-2"){
						$("#regFirmcode").css({'background-color':'#993300'});
					   formField.parent().prepend("<div id='regErrorMsg'>Der eingegebene Firmencode ist f&uuml;r Ihre Firma nicht g&uuml;ltig!</div>");
						setTimeout('$("#regErrorMsg").remove();',3000);
					}
					if(result == "\n1"){
					    $("#regFirmcode").css({'background-color':'#99FF00'});
					}
				}});
			}
		}
	}
}




/*----------  galleriefunktionen  ----------*/
var ajaxurl = '/ecs/ajax.php';
$(document).ready(function(){
	galFillImglist(0);
	
	$("#albumSelect").change(function(){
		galFillImglist(0);
	});
});


function galFillImglist(startcount){

	$("#galImglistMainCon > div").remove();

	// lese die uebersicht des 1. album aus
	var ajaxurldata = "wk=gal_001&album="+$("#albumSelect").val()+'&startcount='+startcount;
	$.ajax({type: "POST",url: ajaxurl,data: ajaxurldata,success: function(result){
		$("#galImglistMainCon").append(result);
		
		if($("#galNavBack").attr("startcount") < 0){$("#galNavBack").hide();}
		if($("#galNavNext").attr("startcount") == 0){$("#galNavNext").hide();}

		$("#galNavBack").click(function(){
            galFillImglist($(this).attr("startcount"));
		});

		$("#galNavNext").click(function(){
            galFillImglist($(this).attr("startcount"));
		});
	}});
}














/*----------  diverses  ----------*/

// open a new window with parameters of location and size
function openWindow(linkTo, height, width) {		
	window.open(linkTo,"Navigation","height="+height+",width="+width+",scrollbars=yes,scrollbars=1");
}

// close the actualli window
function wclose(){
	window.close();
}

// open the page where is in parameter
function jumpToPage(page) {
	window.location.href = page;	
}

// set the focus on first field
function setfocus(form,fild){
	window.document.form[form].element[field].focus();
}

// reload the orderstage for recalculate the articlelist
// form => name of the form
// setvalue => if set of value ok? true/false
// field => field for set the value
// value => value to set
// action => action from form
function reloados(form,setval,field,value,action){
	if(setval == 'true'){
		document.forms[form].elements[field].value = value;
	}
	document.forms[form].action = action;
	document.forms[form].submit();
}

function work(fname,act){
	if(act == 'del'){
		check = confirm("Möchten Sie diese Adresse wirklich löschen?");
		if(check == true) {
			document.forms[fname].mod.value = 'del';
			document.forms[fname].action = 'uz_shshipadr.php';
			document.forms[fname].submit();
		}
	}
	if(act == 'sel'){
		document.forms[fname].mod.value = 'sel';
		document.forms[fname].action = 'uz_shshipadr.php';
		document.forms[fname].submit();	
	}
}

function modadr(fname){
	document.forms[fname].action = 'uz_regshiadr.php';
	document.forms[fname].submit();
}

function os_adr_mod(action){
	window.location.href = action+'?usercommand='+document.forms['comment'].formcomment.value;
}


