$(document).ready(function(){

	// initialize the tabber tabs
	$('.tabber').accessibleTabs({
    	wrapperClass: 'content',
    	currentClass: 'current',
    	tabhead: 'h2',
    	tabbody: '.tabbertab',
    	fx:'fadeIn',
    	fxspeed: 'fast',
    	currentInfoText: '',
    	currentInfoPosition: 'prepend',
    	currentInfoClass: 'current-info'
	});
	
	//listing items hover
   	$('.listing_title').hover(function() {
     	$(this).parent().addClass("listing_title_hover");
   		}, function() {
   		$(this).parent().removeClass("listing_title_hover");
  	});

   	$('.listing_actions a, .listing_last_action a, .listing_icon').hover(function() {
     	$(this).addClass("listing_actions_hover");
   		}, function() {
   		$(this).removeClass("listing_actions_hover");
  	});
  	

		// when currency rate is changed then fill in the date updated field with todays date  
    $("input[name$='[rate]']").change(function() {
	 	var dtm = new Date();
	 	$(this).parent().next().children("input").css("color", "green");
	 	$(this).parent().next().children("input").val(dtm.asString()); 
	});
  	

	 
	//automatically hide messages after 3 seconds
	window.setTimeout(function() {
 		$('.pagemessage').slideUp();
	}, 3000);
	window.setTimeout(function() {
 		$('.errormessage').slideUp();
	}, 3000);

	//documens tab update title + file toggles
       $(".updatedocsform").css("display","none");
       $(".updatedocscheckbox").click(function(){
      		$(this).parent().parent().children("a").toggle();
       		$(this).parent().parent().children(".updatedocsform").toggle();
            });
            
    	//offers tab update title + description toggles
       $(".updateoffersform").css("display","none");
       $(".updateofferscheckbox").click(function(){
      		$(this).parent().parent().children(".offeritem").toggle();
       		$(this).parent().parent().children(".updateoffersform").toggle();
            }); 
            
    	//testimonials tab update title + description toggles
       $(".updatetestimonialsform").css("display","none");
       $(".updatetestimonialscheckbox").click(function(){
      		$(this).parent().parent().children(".testimonialitem").toggle();
       		$(this).parent().parent().children(".updatetestimonialsform").toggle();
            });             
                   
     
      
//images tab update file toggles
	$(".statsmorebtn").click(function(){
  	$(this).parent().parent().parent().children(".boxcontents").toggle();
  });

      
//images tab update file toggles
	$(".extra").css("display","none");
  $(".checkme").click(function(){
  	$(this).parent().parent().children(".extra").toggle();
  });

    

    jQuery.fn.outerHTML = function() {
        return $('<div>').append( this.eq(0).clone() ).html();
    }; 

	
    //JQuery code to copy resources title+url into their field whn u paste code 
    $("#resourcecode").change(function() {
      var description = $("#resourcecode").val();
      var match = /<a\s+[^>]*href="([^"]*)"[^>]*>(.*)<\/a>/i.exec(description);
		if (match!=undefined ) {
      		var url = match[1];
      		var text = match[2]; 
			$("input[name='name']").val(text);
			$("input[name='url']").val(url);
			$("input[name='name']").parent().addClass("curInputFocus");
			$("input[name='url']").parent().addClass("curInputFocus");		
			window.setTimeout(function() {$("input[name='name']").parent().removeClass("curInputFocus");}, 1000);
			window.setTimeout(function() {$("input[name='url']").parent().removeClass("curInputFocus");}, 1000);
		}
    });
    
    //JQuery code to copy Latitude + Longitude + zoom level when you paste google maps url 
    $("#googlemapurl").change(function() {
      var googlemapurl = $("#googlemapurl").val();
      var match = /&ll=([\-0-9\.]+),([\-0-9\.]+)(.*)z=([\-0-9\.]+)/i.exec(googlemapurl);
		if (match!=undefined ) {
      		var latitude = match[1];
      		var longitude = match[2];
      		var mapzoom = match[4]; 
			$("input[name='latitude']").val(latitude);
			$("input[name='longitude']").val(longitude);
			$("input[name='mapzoom']").val(mapzoom);
			$("input[name='latitude']").parent().addClass("curInputFocus");
			$("input[name='longitude']").parent().addClass("curInputFocus");
			$("input[name='mapzoom']").parent().addClass("curInputFocus");		
			window.setTimeout(function() {$("input[name='latitude']").parent().removeClass("curInputFocus");}, 1000);
			window.setTimeout(function() {$("input[name='longitude']").parent().removeClass("curInputFocus");}, 1000);
			window.setTimeout(function() {$("input[name='mapzoom']").parent().removeClass("curInputFocus");}, 1000);
		}
    });    


			//highlight input fields
			$("select,textarea,input:not([type='checkbox'],.nohover)").focus(function() {
				$(this).parent().addClass("curInputFocus");
			});
			
			$("select,textarea,input").blur(function() {
				$(this).parent().removeClass("curInputFocus");
			});


		// draw multiple select boxes using asmselect
    $("select[multiple]").asmSelect();

	// automatically apply date picker
	$('.datepicker').datePicker({clickInput:true,createButton:false});

 });

window.onload=show;
function show(id) {
var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
	}
if (d) {d.style.display='block';}
}


function confirmaction(message,url) {
	if (confirm(message)) {
	    location.href = url;
	}
}

function popupWindow(url) {
	window.open(url,"","scrollbars=yes,resize=yes,menubar=yes,status=yes,toolbar=no,files=no,width=600,height=600,left=25,top=25");
}

function toggleDivDisplay(divId) {
  var div = document.getElementById(divId);
  div.style.display = (div.style.display=="block" ? "none" : "block");
}

function toggleMenuArrow(divId) {
  var div = document.getElementById(divId);
  div.style.backgroundImage = (div.style.backgroundImage=="url(images/menu-expanded.gif)" ? "url(images/menu-collapsed.gif)" : "url(images/menu-expanded.gif)");
  div.style.backgroundRepeat = "no-repeat";
}

function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];		
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}	
	}
	return (arrReturnElements)
}

function AddField(strclass){
	trs=getElementsByClassName( document, "div", strclass);
	for(var w=0;w<trs.length;w++){
		if(trs[w].style.display=="none"){
			trs[w].style.display="block"
			var control=document.getElementById("field"+trs[w].id)
			try{control.focus()}
			catch(e){}
			break
		}
	}
}



