$(document).ready(function() {
  
  loadprevnextlinks();
  loadmyapplicationdeadlines();
  loadmyapplications();
  loadmyauditions(); 
  loadrecentapplications();
  
  $("#mod_search_searchword").autocomplete("/ajax/getsearchnames.php", {
  		width: 260,
  		max: 300,
  		minChars:2,
  		selectFirst: false
  		
  		
   });
   
    $("#searchbox").autocomplete("/ajax/getsearchnames.php", {
     		width: 260,
     		max: 300,
     		minChars:2,
     		selectFirst: false
     		
     		
   });
   
   
 
  
 
   $('#accompanisttools').each(function(i) {
         
        
             
        $.get('/ajax/getaccompanistmenu.php', {'uniqueid': new Date().getTime()}, function(data) {
       		 $('#accompanisttools').html(data);

       
	    });
         
  });   
  /*
    $('#appdecisions').each(function(i) {
         
        
             
        $.get('/ajax/getappdecisions.php', {'uniqueid': new Date().getTime()}, function(data) {
       		 $('#appdecisions').html(data);

       
	    });
         
  });   
   */
   
 
  
  $('.ptform .required').prev('label').end().after(' <span class="reqstar">*</span>');
   $('.ptform .required2').prev('label').end().after(' <span class="reqstar">*</span>');
 
     var emailFormat = /[-_\.a-zA-Z0-9]+@[-_\.a-zA-Z0-9]+(\.\w)+/i;
  
     
  
  $(".featuretab").hover(
        function () {
        $(".featuretab").each (function() { $(this).attr("src",$(this).attr("inactive")) });
             $('.featuretabtext').hide();
             $('#' + $(this).attr('featurediv')).show();
             $(this).attr("src",$(this).attr("active"));

    	     
   }, 
        function () {
          //   $(this).attr("src",$(this).attr("inactive")); 

    });
    
    
    
  
  
  
     
     $('#country').change(function() {
         $.get('/ajax/getstates.php', {'country': $(this).val()}, function(data) {
         $('#states').html(data);
          });
     });
     
     $('#country').trigger('change');
  
  
  
     $('form :input').blur(function() {
  
        $(this).parent('div:first').removeClass('warning').find('span.error-message').remove();
        $(this).parent('li:first').removeClass('warning').find('span.error-message').remove();
        
	var $listItem = $(this).parents('li:first');
	
 	if ($listItem.html() == null)
	{
	    $listItem = $(this).parents('div:first');
	}

        if ($(this).is('.required')) {


		$listItem.removeClass('warning');
		if (this.value == '') {
 
		 var errorMessage = 'This is a required field';
		 if ($(this).is('.conditional')) {
		    errorMessage += ', when its related checkbox is checked';
		 };

		 $('<span></span>')
		 .addClass('error-message')
		 .text(errorMessage)
		 .appendTo($listItem);
		 $listItem.addClass('warning');
 		};
        };
        if ($(this).is('.year')) {
 	           $listItem.removeClass('warning');
	           if (this.value.length != 0 && (this.value.length != 4 || isNaN(this.value) || this.value < 1900 || this.value > 2015)) {
	              var errorMessage = 'Please enter a valid 4 digit year';
	              $('<span></span>')
	              .addClass('error-message')
	              .text(errorMessage)
	              .appendTo($listItem);
	              $listItem.addClass('warning');
	           };
        };
        if ($(this).is('.amount')) {
 	   $listItem.removeClass('warning');
	   if (this.value.length != 0 && (this.value.length != 4 || isNaN(this.value) || this.value < 1900 || this.value > 2015)) {
	      var errorMessage = 'Please enter a valid 4 digit year';
	      $('<span></span>')
	      .addClass('error-message')
	      .text(errorMessage)
	      .appendTo($listItem);
	      $listItem.addClass('warning');
	   };
        };
        
        if ($(this).is('.email')) {
              if (!emailFormat.test(this.value)) {
  	     var errorMessage = ' Invalid e-mail';
  	     $('<span></span>')
  	     .addClass('error-message')
  	     .text(errorMessage)
  	     .appendTo($listItem);
  	     $listItem.addClass('warning');
             };
        };        
        
  });
   
     
  
   
});





  function loadmyapplications()
  {
  
   $('#rmyapplications').each(function(i) {
         
        
             
        $.get('/ajax/getmyapplications.php', {'uniqueid': new Date().getTime()}, function(data) {
       		 $('#rmyapplications').html(data);

       
	    });
         
  });
  
  }
  
   function loadrecentapplications()
  {
  
   $('#recentapplications').each(function(i) {
         
        
             
        $.get('/ajax/getallapplications.php', {'uniqueid': new Date().getTime()}, function(data) {
       		 $('#recentapplications').html(data);

       
	    });
         
  });
  
  }

  function loadmyapplicationdeadlines()
  {
  
   $('#myapplicationdeadlines').each(function(i) {
         
        
             
        $.get('/ajax/getmyapplicationdeadlines.php', {'uniqueid': new Date().getTime()}, function(data) {
       		 $('#myapplicationdeadlines').html(data);

       
	    });
         
  });
  
  }
  
   function loadprevnextlinks()
   {
        $('#nextprevlinks').each(function(i) {
        var Itemid = $('#Itemid').val();
     	var option = $('#option').val();
     	var invoker = $('#invoker').val();
     	var audition_id = $('#audition_id').val();
     	var publish_date = $('#publish_date').val();

	$.get('/ajax/getnextprevlink.php', {'audition_id' :audition_id, 'publish_date':publish_date, 'option' : option, 'Itemid' : Itemid, 'invoker' : invoker, 'uniqueid': new Date().getTime()}, function(data) {
		 $('#nextprevlinks').html(data);


	}, 'html');
             
    });
      
  }
  
     function loadmyauditions()
       {
       
        $('#myauditions').each(function(i) {
              
             
                  
             $.get('/ajax/getmyauditions.php', {'uniqueid': new Date().getTime()}, function(data) {
            		 $('#myauditions').html(data);
     
            
     	    });
              
       });
       
  }

  function clearValidationMessages(targetform)
  {
      $('.warning').removeClass('warning');
      $('li').removeClass('warning').find('div.error-message').remove();
      $('li').removeClass('warning').find('span.error-message').remove();
      $('div').removeClass('warning').find('div.error-message').remove();
      $('div').removeClass('warning').find('span.error-message').remove();

  }
  
  function fillUsrDateTime(source)
  
  {
  
  
  
  
  
          var date = trim($('#' + source + '_date').val());
  
          
                
  
          var timestring;
  
  
          var time = $('#' + source + '_time').val();
    
     
          if (time == '')
  
          {
  
             if (date == '') 
             {
                 $('#' + source).val('0000-00-00 00:00');
    	       return true;	 
    	   }
  
             var val = date;
  
             timestring = dparseDate(val,ALL_FORMATS,DB_DATE_FORMAT); 
             
             timestring = timestring + ' 00:00';
  
          }
  
          else
          {
          
             if (date == '') date = '00-00-0000';
  
             var val = date + ' ' + time;
  
             timestring = dparseDate(val,ALL_FORMATS,DB_TIME_FORMAT);      
  
  	}
   	
          $('#' + source).val(timestring);
  
   
   	return true;	
  
  	
  
  }

  
  
  function showicallink()
  {
	$.get('/ajax.php', {'task' : 'geticallink', 'uniqueid': new Date().getTime()}, function(data) {
		 $('#icallink').html(data);


	});
	return false;
  }
  function filterAuditions()
  {
    // get the entered filter
    
    var spacereg = /\s/g;
    
  //  var filter = $('#filter').val().replace(spacereg,"|");
  //  alert(filter);
    var filter = new RegExp($('#filter').val().replace(spacereg,"|"),"i");
    showWaitSpinner('Please Wait', $('#filter'));
    
     // filter the rows
    if (filter == '')
    {
     // show all 
     
     $('.audition').show();
    }
    else
    {
     $('.audition').hide();

     $('.audition').each(function () {
         var matchPos1 = stripHTML($(this).html()).search(filter);
         if(matchPos1 != -1)
         {
            $(this).show();
         }
         else
         {
            $(this).hide();

         }

     });
    }
        hideWaitSpinner()

    
    
  }
  
 
  function getavailableapplications()
  {
  
       $('#upcomingapppreview').html('<img class="ind" title="indicator.gif" alt="indicator.gif" src="/images/wait16trans.gif"/>');

           $.get('/ajax/getavailableapps.php', {'uniqueid': new Date().getTime()}, function(data) {
           $('#upcomingapppreview').html(data);
                   hideWaitSpinner()
            });
            
            return false;
  
  
  }
  
  
   
  function stripHTML(s)
  {
          // What a tag looks like
 
          var matchTag = /<(?:.|\s)*?>/g;
  
          // Replace the tag
  
          return s.replace(matchTag, "");
  
  };
  
     
      
  function validateattachedfiles()
  {
  
  $('.filesrequested').each(function(i) {
                
        $(this).removeClass('warning').html('');
        
        var type = $(this).attr('type');
        var question_id = $(this).attr('question_id');
        var requested = $(this).attr('requested');
      
        if (requested > 0)
        {
          
           var amountselected = 0;
           
           // get all the items with that question
           
            $('.filesrequested' + question_id).each(function(i) {
           
              // for each see if its checked - increment count for each one

              if ($(this).is(":checked")) { amountselected++; }
       
            });
            
            // count files that were already uploaded (for those editing an existing app)
            
            $('.fileuploaded' + question_id).each(function(i) {
	               
	         amountselected++; 
	           
            });
            
            // check to see if the count is greater than or equal to the number requested
            
            if (amountselected < requested)
            {
               // we have a problem - need to show warning messages
               
               if (type == 'radio')
               {
                   $(this).addClass('warning').html('A selection is required');
               }
               else
               {
                   $(this).addClass('warning').html(requested + ' item(s) are required');
               }
             
     
            }
         }

       });
  
  }


  function validateForm()
  {
 
      updateEditorFormValue();
 
      // clear warning messages
	  $('#submit-message').remove();

      $(':input.required').trigger('blur');
      
      $(':input.year').trigger('blur');
  
      $(':input.email').trigger('blur');

  
      // validateattached files
      
      validateattachedfiles();
       var numWarnings = $('.warning').length;
 
        if (numWarnings) {
           var fieldList = [];
           $('.warning label').each(function() {
              fieldList.push($(this).text());
           });
           $('<div></div>')
           .attr({'id': 'submit-message','class': 'warning'})
           .append('Please correct errors with the following ' +
           numWarnings + ' fields:<br />')
           .append('&bull; ' + fieldList.join('<br />&bull; '))
           .insertBefore('#send');
           return false;
       };
        return true;
  
  
  }
  
  function showwarning()
  {
   $('.warning').each(function(i) {
            
           
                
          alert($(this).html());
            
  });
  }
  
  function showMoreInformation(object, anchor)
  {
  
      var top = anchor.offset().top ;
    
      object.css('top',top - 25);
      object.show();
      return false;
  
  }
  
  
  function showWaitSpinner(str, object)
  {
  
     if (str == null)
     {
        str = "Please Wait...";
     }
     if (object == null)
     {
     
        var wh = (self.innerHeight) ? self.innerHeight : document.documentElement.clientHeight;
	var y = (self.pageYOffset) ? self.pageYOffset : document.documentElement.scrollTop;
	var x = (self.pageXOffset) ? self.pageXOffset : document.documentElement.scrollLeft;
	$("#waitspinner").css({top:(y+(wh/2))+'px',left:(x+365)+'px',display:'block'});
      
        $("#waitspinner").show();
        $("#waitspinner div").html(str);
     }
     else
     {
        var top = object.offset().top ;
  
       $("#waitspinner").css('top',top);
       $("#waitspinner").show();
       $("#waitspinner div").html(str);
       
     }
  
  }
  
  function clearinputfields()
  {
     $(":text").val('');
     $(":file").val('');
  }
  
  function getdetails(id, anchor) 
  {
  
    if ($('#ae' + id).html().length != 0)
    {
            $('#aer' + id).css("display", "");
            $('#abstract' + id).hide();

    }
    else
    {
            showWaitSpinner('Please Wait', $('#abstract' + id));

	    $.get('/ajax.php', {'id': id, 'anchor' : anchor,'uniqueid': new Date().getTime()}, function(data) {
		 $('#ae' + id).html(data);
                 $('#aer' + id).css("display", "");
		 $('#abstract' + id).hide();
		 hideWaitSpinner();
		 pageTracker._trackPageview('/index.php?option=com_audition&Itemid=31&task=getdetails&id=' + id );


	    });
    }
    
        
  }
  
  function hidedetails(id,anchor)
  {
      $('#aer' + id).css("display", "none");
      $('#abstract' + id).show();
      
      if (anchor != '' || anchor == '0')
      {
         window.location.hash = 'k' + anchor;
      }
  
  }
  
  function hideWaitSpinner()
  {
      $("#waitspinner").hide();
  
  }
  
  function updateEditorFormValue()
  {  
     for ( i = 0; i < parent.frames.length; ++i )
     {
  	   if ( parent.frames[i].FCK ) {
  	     parent.frames[i].FCK.UpdateLinkedField();
  	   }
     }
  }
  
  function createrecommender()
  {
     // get email
     
     var email = $('#email').val();
     var name = $('#name').val();
     var password = $('#password').val();

     $('#warning').html('');

     // check to see if it exists
     
      $.getJSON('/ajax/createrecommender.php', {'newemail':email,'newname':name, 'password':password}, function(data) {

	      $.each(data, function(entryIndex, entry) {

		     var result = entry['result'];
 		     if (result == '1') // already exists 
		     {



			 $('#warning').html('A YAP Tracker account already exists with this e-mail.');
			 hideWaitSpinner();




		       // refresh the data
		     }
		     else
		     {
		        $('#createrecommender').hide();
		        $('#recommenderconfirmation').show();


		     	$('.recommenderconfirmationname').html(entry['name']);
		        $('.recommenderconfirmationemail').html(entry['email']);

   



		     }

		});
                
               
                
    });
     
  }
  
  function validateexpcheckout(form)
  {
     var name = trim(form.name.value);
     var password = trim(form.password.value);
     
     if (name == '' || password == '')
     {
        alert('Please enter your name and the password you would like to use.');
        return false;
     }
     else
     {
        return true;
     }
  
}
  
  function setmyinterest(id, currentinterest, desiredinterest) {
  
       showWaitSpinner('Please Wait');
       
       hidedetails(id, '');
       
       $.get('/ajax.php', {'task': 'setinterest', 'interest': desiredinterest,'id': id,'previousinterest': currentinterest,'uniqueid': new Date().getTime()}, function(data) {
           var start = $('#start').val();
           $('#count').val($('#count').val()-1);
           $('#abstract' + id).hide();
           $('#interest' + id).hide();
           hidetag('audition_' + id,'span'); 
           
           hideWaitSpinner();
           if (start != undefined)
           {
           shownextaudition(start);
           }
           $('#interested' + desiredinterest).attr('checked', true);
           if (desiredinterest > 0)
	   {
	      loadmyapplicationdeadlines();
	   }

       });
       
      
  }
  
  function refreshsummarystats()
  {
    showWaitSpinner('Please Wait');

    $.get('/ajax/refreshsummarystats.php', {'uniqueid': new Date().getTime()}, function(data) {   
        hideWaitSpinner();
		window.location.href=window.location.href;
    });
    
    return false;
  
  }
  
  function showorigduedate(audition_id)
  {
    showWaitSpinner('Please Wait');

    $.get('/ajax.php', {'task': 'getorigduedate','id': audition_id,'uniqueid': new Date().getTime()}, function(data) {
           
                            hideWaitSpinner();
alert(data);
    });
  
  }
  
   function shownextaudition(start)
    {
  
      // get the information that we need from hidden fields
       var option 	= $('#option').val();
       var Itemid 	= $('#Itemid').val();
       var comp = $('#comp').val();
       var order = $('#order').val();
       var current_season = $('#current_season').val();
       var status = $('#status').val();
       var rowcount = $('#rowcount').val();
       var interest = $('#interest').val();
       var filter = $('#filter').val();       
       // get the information needed to show audition
       $.get('/ajax/getauditionrow.php', {'option': option, 'Itemid': Itemid,'comp': comp,'order': order,'current_season': current_season,'status': status,'start': start,'rowcount' : rowcount, 'interest':  interest, 'filter':filter,'uniqueid': new Date().getTime()}, function(data) {
               $('#lastauditionrow').before(data);
               updateauditionsresultcount();
               hideWaitSpinner();
            });
      
  }
  
  function updateauditionsresultcount()
  {
     var start = $('#start').val();
     var rowcount = $('#rowcount').val();
     var count = $('#count').val();
     var end = ((start + 1) * rowcount);
   
   var start = (start * rowcount + 1);
     
     if (count < end) 
     {
         end = count;
     }
     
     if (start > end)
     {
          $('.auditionresultscount').html('');
     
     }
     else
     {
          $('.auditionresultscount').html('Results ' + start + ' - ' + end + ' of ' + count);
     }
     
     var group = $('#group').val();

     if (count <= ((group - 1) * rowcount))
     {
      $('.jumpto' + group).hide();
      $('#group').val($('#group').val()-1);
     }

     
     
  
  }

  
  
  function filterauditions()
  {
      $('#start').val('0');
      showauditions();
  }
  
  function jumptopage(start)
  {
     $('#start').val(start);
     showauditions();

  }
  
  function showm4a(url, id)
  {
      $('#' + id).html('<embed width="200" autostart="1" height="30" name="plugin" src="' + url + '" type="audio/x-m4a"/>');
}

  function jumptostatus(status)
  {
     $('#start').val('0');
     $('#status').val(status);
     showauditions();

  }
  
  function jumptoorder(order)
  {
     $('#order').val(order);
     showauditions();

  }  
  
  function jumptointerest(interest)
  {
      $('#start').val('0');
      $('#interest').val(interest);
      showauditions();
  }
  
  function showauditions()
  {
     showWaitSpinner('Please Wait');

     // get the information that we need from hidden fields
     var option 	= $('#option').val();
     var Itemid 	= $('#Itemid').val();
     var comp = $('#comp').val();
     var order = $('#order').val();
     var current_season = $('#current_season').val();
     var status = $('#status').val();
     var rowcount = $('#rowcount').val();
     var start = $('#start').val();
     var interest = $('#interest').val();
     var filter = $('#filter').val();
  
    // get the information needed to show audition
     $.get('/ajax/getauditions.php', {'option': option, 'Itemid': Itemid,'comp': comp,'order': order,'current_season': current_season,'status': status,'start': start,'interest': interest,'filter': filter, 'rowcount': rowcount,'uniqueid': new Date().getTime()}, function(data) {
             $('#auditions').html(data);
   
              pageTracker._trackPageview('/index.php?task=showauditions&option=' + option + '&Itemid=' + Itemid + '&comp=' + comp + '&order=' +  order + '&current_season=' + current_season + '&status=' + status + '&start=' + start + '&interest=' +  interest + '&filter=' + filter +  '&rowcount=' + rowcount );
          });
    
  }


