//jQuery
$(document).ready(function(){

	$('.sub_nav').hover(function(){
	var temp=$(this).attr('src')
	temp=temp.replace('.gif', '-over.gif');
	$(this).attr('src', temp);
	}, 
	function() {
	var temp=$(this).attr('src')
	temp=temp.replace('-over.gif', '.gif');
	$(this).attr('src', temp);
	});
	
	$('#home_users_nav2').hover(function(){
	var temp=$(this).attr('src')
	temp=temp.replace('.jpg', '-over.jpg');
	$(this).attr('src', temp);
	//$('#home_users_title').attr('src', '/images/commercial_contractor_title.gif');
	//$('#home_users_text').attr('src', '/images/com_contractor_home_text.gif');
	}, 
	function() {
	var temp=$(this).attr('src')
	temp=temp.replace('-over.jpg', '.jpg');
	$(this).attr('src', temp);
	//$('#home_users_title').attr('src', '/images/user_title.gif');
	//$('#home_users_text').attr('src', '/images/spacer.gif');
	});
	
	$('#home_users_nav1').hover(function(){
	var temp=$(this).attr('src')
	temp=temp.replace('.jpg', '-over.jpg');
	$(this).attr('src', temp);
	//$('#home_users_title').attr('src', '/images/architect_title.gif');
	//$('#home_users_text').attr('src', '/images/architects_home_text.gif');
	}, 
	function() {
	var temp=$(this).attr('src')
	temp=temp.replace('-over.jpg', '.jpg');
	$(this).attr('src', temp);
	//$('#home_users_title').attr('src', '/images/user_title.gif');
	//$('#home_users_text').attr('src', '/images/spacer.gif');
	});
	
	$('#home_users_nav3').hover(function(){
	var temp=$(this).attr('src')
	temp=temp.replace('.jpg', '-over.jpg');
	$(this).attr('src', temp);
	//$('#home_users_title').attr('src', '/images/engineer_title.gif');
	//$('#home_users_text').attr('src', '/images/engineers_home_text.gif');
	}, 
	function() {
	var temp=$(this).attr('src')
	temp=temp.replace('-over.jpg', '.jpg');
	$(this).attr('src', temp);
	//$('#home_users_title').attr('src', '/images/user_title.gif');
	//$('#home_users_text').attr('src', '/images/spacer.gif');
	});
	
	$('#home_users_nav4').hover(function(){
	var temp=$(this).attr('src')
	temp=temp.replace('.jpg', '-over.jpg');
	$(this).attr('src', temp);
	//$('#home_users_title').attr('src', '/images/building_owner_title.gif');
	//$('#home_users_text').attr('src', '/images/building_owner_home_text.gif');
	}, 
	function() {
	var temp=$(this).attr('src')
	temp=temp.replace('-over.jpg', '.jpg');
	$(this).attr('src', temp);
	//$('#home_users_title').attr('src', '/images/user_title.gif');
	//$('#home_users_text').attr('src', '/images/spacer.gif');
	});
	
	$('#map_home').hover(function(){
	var temp=$(this).attr('src')
	temp=temp.replace('.gif', '-over.gif');
	$(this).attr('src', temp);
	}, 
	function() {
	var temp=$(this).attr('src')
	temp=temp.replace('-over.gif', '.gif');
	$(this).attr('src', temp);
	});
	
	
//$("#rep_search").click(function(){
$("#rep_search_form").submit(function(){
var zip=$("input#zip").val();
if (zip!="") {
var dataString = 'zip=' + zip;
//alert (dataString);

$.ajax({
type: "GET",
url: "/findarep/rep_data.aspx",
data: dataString,
dataType: "xml",
success: function(xml) {
var return_text
$(xml).find('rep_detail').each(function(){
return_text = '<table><tr><td> </td><td bgcolor="#e1dbd3"><div class="rep_citystate">' + $(this).attr('city') + ', ' + $(this).attr('state') + '</div></td></tr>';
//return_text = return_text + $(this).attr('role') + '<br />';
return_text = return_text + '<tr><td><div class="rep_finder_image" style="padding-bottom: 5px;">';
if ($(this).attr('image') != '') { 	return_text = return_text + '<img src="/images/reps/' + $(this).attr('image') + '" />';	}
return_text = return_text + '</div></td><td bgcolor="#e1dbd3"><div class="rep_data">';
return_text = return_text + '<b>' + $(this).attr('name') + '</b><br />';
if ($(this).attr('phone') != '') { 	return_text = return_text + 'Phone: ' + $(this).attr('phone') + '<br />';	}
if ($(this).attr('cell') != '') { return_text = return_text + 'Cell: ' + $(this).attr('cell') + '<br />'; }
if ($(this).attr('fax') != '') { return_text = return_text + 'Fax: ' + $(this).attr('fax') + '<br />'; }
if ($(this).attr('email') != '') { return_text = return_text + '' + $(this).attr('email') + '<br />'; }
return_text = return_text + '</div></td></tr>';
// var name_text = $(this).find('name').text() this would find any nested tags
}); //close each(
$(xml).find('spec_rep_detail').each(function(){
if ($(this).attr('name') != '') {
//return_text = return_text + '<br />' + $(this).attr('role') + '<br />';
return_text = return_text + '<tr><td><div class="rep_finder_image">';
if ($(this).attr('image') != '') { 	return_text = return_text + '<img src="/images/reps/' + $(this).attr('image') + '" />';	}
return_text = return_text + '</div></td><td bgcolor="#e1dbd3"><div class="rep_data">';
return_text = return_text + '<div>Specifier Representative</div>';
return_text = return_text + '<b>' + $(this).attr('name') + '</b><br />';
if ($(this).attr('phone') != '') { 	return_text = return_text + 'Phone: ' + $(this).attr('phone') + '<br />';	}
if ($(this).attr('cell') != '') { return_text = return_text + 'Cell: ' + $(this).attr('cell') + '<br />'; }
if ($(this).attr('fax') != '') { return_text = return_text + 'Fax: ' + $(this).attr('fax') + '<br />'; }
if ($(this).attr('email') != '') { return_text = return_text + '' + $(this).attr('email') + '<br />'; }
return_text = return_text + '</div></td></tr>';
}																						 
}); //close each(
$(xml).find('parent_rep_detail').each(function(){
return_text = return_text + '<tr><td>';
//if ($(this).attr('image') != '') { 	return_text = return_text + '<img src=/images/reps/' + $(this).attr('image') + ' />';	}
return_text = return_text + '</td><td bgcolor="#e1dbd3"><div class="rep_data">';		 
return_text = return_text + '<div>' + $(this).attr('role') + '</div>';
return_text = return_text + '<b>' + $(this).attr('name') + '</b><br />';
if ($(this).attr('phone') != '') { 	return_text = return_text + 'Phone: ' + $(this).attr('phone') + '<br />';	}
else if ($(this).attr('cell') != '') { return_text = return_text + 'Cell: ' + $(this).attr('cell') + '<br />'; }
//if ($(this).attr('fax') != '') { return_text = return_text + 'Fax: ' + $(this).attr('fax') + '<br />'; }
if ($(this).attr('email') != '') { return_text = return_text + '' + $(this).attr('email') + '<br />'; }
return_text = return_text + '</div></td></tr></table>';
}); //close each(

$("input#zip").val("");
$("#rep_detail").html(return_text);
}
}); //close $.ajax

}
return false;
});
	


//fix for change() event and ie
$(function () {
    if ($.browser.msie) {
        $('input:checkbox').click(function () {
            this.blur();
            this.focus();
        });
    }
});
	

$('.cad_check_box').change(function() {
var v_id=$(this).val();
var dataString = 'id=' + v_id; // + '&phone=' + phone;   
//alert(v_id); 

$.ajax({   
  type: "GET",   
  url: "/resources/downloads_update.aspx",   
  data: dataString,  
  success: function(xml) { 
	$(xml).find('message').each(function(){
	var msg = $(this).attr('id');
if (msg=='failed') {

}else if (msg=='added') {
		var v_int = parseInt($('#item_count').text());
$('#item_count').text(v_int + 1);
}else{
var v_int = parseInt($('#item_count').text());
$('#item_count').text(v_int - 1);
}
});
}   
});

});


		
}); // end ready

