var PageNum = 10;

function search_coupon(){
	  var objSave = document.getElementById('coupon_only');

	  objSave.value = "Y";
	  document.getElementById('form_search').submit();	

}

 function show_sibling(event)
 {

  	  var theEvent = event ? event : window.event;
	  var objSelect = theEvent.srcElement ? theEvent.srcElement : theEvent.target ;
	  var	objParent	= objSelect.parentElement ? objSelect.parentElement :objSelect.parentNode;	   
	  var DivRef = document.getElementById('actcontent');
	  var IfrRef = document.getElementById('DivIframe');

	if(theEvent.srcElement !=null){
		  var BodyRect = objParent.getBoundingClientRect();
		 
		  if(DivRef.style.display=="none"){
				DivRef.style.top = parseInt(BodyRect.top) +20 + "px";
				DivRef.style.left =parseInt(parseInt(BodyRect.left) - 5) + "px";
				DivRef.style.display = "block";
				IfrRef.style.width = DivRef.offsetWidth;
				IfrRef.style.height = DivRef.offsetHeight;
				IfrRef.style.top = DivRef.style.top;
				IfrRef.style.left =  DivRef.style.left;
				IfrRef.style.zIndex = DivRef.style.zIndex - 1;
				IfrRef.style.display = "block";
		  }
		  else{
				DivRef.style.display = "none";
				IfrRef.style.display = "none";
		  }		
	}
		
	else{
	/*	 var BodyRect = document.getBoxObjectFor(document.getElementById("actbox"));
		
		 if(DivRef.style.display=="none"){
				DivRef.style.top = parseInt(parseInt(BodyRect.top)  -100) + "px";
				DivRef.style.left =parseInt(parseInt(BodyRect.left) - 5) + "px";
				DivRef.style.display = "block";
				IfrRef.style.width = DivRef.offsetWidth;
				IfrRef.style.height = DivRef.offsetHeight;
				IfrRef.style.top = DivRef.style.top;
				IfrRef.style.left =  DivRef.style.left;
				IfrRef.style.zIndex = DivRef.style.zIndex - 1;
				IfrRef.style.display = "block";

				alert(BodyRect.top);
		  }
		  else{
				DivRef.style.display = "none";
				IfrRef.style.display = "none";
		  }		*/
	}

 }

function change_category(value_category_id){

  	 var moveUrl = "local_list.html";
	 var objSelect = 	document.getElementById("location_id") ;
	 var value_location_id = objSelect.options[objSelect.selectedIndex].value;

	moveUrl = moveUrl + "?category_id=" + value_category_id + "&location_id=" + value_location_id;

	location.replace(moveUrl);
}

function location_category(value_location_id){

  	 var moveUrl = "local_list.html";

	 var value_category_id = document.getElementById("category_id").value;
	 var value_searchstring = document.getElementById("searchstring").value;

	moveUrl = moveUrl + "?category_id=" + value_category_id + "&location_id=" + value_location_id + "&searchstring=" + value_searchstring;

	location.replace(moveUrl);
}

function chage_order(strType){
	document.getElementById('order_type').value = strType;
	document.getElementById('form_search').submit();	
}