function populatecitydropdown(country, state, defaultcity)
  {
 
    
       var city = '<option value="">-- Select City --</option>';
    
    
       $.ajax({
  	  url: "/ajax/getauditioncity.php",
  	  dataType: 'json',
  	  data: "country=" + country + "&state=" + state,

            success: function(data) {
                if (data.error) { alert(data.error); }
   	      for ( i = 0; i < data.length; i++)
  	      { 
  	           if (data[i] != '')
  	           {
                    city  += '  <option '+(defaultcity == data[i] ? 'selected' : '') + ' value="' + data[i] + '">' + data[i] + '</option>';
                   }
                
  	      }     
               $("#city").html(city);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
    
            console.log('err status - '+textStatus);
            console.log('err thrown - '+errorThrown);
            }
       }); 
  
       
    
  }
  
  function populatestatedropdown(country, defaultstate, defaultcity)
  {
    
 
 
       var state = '<option value="">-- Select State --</option>';
    
    
       $.ajax({
  	  url: "/ajax/getauditionstates.php",
  	  dataType: 'json',
  	  data: "country=" + country,

            success: function(data) {
                if (data.error) { alert(data.error); }
   	      for ( i = 0; i < data.length; i++)
  	      { 
  	           if (data[i] != '')
  	           {
                    state  += '  <option '+(defaultstate == data[i] ? 'selected' : '')+' value="' + data[i] + '">' + data[i] + '</option>';
                   }
                
  	      }     
               $("#state").html(state);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
    
            console.log('err status - '+textStatus);
            console.log('err thrown - '+errorThrown);
            }
       }); 

     $('#state').change(function() {
          populatecitydropdown($('#acountry').val(), $('#state').val(), defaultcity);
     });       
  
       
    
  }
	
	
  function populatecountrydropdown(defaultcountry,defaultstate,defaultcity)
  {
  
  
     var country = '<option value="">-- Select Country --</option>';


     $.ajax({
	  url: "/ajax/getcountries.php",
	  dataType: 'json',
          success: function(data) {
              if (data.error) { alert(data.error); }
              
 	      for ( i = 0; i < data.length; i++)
	      {
	      
                  country  += '  <option ' + (defaultcountry == data[i] ? 'selected' : '') +' value="' + data[i] + '">' + data[i] + '</option>';
              
	      }               
              $("#acountry").html(country);
          },
          error: function (XMLHttpRequest, textStatus, errorThrown) {
  
          console.log('err status - '+textStatus);
          console.log('err thrown - '+errorThrown);
          }
     }); 

     $('#acountry').change(function() {
         populatestatedropdown($(this).val(), defaultstate, defaultcity);
         populatecitydropdown($(this).val(), $('#state').val(), defaultcity);
     });
  
  }
