/*
function store_pref(pref_code){
    $.pref_code=pref_code;
    $.ajax({
        url:'/xml_out/memberstore.xml',
        type:'get',
        dataType:'xml',
        timeout:35000,
        success:write_store_pref_rows
    });
	
}

function write_store_pref_rows(xml,status){
    if(status!='success')return;
    $.store_data=[];
    $(xml).find('memberStore').each(write_store_pref_row);
	
	setMembersNewIcon();
	
    show_gmap();
}

function write_store_pref_row(){
    if(($.pref_code!=undefined)&&($.pref_code!=$(this).find('prefCode').text()))return;

    var storeName=$(this).find('storeName').text();
    var modelName=$(this).find('modelName').text();
    var zip=$(this).find('zip').text();
    var address=$(this).find('address').text();
    var tel1=$(this).find('tel1').text();
    var tel2=$(this).find('tel2').text();
    var pictAddress=$(this).find('pictAddress').text();
	var pictAddress2=$(this).find('pictAddress2').text();
    var webAddress1=$(this).find('webAddress1').text();
    var webAddress2=$(this).find('webAddress2').text();
    var webAddress3=$(this).find('webAddress3').text();
    var detailAddress='/modelhouse/'+$(this).find('detailAddress').text();
    var latitude=$(this).find('latitude').text();
    var longitude=$(this).find('longitude').text();

    var hasModelhouseLink=$(this).find('hasModelhouseLink').text();
    var hasStuffLink=$(this).find('hasStuffLink').text();
    var hasBuildingLink=$(this).find('hasBuildingLink').text();
	
    var hasEventLink=$(this).find('hasEventLink').text();
	
	if(hasEventLink=="True"){
		var nowDate = structureNowDate();
		
		var eventStart=$(this).find('hasEventLink').attr("start");
		var eventStartDate = structureDate(eventStart);
		
		var eventEnd=$(this).find('hasEventLink').attr("end");
		var eventEndDate = structureDate(eventEnd);
	
		if(! ( eventStartDate <= nowDate && eventEndDate >= nowDate) ){
			hasEventLink = "False";
		}
	}
	


    var memberStoreCode=$(this).find('modelCode').text();


    var arr={
        'storeName':storeName,
        'modelName':modelName,
        'address':address,
        'pictAddress':pictAddress2,
        'latitude':latitude,
        'longitude':longitude
        };
    $.store_data.push(arr);

	var modelImagePrefix = '';
	var modelNamePrefix = '';
	var surfix = '';

	if(webAddress1){
		modelImagePrefix = '<a href="'+webAddress1+'" rel="model_image" target="_blank">';
		modelNamePrefix = '<a href="'+webAddress1+'" rel="model_name" target="_blank">';
		surfix = '</a>';
	}

    $(
		'<tr>'+
			'<td class="photo">'+
				'<div class="photoWrapper">'+
					modelImagePrefix+'<img border="0" width="120" src="'+pictAddress2+'" alt="'+storeName+(modelName?' '+modelName:'')+'">'+surfix+
				'</div>'+
			'</td>'+
			'<td class="detail">'+
				'<p class="name">'+modelNamePrefix+storeName+(modelName?'<br>'+modelName:'')+surfix+'</p>'+
				'<p class="post">〒'+zip+'</p>'+
				'<p class="adr">'+address+'</p>'+
				'<p class="tel">TEL：'+tel1+(tel2?'<br>'+tel2:'')+'</p>'+
			'</td>'+
			'<td class="info iconMap">'+
				'<p class="icon"><a href="'+detailAddress+'" rel="icon_map"><img src="/modelhouse/images/icon_accessmap.gif" alt="地図・アクセス" /></a></p>'+
			'</td>'+
			'<td class="info iconHouse" id="iconHouse'+memberStoreCode+'"><p class="icon">'+
				(hasModelhouseLink=='True' ? '<a href="'+webAddress1+'index.html" target="_blank" rel="icon_model"><img src="/modelhouse/images/icon_house.gif" alt="モデルハウス紹介" /></a>':'<img src="/modelhouse/images/icon_no_house.gif" />')+
			'</p></td>'+
			'<td class="info iconStaff" id="iconStaff'+memberStoreCode+'"><p class="icon">'+
				(hasStuffLink=='True' ? '<a href="'+webAddress1+'staff/index.html" target="_blank" rel="icon_staff"><img src="/modelhouse/images/icon_staff.gif" alt="スタッフ紹介" /></a>':'<img src="/modelhouse/images/icon_no_staff.gif" />')+
			'</p></td>'+
			'<td class="info iconSample" id="iconSample'+memberStoreCode+'"><p class="icon">'+
				(hasBuildingLink=='True' ? '<a href="'+webAddress1+'example/index.html" target="_blank" rel="icon_example"><img src="/modelhouse/images/icon_sample.gif" alt="建築実例" /></a>':'<img src="/modelhouse/images/icon_no_sample.gif" />')+
			'</p></td>'+
			'<td class="info iconEvent" id="iconEvent'+memberStoreCode+'">'+
				(hasEventLink=='True' ? '<p class="icon new"><a href="'+webAddress1+'event/index.html" target="_blank" rel="icon_event"><img src="/modelhouse/images/icon_event.gif" alt="イベント情報" /></a>':'<p class="icon"><img src="/modelhouse/images/icon_no_event.gif" />')+
			'</p></td>'+
		'</tr>'
	).appendTo('table#store_pref');
	
}
*/


