/* (c)2010 by projects of WDNS.at öÖäÄüÜß */

var wdnsAjaxObjects_ivc = new Array();
var crmtimeout = '';
var FValOffset = '0 0';


function resizeCompletedContent(ajaxIndex){ eval(wdnsAjaxObjects_ivc[ajaxIndex].response); wdnsAjaxObjects_ivc[ajaxIndex] = false; }

/*
 * Auswerten der Formulareingabe
 * @CoreInForm -> ID des Forms
 ******************************************************************************/
function testFVal(id){

  $.tools.validator.localize("de", {
    ':email' : ' ist eine ungültige Angabe!',
	':number' : ' ist ein Nummernfeld [0-9]!',
	'[max]' : ' ist zu groß, max: $1',
	'[min]' : ' ist zu klein, min: $1',
	'[required]' : ' ist ein Pflichtfeld!'
  });

  $('#'+id).validator({lang: 'de'});

  // adds an effect called "wall" to the validator
  $.tools.validator.addEffect("wall", function(errors, event) {
	// get the message wall
	var wall = $(this.getConf().container).fadeIn();
	// remove all existing messages
	wall.find("p").remove();
	// add new ones
	$.each(errors, function(index, error){
	   wall.append( "<p><strong>" +error.input.attr("name")+ "</strong> " +error.messages[0]+ "</p>" );		
	});
	
  // the effect does nothing when all inputs are valid	
  }, function(inputs){});

    var inputs = $('#'+id).validator();
    if(inputs){
      if(typeof inputs.data == 'function' && typeof inputs.data('validator') == 'object' && inputs.data('validator') !== null){
         /*inputs.data('validator').reset(inputs);*/
         inputs.data('validator', null); 
      }
      
      inputs.validator({ effect:'wall',container:'#ci_frm_errormessage',speed:'normal',lang:'de'});
      var chkVal = inputs.data("validator").checkValidity(); 
      if(chkVal==true){ checkInput4Send(id); }
    }
  $("#ci_frm_errormessage").position({ of: $('#content'), my: 'center center',  at: 'center center', offset: FValOffset, collision: 'flip flip' });
}

function sendFValOKMessage(message){
 $("#ci_frm_errormessage").html("<h2>"+ message +"</h2>");
 $("#ci_frm_errormessage").show();	
 $("#ci_frm_errormessage").position({ of: $('#content'), my: 'center center',  at: 'center center', offset: FValOffset, collision: 'flip flip' });
}

function checkInput4Send(CiForm){

  var objFrm = document.getElementById(CiForm);
  var frmL = objFrm.length;
  var elem = '';
  var url = 'inc/smtp-auth-connect.php?';
  var id = 'submit';
  
  for(i=0;i<frmL;i++){
    elem = objFrm.elements[i].name;
    if(objFrm.elements[i].type != 'label' && objFrm.elements[i].type != 'legend' && objFrm.elements[i].type != 'button' && objFrm.elements[i].type != 'reset'      ){ url += elem +'='+objFrm.elements[i].value+'&'; }
  }
 
   //document.getElementById('sendfrm').disabled = 'true';
   var ajaxIndex = wdnsAjaxObjects_ivc.length;
   wdnsAjaxObjects_ivc[ajaxIndex] = new sack();
   wdnsAjaxObjects_ivc[ajaxIndex].requestFile = encodeURI(url);
   wdnsAjaxObjects_ivc[ajaxIndex].onCompletion = function(){ resizeCompletedContent(ajaxIndex);  };
   wdnsAjaxObjects_ivc[ajaxIndex].runAJAX();
}


//??
function printDiv(replf,replt,theDIV){    
 var id = Math.random();
 var popupWin   = window.open('http://'+self.location.hostname+'/main_print.php?id='+id+'&dc='+theDIV+'&rf='+replf+'&rt='+replt, 'PrintPage', 'location=0,status=0,toolbar=0,menubar=0,resizable=0,scrollbars=0,width=600,height=100');
}


//??
//function test(){
//$(function() {		
//		
//	// initialize scrollable with mousewheel support
//	$(".scrollable").scrollable({ vertical: true, mousewheel: true });	
//	
//});
//}

/**** CALLBACK FUNCTIONS ****/
/* Init slimbox2 für ArtikelDB */
function slimboxAjaxDB(){ $("#ciDBADIV img").slimbox({loop:true, overlayOpacity: 0.6, resizeEasing: "swing", captionAnimationDuration: 600, overlayFadeDuration:600, resizeDuration:600, imageFadeDuration:600, counterText: "Bild {x} von {y}", closeKeys: [27, 88, 67], nextKeys: [90, 39], previousKeys:[37, 87]}, function(el){return [el.src, el.alt];}, function(el){return true;} );  }
/* Init slimbox2 für ArtikelDB */
function slimboxAjaxFRM(){ $("#ciFRMDIV img").slimbox({loop:true, overlayOpacity: 0.6, resizeEasing: "swing", captionAnimationDuration: 600, overlayFadeDuration:600, resizeDuration:600, imageFadeDuration:600, counterText: "Bild {x} von {y}", closeKeys: [27, 88, 67], nextKeys: [90, 39], previousKeys:[37, 87]}, function(el){return [el.src, el.alt];}, function(el){return true;} );  }