function createguest()
{
     if (!validateForm())
     {
     
         return false;
     }
     
     showWaitSpinner('Please Wait', null);

     // get email
     
     var email = $('#email').val();
     var name = $('#name').val();
     var password = $('#password').val();

     $('#warningmessage').html('');

     // check to see if it exists
     
      $.getJSON('/ajax/createguest.php', {'newemail':email,'newname':name, 'password':password}, function(data) {

	      $.each(data, function(entryIndex, entry) {

		     var result = entry['result'];
 		     if (result == '1') // already exists 
		     {



			 $('#warningmessage').html('A YAP Tracker account already exists with this e-mail.');

		       // refresh the data
		     }
		     else if (result == '2') // blocked account
		     {
		 	 $('#warningmessage').html('An account with this e-mail already exists with YAP Tracker but has expired. To renew this account, please click <a href="/renew">here</a>.');
    
		     }
		     else
		     {
		        $('#createguest').hide();
		        $('#guestconfirmation').show();


		     	$('.guestconfirmationname').html(entry['name']);
		        $('.guestconfirmationemail').html(entry['email']);
		     }
		     hideWaitSpinner();


		});
                
               
                
    });
     
  }
  
  function flashbackground(objref)
  {
  
  var originalBG = $(objref).css("background-color");
  var fadeColor = "#FFFFCC"; 
  $(objref).animate({backgroundColor:fadeColor}, 250).animate({backgroundColor:originalBG},250).animate({backgroundColor:fadeColor}, 250).animate({backgroundColor:fadeColor}, 250).animate({backgroundColor:originalBG},250).animate({backgroundColor:fadeColor}, 250);
  $(objref).css('backgroundColor', fadeColor);
}
  
  function showoverlay()
  {
      $("body").append('<div id="overlay_modal" class="overlay_alphacube" style="position: absolute; top: 0pt; left: 0pt; z-index: 1; width: 3000px; height: 10000px; opacity: 0.5; filter: alpha(opacity=50);"/>');
 
  }
  
  function showelementoverlay(obj)
  {
        if (!obj.length)
        { 
          showoverlay();
          return;
        }
        // get the width of the page
        
        var height = $(document).height();
         
        // get the height of the page
        
        var width = obj.width();
         
        $("body").append('<div id="overlay_modal" class="overlay_alphacube" style="position: absolute; top: 0pt; left: 0pt; z-index: 1; width: ' + width+'px; height: ' + height+'px; opacity: 0.5; filter: alpha(opacity=50);"/>');
  }
  
  function hideoverlay()
  {
      $('#overlay_modal').remove();
  }
  
  function closedialog()
  {
  
       	  $('#example').dialog('close');
      	    	  $('#example').html('');
  
      	  hideoverlay();
     return false;
  }


