function selectChange_address(control, controlToPopulate, ItemArray, GroupArray)
{
  var myEle ;
  var x ;
	var altObject = document.getElementById(''+controlToPopulate+'');
	var disObject = document.getElementById('district_id');
  // Empty the second drop down box of any choices
  for (var q=altObject.length;q>=0;q--) altObject.options[q]=null;
  if (control.name == "province_id") {
    // Empty the third drop down box of any choices
    for (var q=disObject.length;q>=0;q--) disObject.options[q] = null;
 }
  // ADD Default Choice - in case there are no values
  myEle = document.createElement("option") ;
  myEle.value = 0 ;
  myEle.text = "-- --เลือก-- --" ;
  altObject.add(myEle) ;
  // Now loop through the array of individual items
  // Any containing the same child id are added to
  // the second dropdown box
  for ( x = 0 ; x < ItemArray.length  ; x++ )
    {
      if ( GroupArray[x] == control.value )
        {
          myEle = document.createElement("option") ;
          myEle.value = x ;
          myEle.text = ItemArray[x] ;
          altObject.add(myEle) ;
        }
    }
}


function formCheck_i(formobj,fieldRequired,fieldDescription){

	var alertMsg = "กรุณากรอกข้อมูลต่อไปนี้ให้ครับถ้วน:\n";
	var l_Msg = alertMsg.length;

	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == "" || obj.options[obj.selectedIndex].value == ""  || obj.options[obj.selectedIndex].value == 0){
					alertMsg += " i.. " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " i.. " + fieldDescription[i] + "\n";
				}
				break;
			case "checkbox":
				if (obj.checked == false){
					alertMsg += " i.. " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " i.. " + fieldDescription[i] + "\n";
				}
				break;
			default:
				if (obj.value == "" || obj.value == null){
					alertMsg += " i.. " + fieldDescription[i] + "\n";
				}
			}
		}
	}


	if (alertMsg.length == l_Msg){	
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}

function showFavoriteDLG(w,r){
	 var actionURL = showModalDialog('lessee_favorite_add.php?where_id='+w+'&room_id='+r, '', 'dialogHeight:150px; dialogWidth:300px; resizable:no; status:no');
	 if(actionURL){
		 window.location.replace(actionURL);
	 }
}



 function isObji(id) {
	return document.getElementById(id);
 }


 function createDiv(info) {     
		if (!document.createElement)  {	return;  }
		var objDiv =  document.createElement('div');
		if (typeof(objDiv.innerHTML) != 'string') { return; }
			objDiv.id = 'remarkINFO';
			objDiv.style.position = 'absolute';
			objDiv.style.display = 'none';
			objDiv.innerHTML = ""
				+ "<table style=\"	background-color: #FFFFFF; border: 1px solid #006699;\" cellspacing=\"0\" border=\"0\" width=\"450\" >\n"
				+ "<tr><td bgcolor=\"#FFDDDD\">\n"
				+ info
				+ "</td>\n</tr>\n</table>\n" 
				+ "";
			 document.body.appendChild(objDiv);
			setTimeout("kill_me()", 5400);
 }
 

function kill_me(){
	var rObj = isObji('remarkINFO');
	if(rObj){
			rObj.style.display = 'none';
			 document.body.removeChild(rObj);
	}
}


 function displayDiv(img,info) {
	createDiv(info);
	var rObj = isObji('remarkINFO');
	if(rObj){
		if (rObj.style.display == '') {
			rObj.style.display = 'none';
		}else if (rObj.style.display == 'none') {
			rObj.style.display = '';
			var locateObj = isObji(img);
			rObj.style.top = gPosition(locateObj,'top')+ 1 ;
			rObj.style.left = gPosition(locateObj,'left')+20;     
		}
	}
 }
 
 function gPosition(obj,nav) {
	var position;
	if(nav == "left"){
			position = obj.offsetLeft;
	}else if(nav == "top"){
			position = obj.offsetTop;
	}
	var currentObj = obj.offsetParent;
	while (currentObj != document.body) {
		if(nav == "left"){
				position += currentObj.offsetLeft;
		}else if(nav == "top"){
				position += currentObj.offsetTop;
		}
		currentObj = currentObj.offsetParent;
	}
	return position;
 }
 
function selectChange_cat(control, controlToPopulate, ItemArray, GroupArray)
{
  var myEle ;
  var x ;
	var altObject = document.getElementById(''+controlToPopulate+'');
  // Empty the second drop down box of any choices
  for (var q=altObject.length;q>=0;q--) altObject.options[q]=null;
  // ADD Default Choice - in case there are no values
  myEle = document.createElement("option") ;/*
  myEle.value = 0 ;
  myEle.text = "-Select-" ;
  altObject.add(myEle) ;*/
  // Now loop through the array of individual items
  // Any containing the same child id are added to
  // the second dropdown box
  for ( x = 0 ; x < ItemArray.length  ; x++ )
    {
      if ( GroupArray[x] == control.value )
        {
          myEle = document.createElement("option") ;
          myEle.value = x ;
          myEle.text = ItemArray[x] ;
          altObject.add(myEle) ;
        }
    }
}



