jQuery(document).ready(function() {
	//insertHelp();
    jQuery("#helpText").corner("dog tr 15px");

});

function insertHelp() {
	jQuery(".component").each(function() {
		jQuery(this).css("float", "left");
		if(jQuery(this).next().attr("id")!="helpLogo") {
		    jQuery("#imgHelp0").show(0);
		    jQuery("#helpLogo").insertAfter(".component");
	        jQuery(".required").after("<label class='lblExampleInput'>::</label>");
	        jQuery(".phone").after("<label class='lblExampleInput'>(Country Code)AreaCode PhoneNumber</label>");

	        
	        jQuery("textarea").each(function(e){
	        	clase= document.getElementById(this.id).getAttribute("class");
	        	if (clase=="wysiwyg"){
	                jQuery(this).wysiwyg({
                        controls : {
                           insertOrderedList : { visible : true },
                           insertUnorderedList : { visible : true },
                           insertImage: {visible: false},
                           createLink: {visible: false},
                           separator01: {visible: false},
                           separator06 : { visible : false },
                           h1: {visible: false},
                           h2: {visible: false},
                           h3: {visible: false},
                           h1mozilla: {visible: false},
                           h2mozilla: {visible: false},
                           h3mozilla: {visible: false},
                           increaseFontSize : { visible : false && !( $.browser.msie ), tags : ['big'] },
                           decreaseFontSize : { visible : false && !( $.browser.msie ), tags : ['small'] },
                           removeFormat : {visible : true }

                          },
                          css: {fontFamily : 'verdana'}
	                });
	        	}
	        }); 
	    }
    });
    jQuery(".component").each(function() {
        if(jQuery(this).attr("title") == undefined  || jQuery(this).attr("title") == "") {
	        jQuery(this).next().css("display", "none");
	    }
	});
    jQuery("#imgHelp0").hide(0);
    var idHelp = 0;
    jQuery(".divHelp").each(function() {
        jQuery(this).find("img").each(function() {
            jQuery(this).attr("id", "imgHelp" + idHelp);
            idHelp++;
        })
    });
    jQuery(".imgHelp").each(function(){
        jQuery(this).mouseover(function() {
            var prev = jQuery(this).parent().prev();
            jQuery("#helpTextContent").attr("innerHTML", prev.attr("title"));
            jQuery("#helpText").css("top", getElementPosition(jQuery(this).attr("id")).top);
            jQuery("#helpText").css("left", getElementPosition(jQuery(this).attr("id")).left + 50 + "px");
            jQuery("#helpText").show("normal");            
        });
        jQuery(this).mouseout(function() {
            jQuery("#helpText").hide("fast");            
        });
    });
    
	   //setTimeout("insertHelp()", 300);
}
/*
* Function to get position to open options div
*/
function getElementPosition(elemID)
{
    var offsetTrail = document.getElementById(elemID);
    var offsetLeft = 0;
    var offsetTop = 0;
    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 &&
    typeof document.body.leftMargin != "undefined") {
    offsetLeft += document.body.leftMargin;
    offsetTop += document.body.topMargin;
    }
    return {left:offsetLeft, top:offsetTop};
}

///////////////////////////////////// RIGO FORM FUNCTIONS //////////////////////
 function showMessage(obj){
     if (jQuery(obj).next().css("display") == "none"){
		jQuery(obj).next().show("normal");
     }else{
	    jQuery(obj).next().hide("normal");
	 }
 }

 function showChangeLocation(){
     /* if (jQuery("#tx_ltgformsv2_pi1__chgLocation").css("display") == "none"){
	      jQuery("#tx_ltgformsv2_pi1__chgLocation").show("normal");
      }else{
		  jQuery("#tx_ltgformsv2_pi1__chgLocation").hide("normal");
      }*/
      
     jQuery(".information").each(function(e){
     	 if (jQuery(this).css("display") == "none"){
     	 	jQuery(this).show();
     	 }
     });
 }
		                         