function change_list(event,addQuery){

	var programExecDir = "./";
	var way = "GET";
	var mode = "text";
	var sync_type = true;//true (async) , false (sync)
	var queryString = "";
	var i= 0;
	var theEvent = event ? event : window.event;

	PagingDiv = document.getElementById('local_paging');

	while(1){
		if(PagingDiv.childNodes[i]==null) break;
		if(PagingDiv.childNodes[i].id=="pastPage" || PagingDiv.childNodes[i].id=="nextPage"){ i++; continue};
		if(PagingDiv.childNodes[i].nodeType==3){ i++; continue};

		if(PagingDiv.childNodes[i].className !="display_none")
			PagingDiv.childNodes[i].className = "paging";
		i++;
	}

	var objSelect = theEvent.srcElement ? theEvent.srcElement : theEvent.target ;

	if(objSelect.id=="nextPage"){
		selectNum = parseInt(objSelect.tabIndex);
	}
	else if(objSelect.id=="pastPage"){
		selectNum = parseInt(objSelect.tabIndex);
	}
	else{
		selectNum = parseInt(objSelect.innerHTML);
		objSelect.className = "page_selected";
	}

	addQuery += "&start=" +  PageNum * (selectNum-1);

	queryString = "?mode=show_list&" + addQuery;
	var rel = "ajax_process.html"+queryString;

	if( navigator.appName.indexOf("Microsoft") > -1 ){         // ¸¶ÀÌÅ©·Î¼ÒÇÁÆ® ÀÍ½ºÇÃ·Î·¯ÀÎÁö È®ÀÎ
			if( navigator.appVersion.indexOf("MSIE 6") > -1){         // ÀÍ½ºÇÃ·Î·¯ÀÌ¸é ¹öÀü 6ÀÎÁö È®ÀÎ
				var selAttachfunction  = "newDataAttach";
			}else if(navigator.appVersion.indexOf("MSIE 7") > -1){  // ÀÍ½º ÇÃ·Î·¯ÀÌ¸é ¹öÀü 7ÀÎÁö È®ÀÎ
			var selAttachfunction  = "newDataAttach";
			}
		}
	else{                                                                               // ÀÍ½ºÇÃ·Î·¯°¡ ¾Æ´Ò °æ¿ì
		  var selAttachfunction  = "newDataAttach_firefox";
	}

	var protoTypeAjax =new Ajax.Request(rel,   {
				method:'get', 
				onSuccess: function(transport){       
				var response = transport.responseText || "no response text";      
				
					if( navigator.appName.indexOf("Microsoft") > -1 ){         // ¸¶ÀÌÅ©·Î¼ÒÇÁÆ® ÀÍ½ºÇÃ·Î·¯ÀÎÁö È®ÀÎ
							if( navigator.appVersion.indexOf("MSIE 6") > -1){         // ÀÍ½ºÇÃ·Î·¯ÀÌ¸é ¹öÀü 6ÀÎÁö È®ÀÎ
								newDataAttach(response);
							}else if(navigator.appVersion.indexOf("MSIE 7") > -1){  // ÀÍ½º ÇÃ·Î·¯ÀÌ¸é ¹öÀü 7ÀÎÁö È®ÀÎ
								newDataAttach(response);
							}
						}
					else{                                                                               // ÀÍ½ºÇÃ·Î·¯°¡ ¾Æ´Ò °æ¿ì
						 newDataAttach_firefox(response);
					}

			},    
			onFailure: function(){ alert('Ajax wrong...') } 
			}
	); 

}