function setMembersNewIcon(){
    $.ajax({	   
        url:'/xml_out/member_new.xml',
        type:'get',
        dataType:'xml',
        timeout:35000,
        success:function(xml,status){
			
		    if(status!='success')
				return;

		   $(xml).find('member').each(function(){
					var memberStoreCode = $(this).attr('id');
					var modelhouseLink = isLinkView($(this).find('newicon modelhouse').attr("start") , $(this).find('newicon modelhouse').attr("end"));
					var stuffLink = isLinkView($(this).find('newicon staff').attr("start") , $(this).find('newicon staff').attr("end"));
					var buildingLink = isLinkView($(this).find('newicon example').attr("start") , $(this).find('newicon example').attr("end"));
					
					var target
					target= $("#iconHouse" + memberStoreCode).find(".icon");
					if(modelhouseLink)
						target.addClass("new");
						
					target= $("#iconStaff" + memberStoreCode).find(".icon");
					if(stuffLink)
						target.addClass("new");
						
					target= $("#iconSample" + memberStoreCode).find(".icon");
					if(buildingLink)
						target.addClass("new");

				}
			);
		   
		}		
    });
}


function isLinkView(start , end ){
	var nowDate = structureNowDate();
	var hasLink = false;
	if(!start)
		return hasLink;
	else if(start.match(/^[0-9]{4}\/[0-9]{2}\/[0-9]{2}$/)){
		var startDate = structureDate(start);
			
		var endDate;
		if(end){
			if(end.match(/^[0-9]{4}\/[0-9]{2}\/[0-9]{2}$/) ){
				endDate = structureDate(end);
			}else {
				endDate = structureDate(start);
				endDate.setDate(endDate.getDate() + 14);
			}
		}else {
			endDate = structureDate(start);
			endDate.setDate(endDate.getDate() + 14);
		}
		
		if(( startDate <= nowDate && endDate >= nowDate) ){
			hasLink = true;
		}
	}
	
	return hasLink;
}


function structureDate(dateString){
	return new Date(dateString);
}
function structureNowDate(){
	var now = new Date();
	var year = 0;
	if (now.getFullYear) {
		year = now.getFullYear();
	} else {
		year = now.getYear();
		if (year < 1900) year += 1900;
	}
	return new Date(year, now.getMonth(), now.getDate());
}