function startapplication(id)
{
location.href = "http://www.yaptracker.com/applications/" + id;

}
function centerdialog(x)
{
//get viewport's width and height
vpWidth=self.innerWidth;
vpHeight=self.innerHeight;

//get dialog's width and height
dialogWidth=x.offsetWidth;
dialogHeight=x.offsetHeight;

//calculate position
dialogTop = (vpHeight/2) - (dialogHeight/2);
dialogLeft = (vpWidth/2) - (dialogWidth/2);


//Position the Dialog
x.style.top =dialogTop+"px";
x.style.left =dialogLeft+"px";

a = x.style.display="block";

}


function updateselectstates(country,states)
{
     var ccountry = $('#country').val();
     alert(ccountry);
   
     
	 var state =  document.getElementById('state');
	 var cstate = 'xxx';
	 state.options.length=0;

	 state.options[0] = new Option("-- Select State --", "");

     if (ccountry == '')
     {
        updatecities(state);
        return;
     }



	 for (var i = 0; i < locations.length; i++)
	 {

	   if (locations[i][0] == ccountry)
	   {
         if (locations[i][1] != '' && cstate != locations[i][1] )
    	     state.options[state.options.length] = new Option(locations[i][1],locations[i][1]);
    	 cstate = locations[i][1];
	   }
	 }
     updatecities(state, ccountry);

	}

