// CALENDAR

$(function() {
		var dates = $( "#from, #to" ).datepicker({
			defaultDate: "+1w",
			changeMonth: true,
			buttonImage: "/MAJ2/js/calendar.gif",
			buttonImageOnly: false,
			numberOfMonths: 1,
			onSelect: function( selectedDate ) {
				var option = this.id == "from" ? "minDate" : "maxDate",
					instance = $( this ).data( "datepicker" );
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings );
				dates.not( this ).datepicker( "option", option, date );
			}
		});
	});







// FORM VALIDATE
$(document).ready(function() {
	$("#form1").validate();
});





// CLOSE DIV
$(document).ready(function(){

$(".divClass .deleteDiv").click(function(){
$(this).parents(".divClass").animate({ opacity: 'hide' }, "slow");
});

});






// REFRESH PAGE ONCLICK

$(document).ready(function() {
            $('#Button1').click(function() {
                location.reload();
            });
			 $('#Button2').click(function() {
                location.reload();
            });
        }); 






// TELEPHONE
function formatTelNo (telNo)
{
    
    if (telNo.value == "") return;

    

    var phone = new String (telNo.value);
    
    phone = phone.substring(0,14);

   
    if (phone.match (".[0-9]{3}.[0-9]{3}-[0-9]{4}") == null)
    {
        
        if (phone.match (".[0-9]{2}.[0-9]{3}-[0-9]{4}|" + ".[0-9].[0-9]{3}-[0-9]{4}|" +
            ".[0-9]{3}.[0-9]{2}-[0-9]{4}|" + ".[0-9]{3}.[0-9]-[0-9]{4}") == null)
        {
            
            var phoneNumeric = phoneChar = "", i;
           
            for (i=0;i<phone.length;i++)
            {
               
                phoneChar = phone.substr (i,1);
    
                
                if (!isNaN (phoneChar) && (phoneChar != " ")) phoneNumeric = phoneNumeric + phoneChar;
            }
    
            phone = "";
            
            for (i=0;i<phoneNumeric.length;i++)
            {
                
                if (i == 0) phone = phone + "(";
               
                if (i == 3) phone = phone + ") ";
              
                if (i == 6) phone = phone + "-";
              
                phone = phone + phoneNumeric.substr (i,1)
            }
        }
    }
    else
    { 
       
        phone = "(" + phone.substring (1,4) + ") " + phone.substring (5,8) + "-" + phone.substring(9,13); 
    }
   
    if (phone != telNo.value) telNo.value = phone;
}

     
function checkTelNo (telNo)
{
    if (telNo.value == "") return;
    if (telNo.value.match (".[0-9]{3}.[0-9]{3}-[0-9]{4}") == null)
    {
        if (telNo.value.match ("[0-9]{10}") != null)
            formatTelNo (telNo)              
    }
}


function checkEnterForFindListing(e){ 
    var characterCode;
    
    if(e && e.which){ 
        e = e;
        characterCode = e.which ;
    }
    else{
        e = event;
        characterCode = e.keyCode; 
    }
    
    if(characterCode == 13){ //13 = the code for pressing ENTER 				
        document.forms[getNetuiTagName("findListingForm")].submit();
        return false; 
    }
    else{
        return true ;
    }

}





// OPEN BLANK WINDOW BASED UPON RELATIONS 
$(document).ready(function() {
    $('a[rel="external"]').click( function() {
        window.open( $(this).attr('href'),'MyNewWindow','width=650,height=500,left=25,top=25,scrollbars=yes');
        return false;
    });
	
	
	$('a[rel="openit"]').click( function() {
        window.open( $(this).attr('href'),'MyNewWindow','width=1024,height=800,left=25,top=25,toolbar=1,location=1,scrollbars=1,resizable=1');
        return false;
    });
	
	
	


});
