/**
 * Web NameSpace
 */
var Web = window.Web || 
{  
		   
};

Web.Search = {

    getData:function(action,section,input_type)
    {
        var baseStringURL = Web.Options.baseURL + 'ajax_inputs.php';

        switch(action)
        {
            case "getcities":
                var data = { 
                            action: action,
                            c_id: $("select[name='country']").val(),
                            s_id: $("select[name='state']").val(),
                            cat_id: $("select[name='category']").val(),
                            specialty:$("select[name='specialty']").val()
                           };
                
                break;
            
            case "getstates":
                var data = { 
                            action: action,
                            c_id: $("select[name='country']").val(),
                            cat_id: $("select[name='category']").val(),
                            specialty:$("select[name='specialty']").val()
                           };
            
                break;
            case "getcountries":
	            var data = { 
                            action: action,
                            cat_id: $("select[name='category']").val(),
                            specialty:$("select[name='specialty']").val()
	                       };
            
                break;
                
            case "getspecs":
                var data = { 
                            action: action,
                            cat_id: $("select[name='category']").val()
                       };
                if(input_type=="multi"){
                    data.m = input_type;
                }
                
                break;
        }
        if(section == "mem_profile" || section == "membership")
        {
            data.cat_id = '';
            data.specialty = '';
            data.section = section;
        }
        
        $.get(baseStringURL, data, function(resultdata)
	        {
	            
	            var newdata = $.evalJSON(resultdata);
	            
	            switch(action)
	            {
	            case "getcities":
	                        $('#cities').html(newdata.cities);
	                        break;
	          
	            case "getstates":
	                        $('#states').html(newdata.states);
	                        break;
	           
	            case "getcountries":
	                        $('#countries').html(newdata.countries);
	                        break;
	           
	            case "getspecs":
	                        $('#specs').html(newdata.specs);
	                        break;
	            }
	
	        });
    }
};

Web.MembersAds = {

	changeAdImageSizeText: function(){

		if($("#select2").val() == "1")
		$('#adImageSize').html(" (200x200)");
		else
		$('#adImageSize').html(" (550x290)");
	},

  getRegion: function()
  {
    var baseStringURL = Web.Options.baseURL + 'ajax_inputs.php';
    var data = { 
                            action: 'getregion',
                            region_scope: $('#region_scope').val(),
                            ads_plan: $('#ads_plan').val(),
                            section: 'memberads'
               };
    if($("#trStateScope").length > 0)
      data['state_scope'] =  $('#state_scope').val();                          
                    
    $.post(baseStringURL, data, function(resultdata)
    {
      var newdata = $.evalJSON(resultdata);

      if(newdata.state_scope){
        var htmlData = '<tr id="trStateScope"><td colspan="3" valign="top">'+
                       '<strong>Region State</strong> <span class="subalert">*</span><br />'+
                       newdata.state_scope+'</td></tr><span id="t_state_scope" class="hideRequired"></span>';
                                            
        if($("#trStateScope").length <= 0)                             
          $("#trRegionBox").before(htmlData);

        a_fields['state_scope'] = {'l':'Region State','r':true,'t':'t_state_scope'};
        a_fields['region'] = {'l':'Region','r':true,'t':'t_region'};
      }

      if($("#trRegionBox").length <= 0)
      {
        var regionBoxHTML = '<tr id="trRegionBox">'+
                            ' <td colspan="3" valign="top">'+
                            ' <strong>Region</strong> <span class="subalert">*</span><br>'+
                            '  <div id="regionBox">'+
                            '  </div>'+
                            '  </td>'+
                            '  </tr><span id="t_region" class="hideRequired"></span>';
        $("#trRegionScope").after(regionBoxHTML);
      }

      $('#regionBox').html(newdata.region);
             
      if(data.region_scope != "City/Metro"){
        if($("#trStateScope").length > 0){
          a_fields['state_scope'] = null;
          $("#trStateScope").remove();
        }
        a_fields['region'] = {'l':'Region','r':true,'t':'t_region'};   
                
        if($("#trRegionBox").length > 0 && data.region_scope == "World"){
          $('#trRegionBox').remove();
          a_fields['region'] = null;
        }
      }

      $('#ad_price_box').html(newdata.adPrice);

    });
	}

};

Web.Select = {
  getData: function (action, plan_id, responseDiv) {
    var baseStringURL = Web.Options.baseURL + 'ajax_inputs.php';
    var data = { action: action, plan_id: plan_id };
    $.get(baseStringURL, data, function(resultData) { $(responseDiv).html(resultData); });
  } 
};

Web.Options = {
        
		 //baseURL: "http://123.201.3.153/pbb/"
		 //baseURL: "http://pbb.cobaltcoyote.com/"
		baseURL: "/"
		//baseURL: ""
};

function checkMax(obj, allow) {
	var selected = 0;
	for(var i=0; i<obj.options.length; i++) {
		if(obj.options[i].selected) {
			selected++;
		}
		if(obj.options[i].selected && selected > allow) {
			obj.options[i].selected = false;
		}
		
	}
	if(selected >= allow) {
		alert('You may only select up to ' + allow + ' options');
		return false;
	} else {
		return true;
	}
}