function showSection(){
	//Check If exist Information like Country - City and neigtboarhood
	        if (jQuery("#tx_ltgformsv2_pi1__country").val()){
		        jQuery("#tx_ltgformsv2_pi1__countryDiv").css("display","none");
	        }
	        if (jQuery("#tx_ltgformsv2_pi1__city").val() && jQuery("#tx_ltgformsv2_pi1__city_error").attr("innerHTML") != "<br>Dies ist keine Stadt / Ort"){
		       jQuery("#tx_ltgformsv2_pi1__cityDiv").css("display","none");
	        }else{
	        	//Put Neighboardhood message
	        	html = "<span>No neighborhoods found for that destination.</span>";
	        	jQuery('div[innerHTML=Neighborhood]').next().find('div').attr('innerHTML',html);
	        	jQuery("#tx_ltgformsv2_pi1__cityzoneDiv").css("display","none");
	        }
	        //Change by suvarna to show city text box when description will empty.
	        if (jQuery("#tx_ltgformsv2_pi1__description_destination_error").attr("innerHTML") == "<br>Dies ist ein Pflichtfeld"){
		       jQuery("#tx_ltgformsv2_pi1__cityDiv").css("display","block");
	        }
	        jQuery("input[name=tx_ltgformsv2_pi1__cityzone]").each(function(e){
		        if(this.checked == true){
		        	jQuery("#tx_ltgformsv2_pi1__cityzoneDiv").css("display","none");
		        }
	 });
	
	 /*
	    Only in Login Form
	 */
	 jQuery("#create_new_account").click(function(e){
	 	jQuery("#email_login").attr("innerHTML","Email*");
	 });
	 
	 jQuery("#login_existing_account").click(function(e){
	 	jQuery("#email_login").attr("innerHTML","Benutzername*");
	 });
	 
	 if (jQuery("#email_login").attr("innerHTML")){
	 	jQuery("#email_login").attr("innerHTML","Benutzername*");
	 }
	 
	
    //Add the property to name  IN GERMAN PREFIX ARE DIFFERENT
	//jQuery("div [innerHTML=\"Name von\"]").attr("innerHTML","Name von "+jQuery("#propertyHidden").attr("innerHTML"));
	
	//Change title when change city
	jQuery("#tx_ltgformsv2_pi1__city").blur(function(e){
	     if (jQuery("#tx_ltgformsv2_pi1__city").val() != ""){
		      jQuery("#cityName").attr("innerHTML",jQuery("#tx_ltgformsv2_pi1__city").val());
		 }else{
		      jQuery("#cityName").attr("innerHTML",jQuery("#tx_ltgformsv2_pi1__country").val()); 
		 }
	});
	                 
	jQuery(".titleGroup").each(function(e){
	     if(jQuery(this).next().next().attr("class") != "groupWrap openDiv"){
		      jQuery(this).next().next().slideUp(0);
		      jQuery(this).prepend("<label>[+]</label>");
		 }else{
		      jQuery(this).prepend("<label>[-]</label>");
		 }
		                                  
         jQuery(this).click(function(){
	         if (jQuery(this).next().next().css("display") == "block"){
		         jQuery(this).next().next().slideUp("normal");
		         jQuery(this).find("label").each(function(){
		            jQuery(this).attr("innerHTML","[+]");
		         });
		     }else{
		          jQuery(this).next().next().slideDown("normal");
		          jQuery(this).find("label").each(function(){
		              jQuery(this).attr("innerHTML","[-]"); 
		           });
		     }
        });     
    });
    jQuery("textarea").each(function(){
    	rExp = "/"+"<br>"+"/g";
	    rExp = eval(rExp);
	    if(jQuery(this).attr("innerHTML")) {
    	    jQuery(this).attr("innerHTML", jQuery(this).attr("innerHTML").replace(/<br>/g, '\n').replace(/<br>/g, '\n'));
	    }
	    if(jQuery(this).val()) {
    	    jQuery(this).val(jQuery(this).val().replace(/<br>/g, '\n').replace(/<br>/g, '\n'));
	    }
    });
    jQuery(".calendarDate").each(function(){
       jQuery(this).datepicker(); 
    });
    
    insertHelp();
};