function newDataAttach(ajaxResultStr){
	ShowDiv = document.getElementById('DIV_LIST');

	if(ajaxResultStr=="none" || ajaxResultStr==null ) return false;

	var mapObj = eval( '(' + ajaxResultStr + ')' );

	midLat = mapObj["mapProperty"].midLat;
	midLng= mapObj["mapProperty"].midLng;
	mapSize = mapObj["mapProperty"].mapSize;

	Mapdata = null;
	Mapdata = [];
	for(i=0; i< 10 ; i++){
		ShowDiv.childNodes[i].className = "display_none";
	}

	for(i=0; i< mapObj["mapData"].length; i++){
		var SaveObj = eval(mapObj["mapData"][i]);
		Mapdata[i] = new Array();
		Mapdata[i][0] = SaveObj["latitude"];
		Mapdata[i][1] = SaveObj["longitude"];
		Mapdata[i][2] = SaveObj["name"];
		Mapdata[i][3] = SaveObj["phone"];

		ShowDiv.childNodes[i].childNodes[0].className= "list_icon" + (i+1);
		ShowDiv.childNodes[i].childNodes[1].innerHTML ="<a href=\"local_detail.html?yellow_id="+SaveObj["yellow_id"]+"\">"
		+ SaveObj["name"];

		if(SaveObj["coupon_use"]=="Y")
			ShowDiv.childNodes[i].childNodes[3].className ="coupon";
		else
			ShowDiv.childNodes[i].childNodes[3].className ="nocoupon";

		ShowDiv.childNodes[i].childNodes[2].innerHTML =SaveObj["ename"];		
		ShowDiv.childNodes[i].childNodes[4].innerHTML = SaveObj["phone"];
		ShowDiv.childNodes[i].childNodes[5].innerHTML = SaveObj["address"] +", " + SaveObj["city"]+", " + SaveObj["state"]+" " + SaveObj["zip"];

		if(parseInt(SaveObj["name_count"]) > 30 && SaveObj["ename"] !=''){
			ShowDiv.childNodes[i].childNodes[1].className = "name2";
			ShowDiv.childNodes[i].childNodes[2].className = "ename2";
		}else{
			ShowDiv.childNodes[i].childNodes[1].className = "name";
			ShowDiv.childNodes[i].childNodes[2].className = "ename";
		}

		ShowDiv.childNodes[i].className = "storelist";
	}

	nextStart = document.getElementById('nextPage').tabIndex;
	pastStart = document.getElementById('pastPage').tabIndex;

	if(mapObj["pageVal"].method == "past"){

		document.getElementById('nextPage').tabIndex = parseInt(nextStart) - PageNum;
		document.getElementById('pastPage').tabIndex = parseInt(pastStart) - PageNum;

		if(parseInt(mapObj["pageVal"].page) -  PageNum > 1){
				PagingDiv.childNodes[0].className = "paging_nounder";
		}
		else{
			PagingDiv.childNodes[0].className = "display_none";
			PagingDiv.childNodes[11].className = "paging_nounder";
		}

		for(i=1; i< 11; i++){
			nowSelectNum = parseInt(PagingDiv.childNodes[i].innerHTML);
			PagingDiv.childNodes[i].innerHTML = (nowSelectNum - PageNum);
			PagingDiv.childNodes[i].className = "paging";
		}

		PagingDiv.childNodes[10].className = "page_selected";
		PagingDiv.childNodes[11].className = "paging_nounder";
	}

	if(mapObj["pageVal"].method == "next"){

		document.getElementById('pastPage').tabIndex = parseInt(pastStart) + PageNum;
		document.getElementById('nextPage').tabIndex = parseInt(nextStart) + PageNum;

		if(parseInt(mapObj["pageVal"].page) +  PageNum <= mapObj["pageVal"].totalpage){
				pageCount =10;
				PagingDiv.childNodes[0].className = "paging_nounder";
		}
		else{
			pageCount =  parseInt(mapObj["pageVal"].totalpage) - parseInt(mapObj["pageVal"].page);
			PagingDiv.childNodes[0].className = "paging_nounder";
			PagingDiv.childNodes[11].className = "display_none";
		}

		for(i=1; i< 11; i++){
			nowSelectNum = parseInt(PagingDiv.childNodes[i].innerHTML);
			PagingDiv.childNodes[i].innerHTML = (nowSelectNum + PageNum);
			PagingDiv.childNodes[i].className = "display_none";
		}
		for(i=1; i< pageCount+1; i++){
			PagingDiv.childNodes[i].className = "paging";
		}

		PagingDiv.childNodes[1].className = "page_selected";
	}

     setMarkIcon();
}


