function getNewNumCssValue (sInput, absoluteValue, offsetValue ) {
	var retVal = '';
	var met = '';
	var v = '';
	var n = 0;
	if (-1 != sInput.indexOf("px")) { // pixel
		met = 'px';
		v = sInput.replace("px", '');
	} else if (-1 != sInput.indexOf("pt")) { // points
		met = 'pt';
		v = sInput.replace("pt", '');
	} else if (-1 != sInput.indexOf("%")) { // percent
		met = '%';
		v = sInput.replace("%", '');					
	} else if (-1 != sInput.indexOf("em")) { // em
		met = 'em';
		v = sInput.replace("em", '');					
	}
	n = parseFloat (v);
	
	if (absoluteValue != null) {
		retVal = absoluteValue + met;
	} else if (offsetValue != null ) {
		retVal = (n + offsetValue) + met;
	} else {
		retVal = n + met;
	}
	return retVal;
}

(function($) {
	
	var QCartManager = function(element, options) {
		//
		// INITIALIZE
		//
		element = $(element);
		var obj = this;
		var barCreated = false;
		var nowOpen = false;
		var barState = 0;
		
		
		// ====================================================
		// = the main comment field / variables and functions =
		// ====================================================
		var mainCommentField = {
			obj : null,
			id : '111',
			oldSource : null,
			isOpen : false,

			
			saveComment : function () {
				var theid = '#' + this.id + '_inputfield';
				this.saveCommentParent(this.id, $(theid).val(), '15_1_1_20091202_1268918350.jpg');			
			},
			
			resetForm : function () {
				this.obj.children('.YInputComposerOuterShadow').empty();
				this.obj.children('.YInputComposerOuterShadow').html(this.oldSource);
				this.obj.children('.YInputButtonArea').remove();
				this.isOpen = false;				
			},


			openInputArea : function () {
				if ( !this.isOpen ) {
					this.oldSource = this.obj.children('.YInputComposerOuterShadow').html();
					var newHtml = '<textarea id="' + this.id + '_inputfield"" class="YInAnPlaceHolderTArea"></textarea>';
					this.obj.children('.YInputComposerOuterShadow').empty ();
					this.obj.children('.YInputComposerOuterShadow').html(newHtml);	
					
					newHtml = '<div id="' + this.id + '_buttonarea" class="YInputButtonArea">';
					newHtml += '<div id="' + this.id + '_btcancel" class="FR YCancelButtonArea ITN"><a href="#" id="' + this.id +'_therealcancelbt" class="YBTCancel">Abbrechen</a></div>';
					newHtml += '<div id="' + this.id + '_btsave" class="FR YSaveButtonArea ITN"><a href="#" id="' + this.id +'_therealsavebt" class="YBTSave">Speichern</a></div>';
					newHtml += '<br class="FE" />';
					newHtml += '</div>';	
					
					this.obj.append(newHtml);				
					this.isOpen = true;		
					
					var thefield = this.obj.children('.YInputComposerOuterShadow').children()[0];			
					thefield.focus();		
					
					
					// storing a reference in the tags
					$('#' + this.id + '_therealsavebt').data ('theobj', this);
					$('#' + this.id + '_therealcancelbt').data('theobj', this);
					$("#" + this.id + '_inputfield').data('theobj', this);
					
					
					$('#' + this.id + '_therealsavebt').click ( function () {
						$(this).data('theobj').saveComment();
						return false;
					});
					$('#' + this.id + '_therealcancelbt').click ( function () {
						$(this).data('theobj').resetForm();
						return false;
					});															
				}
				return false;			
			}				
		};
		
		
		
		
		//
		// MERGE OPTIONS WITH DEFAULTS
		//		
		var settings = $.extend ( {
			bar_showwhenempty : false,
			bar_hidewhenempty : true,
			bar_popuptimeonadd : 3000,
			bar_popuptimeonnewpage : 0,
			bar_closedHeight : 18,
			bar_openedHeight : 76,
			bar_closeInterval : 1000, 
			bar_confirmHeight : 550,
			url_aftersucess : 'http://www.hauff.com',			
			fld_maincommentfieldId : '#yid_maincommentfield',
			url_captchaimg : 	'/lib/3rd/captcha/images/image.php',
			url_captchaproc :   '/lib/3rd/captcha/process.php',			
			url_servercontroller : '/yctrl.php'
		}, options || {});
		
		
		// =================================
		// = setting some global variables =
		// =================================
		$(settings['fld_maincommentfieldId']).each ( function () {
			var tClasses = $(this).attr("class").split(" ");
			var tId = '';
			
			for (i = 0; i < tClasses.length; i++ ) {
				if (tClasses[i].search(/THEIMGID_.+/) != -1) {
					tId = tClasses[i].substr(tClasses[i].search(/THEIMGID_.+/) + 9);
				}				
			}
			
			mainCommentField['obj'] = $(this);
			mainCommentField['id'] = tId;
			
			mainCommentField['saveCommentParent'] = function (id,question,imagepath) {
				if ( ! barCreated ) {
					createQBar ();
					barCreated = true;
				}
				openQBar (settings.bar_popuptimeonadd);
				addQuestionToBar (id,question,imagepath);
			}
		} );
		
		$(".ycntarea").each ( function () {
			$(this).css("display", "block");
		});
		
		// ==========================================
		// = this function starts the QCartManager  =
		// ==========================================
		this.run = function () {
			$(window).unload (function () {
				storeDataInCookie();
			});
												
			if (settings.bar_showwhenempty) {
				createQBar ();
				barCreated = true;
			}
			modiContent ();
			
			// 
			// checking if there is data on the server
			//
			$.ajax ( {
				type: 		"GET",
				url:  		settings.url_servercontroller, 
				dataType: 	"xml",
				cache:  	false,
				beforeSend: function (req) {
					createQBar ();
					closeQBar ();
					barCreated = true;					
					showLoader (true);
				},				
				success: 	function(xml) {
					showLoader (false);
					processCaptcha (xml);					
					var i = 0;
					var theData = new Array();
					$(xml).find("item").each ( function () {
						theData[i] = {
							id: '',
							name: '',
							thumburl: '',
							imgurl:   '',
							comment: '',
							theurl:  ''
						};
						theData[i].id = $(this).attr("id");
						theData[i].name = $(this).find("name").text();
						theData[i].comment = $(this).find("comment").text();
						theData[i].theurl = $(this).find("imgurl").text();
						theData[i].thumburl = $(this).find("img").find("thumb").text();
						theData[i].imgurl = $(this).find("img").find("file").text();
						i++;
					});
					if (theData.length > 0 ) {

						openQBar (settings.bar_popuptimeonadd);
					} else {
						element.html('');
						barCreated = false;						
					}

					for (i = 0; i < theData.length; i++) {
						addItemToBar(
							theData[i].id, 
							theData[i].name, 
							theData[i].comment, 
							theData[i].thumburl,
							theData[i].imgurl, 
							theData[i].theurl);
					}
				},
				error: 		function(req, msg) {
					showLoader (false);
				},
				complete:  	function(req, msg) {
					
				}
			} );			
		};
		
		
		// ========================================
		// = creates the bottom question cart bar
		// ========================================
		var createQBar = function () {
			var out = '<div id="cart" class="Box1">';
			out += '<div class="FR"><h6 id="yclosebt" class="ITN NV"><a href="#">Fragenkorb schlie&szlig;en</a></h6></div>';
			out += '<div class="YLtr"><div class="YLtrWrp"><div class="FL"><h6 id="yupdownarea" class="ITN Up"><a href="#">Up / Down Area</a></h6></div><div class="FR"><span id="ycartcaption">Meine Fragen</span></div><div class="FR"><div class="YLoader"></div></div><br class="FE" /></div></div>';
			out += '<div class="YLtr"><div class="YLtrWrp" id="ycartcnt"><div class="FR" id="openbtarea"><div class="ITN" id="yeditbtarea"><a href="#">Editieren</a></div><div class="ITN" id="ysend1btbtarea"><a href="#">Senden</a></div></div></div><br class="FE" /></div>';
			out += '<div class="YLtr"><div class="YLtrWrp" id="confirmarea">';
			out += '<div class="FL" style="width: 50%"><h5>Meine Fragen an hauff.com</h5><input type="hidden" id="hiddenCaptcha" name="hiddenCaptcha" value=""/></div><div class="FR" style="width:40%; padding-left: 24px"><h5>Bitte füllen Sie die folgenden Felder aus, damit wir mit Ihnen in Kontakt treten k&ouml;nnen.</h5><br /></div><br class="FE" />';
			out += '<div class="FL" style="width:50%"><div id="yeditlist"></div><div><h5 style="margin-top: 20px">Allgemeine Fragen oder Anregungen</h5><textarea id="yidmemo" name="yidmemo" style="width: 100%; height: 80px"></textarea></div></div><div class="FR" style="width:40%; padding-left: 24px">';
			out += '<label for="yidname">Name*</label><input type="text" name="yidname" id="yidname" /><br />';
			out += '<label for="yidcomp">Firmenname</label><input type="text" name="yidcomp" id="yidcomp" /><br />';
			out += '<label for="yidmail">Emailadresse*</label><input type="text" name="yidmail" id="yidmail" /><br />';
			out += '<label for="yidstreet">Strasse*</label><input type="text" name="yidstreet" id="yidstreet" /><br />';	
			out += '<label for="yidplz">PLZ*</label><input type="text" name="yidplz" id="yidplz" /><br />';	
			out += '<label for="yidcity">Stadt*</label><input type="text" name="yidcity" id="yidcity" /><br />';
			out += '<label for="yidphone">Telefon*</label><input type="text" name="yidphone" id="yidphone" /><br />';
			out += '<label for="yidfax">Fax</label><input type="text" name="yidfax" id="yidfax" /><br />';	
			out += '<div style="margin-top: 4px;font-size: 90%">* Pflichtfelder</div>';	
			out += '<br /><h5>Ihre Daten werden nicht weitergegeben, sondern dienen lediglich der Kommunikation mit Ihnen.</h5>';	
			out += '<br /><input type="checkbox" name="yidemailcopy" id="yidemailcopy" /><label for="yidemailcopy" style="margin-left: 8px; width:350px">Kopie dieser Email an eigene Adresse schicken.</label>';	
			out += '<br /><br /><p><a href="#" id="refreshing" title="Kicken Sie um das Bild zu aktualisieren."><img src="" width="132" height="46" alt="Captcha image" id="captchaImage" style="border: solid 1px #d7d7d7"/></a><br /><input type="text" maxlength="6" name="captcha" id="captcha" style="width:48px; margin-top: 4px"/> <label for="captcha" style="width: 300px">Bitte geben Sie die Sicherheitsabfrage ein!</label></p>';
			out += '<br /><div class="FR" style="border:none"><span id="ycancelbt" class="ITN"><a href="#">Abbrechen</a></span></div><div class="FR" style="border:none"><span id="ysendbt" class="ITN"><a href="#">Absenden</a></span></div><br class="FE" />';
						
			out += '</div><br class="FE" /><br />';
			out += '</div></div></div>';
			element.html (out);
			element.hover ( function () {
				if ( barState == 1 || barState == 0)
					openQBar ();
				else if (barState == 2)
					confirmQBar ();

				nowOpen = true;
			}, function () {
				nowOpen = false;
				setTimeout(function() {
					if (! nowOpen) {
						closeQBar ();
						nowOpen = false;
					}						
				}, settings.bar_closeInterval);
			});
			
			$('#yidmemo').change (function () {
				storeDataInCookie ();
			});
			$('#yidname').change (function () {
				storeDataInCookie ();
			});
			$('#yidmail').change (function () {
				storeDataInCookie ();
			});
			$('#yidcomp').change (function () {
				storeDataInCookie ();
			});
			$('#yidstreet').change (function () {
				storeDataInCookie ();
			});
			$('#yidplz').change (function () {
				storeDataInCookie ();
			});
			$('#yidcity').change (function () {
				storeDataInCookie ();
			});
			$('#yidphone').change (function () {
				storeDataInCookie ();
			});
			$('#yidfax').change (function () {
				storeDataInCookie ();
			});			
			
			restoreDataFromCookie ();
			
			$('#yeditbtarea a').click ( function () {
				confirmQBar ();
				nowOpen = true;
				return false;
			});
			$('#ysend1btbtarea a').click ( function () {
				confirmQBar ();
				nowOpen = true;
				return false;
			});			
			
			$('#ysendbt a').click ( function () {
				validateCaptcha ();
				return false;
			});
			$('#ycancelbt a').click ( function () {
				closeQBar ();
				storeDataInCookie ();
				nowOpen = false;
				return false;
			});			
		}
		

		var processCaptcha = function ( xml ) {
			var capVal = "";
			$(xml).find("headenvelope").each (function () {
				capVal = $(this).find("captchaid").text();
			});
			
			if (capVal != '' ) {
				$('#hiddenCaptcha').val(capVal);
				$('#captchaImage').attr('src', settings.url_captchaimg + '?nocache=' + new Date().getTime() );
				$('#refreshing').click ( function () {
					refreshCaptcha ();
					return false;
				} );
			}
		}
		
		var refreshCaptcha = function ( xml ) {
			$.ajax ( {
				type: 		"GET",
				url:  		settings.url_servercontroller, 
				dataType: 	"xml",
				cache:  	false,
				beforeSend: function (req) {				

				},				
				success: 	function(xml) {
					processCaptcha (xml);
				},
				error: 		function(req, msg) {

				},
				complete:  	function(req, msg) {
					
				}
			} );			
		}		
		
		var validateCaptcha = function () {
			// check captcha 
			var captchaData = {
				captcha: 	$('#captcha').val(),
				hiddenCaptcha: $('#hiddenCaptcha').val()
			}
			

			if ($('#captcha').val() == '') {
				alert ("Bitte geben Sie die Sicherheitsabfrage ein");
				$('#captcha').focus();
				return;
			} else {	
				
				$.ajax ( {
					type: "GET",
					url: settings.url_captchaproc,
					data: captchaData,
					cache: false,
					success: function(resp) {
						if (resp == "no") {
							alert ("Bitte geben Sie die Sicherheitsabfrage erneut ein oder klicken Sie auf die Zeichen um sie zu aktualisieren.");
							$('#captcha').focus();
							return;							
						}
						sendQuestions ();
					},
					error: function (req, msg) {
						
					}				
			 	});
			}
		}
				
		var sendQuestions = function () {
			if ($('#yidname').val() == '') {
				alert ("Bitte geben Sie Ihren Namen ein!");
				$('#yidname').focus();
				return;
			}
			if ($('#yidmail').val() == '') {
				alert ("Bitte geben Sie Email Adresse ein!");
				$('#yidmail').focus();
				return;
			}
			if($('#yidmail').val() == '') {
				alert ("Bitte geben Sie eine gültige Email Adresse ein!");
				$('#yidmail').focus();
				return;				
			}
			if($('#yidstreet').val() == '') {
				alert ("Bitte geben Sie eine Strasse ein!");
				$('#yidstreet').focus();
				return;				
			}
			if($('#yidplz').val() == '') {
				alert ("Bitte geben Sie Ihre Postleitzahl ein!");
				$('#yidplz').focus();
				return;				
			}		
			if($('#yidcity').val() == '') {
				alert ("Bitte geben Sie einen Ort ein!");
				$('#yidcity').focus();
				return;				
			}
			if($('#yidphone').val() == '') {
				alert ("Bitte geben Sie Ihre Telefonnummer ein!");
				$('#yidphone').focus();
				return;				
			}							
			var ajxData = {
				yaction: 	"send",
				yusrname:   $('#yidname').val(),
				yusrmail:   $('#yidmail').val(),
				yusrcomp:   $('#yidcomp').val(),
				yusrstreet: $('#yidstreet').val(),
				yusrplz: 	$('#yidplz').val(),
				yusrcity:   $('#yidcity').val(),
				yusrphone:  $('#yidphone').val(),
				yusrfax:    $('#yidfax').val(),
				yusrcopy:   $('#yidemailcopy').val(),
				ymemo:      $('#yidmemo').val() 				
			};
					
			$.ajax ( {
				type: 		"GET",
				url:  		settings.url_servercontroller, 
				dataType: 	"xml",
				data: 		ajxData, 
				cache:  	false,
				beforeSend: function (req) {
					showLoader (true);
				},				
				success: 	function(xml) {
					showLoader ( false );
					processCaptcha (xml);
					alert ("Vielen Dank für Ihre Anfrage");

					element.html('');

					barCreated = false;	
					
					window.location.href = settings.url_aftersucess;				
				},
				error: 		function(req, msg) {
					showLoader ( false );
				},
				complete:  	function(req, msg) {
					
				}
			} );
		};
		
		var validateEmail = function (s) {
			 var a = false;
			 var res = false;
			 if(typeof(RegExp) == 'function')
			 {
			  var b = new RegExp('abc');
			  if(b.test('abc') == true){a = true;}
			  }

			 if(a == true)
			 {
			  reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+
			                   '(\\@)([a-zA-Z0-9\\-\\.]+)'+
			                   '(\\.)([a-zA-Z]{2,4})$');
			  res = (reg.test(s));
			 }
			 else
			 {
			  res = (s.search('@') >= 1 &&
			         s.lastIndexOf('.') > s.search('@') &&
			         s.lastIndexOf('.') >= s.length-5)
			 }
			 return(res);
		}
		
		var controlOpenState = function (state, obj) {
			var dbgS = ("controlOpenState[state:" + state);
			
			var cssBtValue = obj.css("bottom").replace("px", '');
			var visibleHeight = 0;
			
			switch (state) {
				case 'close':
					visibleHeight = 18;
					break;
				case 'open' :
					visibleHeight = 220/*88 */;
					break;
				case 'confirm':
					visibleHeight = 580;
					break;
			}
			
			if (visibleHeight > obj.height() ) {
				visibleHeight = obj.height();
			}
			
			dbgS += ";height:" + obj.height() + ";visibleHeight:" + visibleHeight + "";
			var newBottomValue = (obj.height() * -1) + visibleHeight;
			
			obj.css('bottom', newBottomValue + "px");			
			dbgS += ";newbottomstyle:" + obj.css("bottom") + "]";
		}
		
		var openQBar = function (interval) {
			element.removeClass();
			element.addClass('YOpenBarClass');
			
			controlOpenState ('open', element);
			
			$('#yclosebt').removeClass('NV');
			$('#yclosebt a').click(function () {
				nowOpen = false;
				closeQBar ();
				return false;
			});
			$('#yupdownarea').removeClass('Up');
			$('#yupdownarea').addClass('Down');	
			$('#yupdownarea a').click(function () {
				nowOpen = false;
				closeQBar ();
				return false;
			});
			
			

			if ( interval != null ) {
				
				setTimeout(function() {
					if (! nowOpen) {
						closeQBar ();
						nowopen = false;
					}						
				}, interval);				
			}
			
			barState = 1;			
		}
		
		var confirmQBar = function () {
			element.removeClass('ClosedCartArea');
			element.removeClass('YOpenBarClass');
			element.addClass('YConfirmBarClass');			
			controlOpenState ('confirm', element);
			
			barState = 2;	
		}
		
		var closeQBar = function () {
			element.removeClass('YConfirmBarClass');
			element.removeClass('YOpenBarClass');
			element.addClass('ClosedCartArea');
						
			controlOpenState ('close', element);
			
			$('#yupdownarea').removeClass('Down');
			$('#yupdownarea').addClass('Up');						
			$('#yclosebt').addClass('NV');	
			if (barState == 2) {
				storeDataInCookie ();
			}
			barState = 0;		
		}
		
		var addItemToBar = function(id, name, comment, thumb, img, theurl) {
			// first check if there is an item with the same id
			// when true then just change the comment
			if ( $('#ybarentry_' + id).length > 0 ) {
				$('#ybarentry_' + id).each ( function () {
					$(this).html(comment);
					$(this).click( function () {
						window.location  = theurl;
					});					
					$(this).hover ( function () {
						var tt = comment.replace('\n', '<br />');
						$('#ytt_' + id ).remove();						
						t = '';
						t += '<div id="ytt_' + id + '" class="YTooltip">';
						t += tt;
						t += '</div>';
						$('body').append(t);


						var offParent = $('#ybarentry_' + id ).offset();
						var theTop = offParent.top - $('#ytt_' + id ).height() ;
						var theLeft = ((offParent.left + $('#ybarentry_' + id ).width()) / 2) - ($('#ytt_' + id ).width() / 2) ;

						$('#ytt_' + id ).css("left", offParent.left + "px");
					}, function () {
						$('#ytt_' + id ).remove();
					});
				});
				$('#ybarconfirmentry_' + id + ' .QCartConfirmItemImage a').each (function () {
					$(this).html(comment);
				});
				
				$('#ybarconfirmentry_' + id + ' textarea').each (function () {
					$(this).html(comment);
				});
			} else {			
				var t = "";
				t += '<div id="ybarentry_' + id  + '" class="ITN QCartItem" ';
				t += 'style="background:url(' + thumb + ') center center no-repeat #fff"';
				t += '>';
				t += comment;
				t += '</div>';
			
				$('#ycartcnt').append ( t );
			
				$('#ybarentry_' + id ).click( function () {
					window.location = theurl;
				});
				$('#ybarentry_' + id ).hover ( function () {
					var tt = comment.replace('\n', '<br />');
					t = '';
					t += '<div id="ytt_' + id + '" class="YTooltip">';
					t += tt;
					t += '</div>';
					$('body').append(t);
				
				
					var offParent = $('#ybarentry_' + id ).offset();
					var theTop = offParent.top - $('#ytt_' + id ).height() ;
					var theLeft = ((offParent.left + $('#ybarentry_' + id ).width()) / 2) - ($('#ytt_' + id ).width() / 2) ;

					$('#ytt_' + id ).css("left", offParent.left + "px");
				}, function () {
					$('#ytt_' + id ).remove();
				});
			
			

				// now add the item to the confirmation list		
				t = '';
				t += '<div id="ybarconfirmentry_' + id + '" class="QCartConfirmItem">';
				t += '<div class="FL QCartConfirmItemImage ITN">';
				t += '<a href="' + theurl + '" style="background:url(' + thumb + ') center center no-repeat #fff">' + comment + '</a>';
				t += '</div>';
				t += '<div class="FR QCartConfirmItemArea" style="border: none"><textarea>' + comment + '</textarea></div>';
				t += '<br class="FE" />';
				t += '<div class="FR DeleteLink" style="border: none"><a href="#">L&ouml;schen</a></div><br class="FE" />';
				t += '</div>';
				$('#yeditlist').append (t);
				
				$('#ybarconfirmentry_' + id + ' textarea').change (function () {
					var tu = $('#ybarconfirmentry_' + id + ' .QCartConfirmItemImage a').attr("href");
					
					updateComment (id, $(this).val(), tu);				
				});
								
				$('#ybarconfirmentry_' + id + ' .DeleteLink a').each ( function () {
					$(this).click( function() {
						deleteQuestion (id);
						return false;
					} );
				});
			}			
		}
		
		var storeDataInCookie = function () {
			var COOKIE_NAME = 'hauff.com.qcart';
			var cOptions = { path: '/', expires: 10 };
			var pData = '';
			
			pData += '' + $('#yidname').val() + '|';
			pData += '' + $('#yidmail').val() + '|';
			pData += '' + $('#yidcomp').val() + '|';
			pData += '' + $('#yidstreet').val() + '|';
			pData += '' + $('#yidplz').val() + '|';
			pData += '' + $('#yidcity').val() + '|';
			pData += '' + $('#yidphone').val() + '|';
			pData += '' + $('#yidfax').val();
			
			$.cookie (COOKIE_NAME + ".memo", $('#yidmemo').val(), cOptions);
			$.cookie (COOKIE_NAME + ".person", pData, cOptions);
		}
		
		var restoreDataFromCookie = function () {
			var COOKIE_NAME = 'hauff.com.qcart';
			if ($.cookie(COOKIE_NAME + ".memo") != null && $.cookie(COOKIE_NAME + ".memo") != '')
				$('#yidmemo').val($.cookie(COOKIE_NAME + ".memo"));
			
			if ($.cookie(COOKIE_NAME + ".person") != null && $.cookie(COOKIE_NAME + ".person") != '') {
				var pArr = $.cookie(COOKIE_NAME + ".person").split ('|');
				if (pArr && pArr[0] != 'undefined')
					$('#yidname').val(pArr[0]);
				if (pArr && pArr[1] != 'undefined')
					$('#yidmail').val(pArr[1]);
				if (pArr && pArr[2] != 'undefined')
					$('#yidcomp').val(pArr[2]);
				if (pArr && pArr[3] != 'undefined')
					$('#yidstreet').val(pArr[3]);
				if (pArr && pArr[4] != 'undefined')	
					$('#yidplz').val(pArr[4]);
				if (pArr && pArr[5] != 'undefined')	
					$('#yidcity').val(pArr[5]);
				if (pArr && pArr[6] != 'undefined')	
					$('#yidphone').val(pArr[6]);
				if (pArr && pArr[7] != 'undefined')
					$('#yidfax').val(pArr[7]);
			}
		}
		
		var updateComment = function (id, question, theurl ) {
			var ajxData = {
				yaction: 	"add",
				yimgid:    	id,
				yimgcomment: question,
				yimgurl: 	theurl		
			};
						
			$.ajax ( {
				type: 		"GET",
				url:  		settings.url_servercontroller, 
				dataType: 	"xml",
				data: 		ajxData, 
				cache:  	false,
				beforeSend: function (req) {
					showLoader (true);
				},				
				success: 	function(xml) {
					showLoader (false);
					processCaptcha (xml);
					var theData = {
						id: '',
						name: '',
						thumburl: '',
						imgurl:   '',
						comment: '',
						theurl:  ''
					};
					$(xml).find("item").each ( function () {
						if ($(this).attr("id") == id) {
							theData.id = $(this).attr("id");
							theData.name = $(this).find("name").text();
							theData.comment = $(this).find("comment").text();
							theData.theurl = $(this).find("imgurl").text();
							theData.thumburl = $(this).find("img").find("thumb").text();
							theData.imgurl = $(this).find("img").find("file").text();
						}
					});

					addItemToBar(theData.id, theData.name, 
						theData.comment, theData.thumburl, 
						theData.imgurl, theData.theurl); 					
				},
				error: 		function(req, msg) {
					showLoader (false);
				},
				complete:  	function(req, msg) {
					
				}
			} );			
		}
		
		var showLoader = function (show) {
			if (show) {
				$(".YLoader").css("display", "block");
			} else {
				$(".YLoader").css("display", "none");
			}
		}
		
		var addQuestionToBar = function (id, question,imagepath) {
			var ajxData = {
				yaction: 	"add",
				yimgid:    	id,
				yimgcomment: question,
				yimgurl: 	location.href		
			};
			

			
			$.ajax ( {
				type: 		"GET",
				url:  		settings.url_servercontroller, 
				dataType: 	"xml",
				data: 		ajxData, 
				cache:  	false,
				beforeSend: function (req) {
					showLoader (true);
				},
				success: 	function(xml) {
					showLoader ( false );
					processCaptcha (xml);
					var theData = {
						id: '',
						name: '',
						thumburl: '',
						imgurl:   '',
						comment: '',
						theurl:  ''
					};
					$(xml).find("item").each ( function () {
						if ($(this).attr("id") == id) {
							theData.id = $(this).attr("id");
							theData.name = $(this).find("name").text();
							theData.comment = $(this).find("comment").text();
							theData.theurl = $(this).find("imgurl").text();
							theData.thumburl = $(this).find("img").find("thumb").text();
							theData.imgurl = $(this).find("img").find("file").text();
						}
					});
					
					addItemToBar(theData.id, theData.name, 
						theData.comment, theData.thumburl, 
						theData.imgurl, theData.theurl); 					
				},
				error: 		function(req, msg) {
					showLoader (false);
				},
				complete:  	function(req, msg) {
					
				}
			} );
			
		}
		
		
		var deleteQuestion = function (id) {
			var ajxData = {
				yaction: 	"rem",
				yimgid:    	id		
			};			
			$.ajax ( {
				type: 		"GET",
				url:  		settings.url_servercontroller, 
				dataType: 	"xml",
				data: 		ajxData, 
				cache:  	false,
				beforeSend: function (req) {
					showLoader (true);
				},				
				success: 	function(xml) {
					showLoader (false);
					deleteItem(id);
					processCaptcha (xml);
				},
				error: 		function(req, msg) {
					showLoader (false);
				},
				complete:  	function(req, msg) {
					
				}
			} );
		}
		
		var deleteItem = function (id) {
			$('#ybarconfirmentry_' + id).remove();
			$('#ybarentry_' + id).remove ();
			
			if ($('.QCartConfirmItem').length == 0 ) {
				element.html('');
				barCreated = false;
			}
			
			
		}
		
		// ============================================================================
		// = replaced / modifies the page content, specially the pony gallery content =
		// ============================================================================
		var modiContent = function () {
			if (mainCommentField['obj'] != null) {
				initMainCommentField ();
			}
		}
		
		// =====================================
		// = initialize the main comment field =
		// =====================================
		var initMainCommentField = function (theField) {
				mainCommentField['obj'].click(function () {
					mainCommentField.openInputArea();
				});			
		}
	};
	
	
	
	/**
	 ** JQUERY WRAPPER 
	 **/
	$.fn.qcart = function (options) {
		return this.each ( function () {
			var element = $(this);			
			// returns if this element already has a plugin instance
			if (element.data('qcart')) return;
			
			var myQCartManager = new QCartManager(this, options);
			element.data('qcart', myQCartManager);	
			myQCartManager.run ();	
		});
	};
}) (jQuery);


/*
 * jquery cookie plugin
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { 
        options = options || {};
        if (value === null) {
            value = '';
            options = $.extend({}, options); 
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); 
        }


        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);

                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
