// @package SellTimeShare
if (jQuery) {  
	jQuery(document).ready(function(){

		myurl = 'http://www.selltimeshare.org';
	
		jQuery("#ajax-load").ajaxStart(function(){
			jQuery(this).show();
		});
		jQuery("#ajax-load").ajaxStop(function(){
			jQuery(this).hide();
		});
		
		jQuery('#mainform select#cat').parent().addClass('stsExtended');
		jQuery('.stsExtended').html('<label>Select Country</label><select id="cat_country" name="cat_country" class="dropdownlist"></select><br clear="left"/><br clear="left"/><label>Select Region(State)</label><select id="cat_state" name="cat_state" class="dropdownlist"></select><br clear="left"><br clear="left"/><label>Select Resort</label><select id="cat" name="cat" class="dropdownlist"></select>&nbsp;&nbsp;&nbsp;<input type="submit" value="Go&rsaquo;&rsaquo;" class="btn_orange" id="getcat" name="getcat">');
		jQuery.ajax({
				url: myurl+"/wp-content/plugins/selltimeshare-ext/selltimeshare-ext-ajax.php?action=getchildren&parent=0",
				cache: false,
				success: function(html){
					jQuery('#mainform #cat_country').html(html);
				}
		});
		jQuery('#cat_country').change(function() {
			jQuery.ajax({
				url: myurl+"/wp-content/plugins/selltimeshare-ext/selltimeshare-ext-ajax.php?action=getchildren&parent="+jQuery('#cat_country').val(),
				cache: false,
				success: function(html){
					jQuery('#mainform #cat').html('');
					jQuery('#mainform #cat_state').html(html);
				}
			});
			
		});
		jQuery('#cat_state').change(function() {
			jQuery.ajax({
				url: myurl+"/wp-content/plugins/selltimeshare-ext/selltimeshare-ext-ajax.php?action=getchildren&parent="+jQuery('#cat_state').val(),
				cache: false,
				success: function(html){
					jQuery('#mainform #cat').html(html);
				}
			});
			
		});	
		
		jQuery('#mainform ol li label').each(function(){
			if (jQuery(this).text() == 'State:'){
				jQuery(this).text('Timeshare:');
			}
			if (jQuery(this).text() == 'State:*'){
				jQuery(this).text('Location:');
			}

					
		});	
		
			
		
		jQuery.ajax({
				url: myurl+"/wp-content/plugins/selltimeshare-ext/selltimeshare-ext-ajax.php?action=getstate&child="+jQuery('#cat').val(),
				cache: false,
				success: function(html){
					jQuery('#cp_state').html(html);
				}
		});
		jQuery.ajax({
				url: myurl+"/wp-content/plugins/selltimeshare-ext/selltimeshare-ext-ajax.php?action=getcountry&child="+jQuery('#cat').val(),
				cache: false,
				success: function(html){
					jQuery('#cp_country').html(html);
				}
		});			
		jQuery.ajax({
				url: myurl+"/wp-content/plugins/selltimeshare-ext/selltimeshare-ext-ajax.php?action=getdescription&child="+jQuery('#cat').val(),
				cache: false,
				success: function(html){
					jQuery('#post_content').html(html);
					jQuery('#post_content').htmlarea();
					jQuery('.jHtmlArea').before('You can edit this default timeshare description:');
				}
		});	
		
		
	});
} else {
	if (window.console && console.log) {
    console.log('Error loading JQuery Javascript library!'); //for firebug
  }else{
	alert ('Error loading JQuery Javascript library!');
}
}