function newDataAttach_firefox(ajaxResultStr){
	ShowDiv = document.getElementById('DIV_LIST');

	if(ajaxResultStr=="none" || ajaxResultStr==null ) return false;
	var mapObj = eval( '(' + ajaxResultStr + ')' );

	midLat = mapObj["mapProperty"].midLat;
	midLng= mapObj["mapProperty"].midLng;
	mapSize = mapObj["mapProperty"].mapSize;

	Mapdata = null;
	Mapdata = [];

	for(i=0; i<ShowDiv.childNodes.length; i++){
		if(ShowDiv.childNodes[i].nodeName=="UL") ShowDiv.childNodes[i].className = "display_none";
	}
	
	var nodeIndex = 0;

	for(i=0; i<ShowDiv.childNodes.length; i++){

		if(ShowDiv.childNodes[i].nodeName=="UL") {

			if(nodeIndex > mapObj["mapData"].length)  break;

			var SaveObj = eval(mapObj["mapData"][nodeIndex]);
			Mapdata[nodeIndex] = new Array();
			Mapdata[nodeIndex][0] = SaveObj["latitude"];
			Mapdata[nodeIndex][1] = SaveObj["longitude"];
			Mapdata[nodeIndex][2] = SaveObj["name"];
			Mapdata[nodeIndex][3] = SaveObj["phone"];

		ShowDiv.childNodes[i].childNodes[3].innerHTML ="<a href=\"local_detail.html?yellow_id="+SaveObj["yellow_id"]+"\">"
		+ SaveObj["name"];

		ShowDiv.childNodes[i].childNodes[5].innerHTML = SaveObj["ename"];		

		if(SaveObj["coupon_use"]=="Y")
			ShowDiv.childNodes[i].childNodes[7].className ="coupon";
		else
			ShowDiv.childNodes[i].childNodes[7].className ="nocoupon";

		ShowDiv.childNodes[i].childNodes[9].innerHTML = SaveObj["phone"];
		ShowDiv.childNodes[i].childNodes[11].innerHTML = SaveObj["address"] +", " + SaveObj["city"]+", " + SaveObj["state"]+" " + SaveObj["zip"];

		if(parseInt(SaveObj["name_count"]) > 30 && SaveObj["ename"] !=''){
			ShowDiv.childNodes[i].childNodes[3].className = "name2";
			ShowDiv.childNodes[i].childNodes[5].className = "ename2";
		}else{
			ShowDiv.childNodes[i].childNodes[3].className = "name";
			ShowDiv.childNodes[i].childNodes[5].className = "ename";
		}

		ShowDiv.childNodes[i].className = "paging";
		nodeIndex = nodeIndex +1;
		}


  }
	obj_nextStart = document.getElementById('nextPage');
	obj_pastStart = document.getElementById('pastPage');

	nextStart = obj_nextStart.tabIndex;
	pastStart = obj_pastStart.tabIndex;

	if(mapObj["pageVal"].method == "past"){
		obj_nextStart.tabIndex = parseInt(nextStart) - PageNum;
		obj_pastStart.tabIndex = parseInt(pastStart) - PageNum;

		if(parseInt(mapObj["pageVal"].page) -  PageNum > 1){
				obj_pastStart.className = "paging_nounder";
		}
		else{
			obj_pastStart.className = "display_none";
			obj_nextStart.className = "paging_nounder";
		}

		nodeIndex = 0;
		for(i=2; i<PagingDiv.childNodes.length-2; i++){

			if(PagingDiv.childNodes[i].nodeName=="SPAN") {
				nowSelectNum = parseInt(PagingDiv.childNodes[i].innerHTML);
				PagingDiv.childNodes[i].innerHTML = (nowSelectNum - PageNum);
				PagingDiv.childNodes[i].className = "paging";
			}
		}

		PagingDiv.childNodes[11].className = "page_selected";
		PagingDiv.childNodes[12].className = "paging_nounder";
	}

	if(mapObj["pageVal"].method == "next"){

		obj_pastStart.tabIndex = parseInt(pastStart) + PageNum;
		obj_nextStart.tabIndex = parseInt(nextStart) + PageNum;

		if(parseInt(mapObj["pageVal"].page) +  PageNum <= mapObj["pageVal"].totalpage){
				pageCount =10;
				obj_pastStart.className = "paging_nounder";
		}
		else{
			pageCount =  parseInt(mapObj["pageVal"].totalpage) - parseInt(mapObj["pageVal"].page);
			obj_pastStart.className = "paging_nounder";
			obj_nextStart.className = "display_none";
		}

		nowPage = 1;

		for(i=2; i<PagingDiv.childNodes.length-2; i++){

			if(PagingDiv.childNodes[i].nodeName=="SPAN") {
				nowSelectNum = parseInt(PagingDiv.childNodes[i].innerHTML);
				PagingDiv.childNodes[i].innerHTML = (nowSelectNum + PageNum);
				
				if(nowPage<=pageCount)
					PagingDiv.childNodes[i].className = "paging";
				else{
					PagingDiv.childNodes[i].className = "display_none";
				}
				nowPage++;
			}
		}

		PagingDiv.childNodes[2].className = "page_selected";
	}

     setMarkIcon();
}

function validForm_comment(){

	if(!joinEtc_chk("name","ÀÌ¸§")) return false;
	if(!joinEtc_chk("password","ºñ¹Ð¹øÈ£")) return false;
	if(!joinTextarea_chk("content","³»¿ë")) return false;

	return true;
}