//Ajax function

function XHConn()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}


function checkEmail()
{
	
	//alert(document.getElementById('email').value);
	
	
	var myConn = new XHConn();
	var email;
	email = document.getElementById('email').value;
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	
	var include_terminado = function (oXML){ 
	if(oXML.responseText == '1'){
	document.getElementById('email').style.background='red';
	document.getElementById('email').style.color='white';
	document.getElementById('err').innerHTML = '<font color=red>Email all ready exist in database</font>';
	document.getElementById('submit').disabled = true;
	}
	else
	{
	document.getElementById('email').style.background='white';
	document.getElementById('email').style.color='black';
	document.getElementById('err').innerHTML = '';
	document.getElementById('submit').disabled = false;
	}
	};
	myConn.connect("checkemail.php", "GET", "email="+email, include_terminado);
	
	
	
}



function getLocation(frmPkg)
{
	var myConnloc = new XHConn();
	
	var con=document.frmPkg["city"];
	var concity = con.value;
	if(concity==""){
	alert("Please Re-Select Country");return false;}
	//alert(country);
	if (!myConnloc) alert("XMLHTTP not available. Try a newer/better browser.");
	var include_terminado = function (oXML){ 
	var hoteldetail=oXML.responseText;
	var x=0;
	
	    var htarr=hoteldetail.split("@");
		//document.frmPkg["city"].value=htarr[0];
		//var htrms=htarr[1].split("@");
      // alert(htarr);
	   var numcity=htarr.length-1;
	   document.frmPkg["location"].options.length=0;
	   document.frmPkg["location"].options[0]=new Option("-----All-----","");
	   //alert(numcity);
	   
	   if(numcity >=1){
		   
		  
						   for(i=0;i<numcity;i++){
						   document.frmPkg["location"].options[i+1]=new Option(htarr[i],htarr[i]);}
								
						}
		
	};
	myConnloc.connect("getLocation.php", "GET", "city="+concity, include_terminado);
	
}

function getpic111(pic,id){
	

var myConn = new XHConn();
var img = document.images['imgPkg'+id]; 

document.getElementById('divpkg'+id).innerHTML = "<img name="+img+" src='images/loading.gif' />";
if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
var include_terminado = function (oXML){ 

	
	};
//img.src = pic;
document.getElementById('divpkg'+id).innerHTML ="";	
document.getElementById('divpkg'+id).innerHTML = "<img name="+img+" src='"+pic+"' />";	


}



function SendQuery()
{
//	alert('HIMANSHU');
	var id=document.getElementById('name').value;
	var ml=document.getElementById('email').value;
	var msg=document.getElementById('telephone').value;
//	alert(msg);
	if(document.getElementById('emailSuccess').style.display == 'none'){
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	var include_terminado = function (oXML){ document.getElementById('emailSuccess').innerHTML = oXML.responseText;};
	//alert(oXML.responseText);
	//document.getElementById('imgPro'+id).src = 'images/close2.jpg'; 
	
	document.getElementById('emailSuccess').style.display = 'inline'; 
	document.getElementById('loadBar').style.display = 'inline'; 
	//document.getElementById('emailSuccess').innerHTML = "<img src='images/loading.gif' />";

	myConn.connect("contact.php", "GET", "name="+id+"&mail="+ml+"&message="+msg, include_terminado);
	document.getElementById('name').value='';
	document.getElementById('email').value='';
	document.getElementById('telephone').value='';
	//alert("PROPERTY DETAILS");
	return false;
	}
	else
	{
		document.getElementById('emailSuccess').style.display == 'none'; 
		document.getElementById('loadBar').innerHTML = "";
		//document.getElementById('imgPro'+id).src = 'images/view_more.gif';
	}
}
function pause()
{
	setTimeout(3000);
}
function deleteMultipl()
{
	
	if(confirm("Do you Really want to Delete?")==true)
	{

		//CheckIsSelected();
		
		document.location.href="property.php";
		return true;
	}
   else
   return false;
	
}

function CheckIsSelected()
{
        var chkobj=document.form1.chk;
		var blSelected = false;
        
		for(i=0;i<chkobj.length;i++)
			{
				if(chkobj[i].checked)
				{ 
						blSelected = true;
						break;
				}
				
			}
		
		if(!blSelected)
        {
          	alert('Please Select at least One Record!');
            return false
        }
		else
		{
			
			return true;
		}
}
var form='form1' //Give the form name here

function SetChecked(val,chkName) {
dml=document.forms[form];
len = dml.elements.length;
var i=0;
for( i=0 ; i<len ; i++) {
if (dml.elements[i].name==chkName) {
dml.elements[i].checked=val;
}
}
}

function checkBox(){
return confirm('All records will be deleted');
}


/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;


/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   integer  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 1.1 Sets the mouse pointer to pointer on mouseover and back to normal otherwise.
    if (theAction == "over" || theAction == "click") {
        theRow.style.cursor='pointer';
    } else {
        theRow.style.cursor='default';
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0)
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // Garvin: deactivated onclick marking of the checkbox because it's also executed
            // when an action (like edit/delete) on a single item is performed. Then the checkbox
            // would get deactived, even though we need it activated. Maybe there is a way
            // to detect if the row was clicked, and not an item therein...
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function

function ChangeImage(param)
{
	var img_array = param.split('@');
	var img_id_array = img_array[1].split('#');
	var img = document.getElementById('bigImage'); 
	var a = document.getElementById('bimg'); 
	img.src = "../propertyimages/"+img_array[0];
	a.href = "javascript:popupWindow('popup_image.php?imgID="+img_id_array[0]+"@"+img_id_array[1]+"')";
	
}

//Booking details showing using AJAX
function showBookingOld(id)
{
document.getElementById('booking'+id).className = 'reveal'; 
alert(id);
}




function close_addPrice()
{
window.opener.location.reload();
self.close();
}



function open_editImgwinGall(id,imid)
{
window.open("edit_imgGall.php?uid="+id+"&imd="+imid,"_blank","scrollbars=yes,width=400,height=300")
}
function chk_imgtype()
{
var extPos=document.reg.upldimg.value.indexOf(".");
var strimg=(document.reg.upldimg.value).substr(extPos+1);
//alert(strimg);
if(document.reg.upldimg.value==""){
alert("Please Select the image");
document.reg.upldimg.focus();
return false;}
var strimg2=strimg.toLowerCase();

if((strimg2!="gif")&&(strimg2!="png")&&(strimg2!="jpg")){
alert("Please Select Only Gif, Jpg or Png Format");
document.reg.upldimg.focus();
return false;}

}

function chk_add_imgtype()
{
var extPos=document.reg.upld_proimg.value.indexOf(".");
var strimg=(document.reg.upld_proimg.value).substr(extPos+1);
//alert(strimg);
if(document.reg.upld_proimg.value==""){
alert("Please Select the image");
document.reg.upld_proimg.focus();
return false;}
if((strimg!="gif")&&(strimg!="png")&&(strimg!="jpg")){
alert("Please Select Only Gif, Jpg or Png Format");
document.reg.upld_proimg.focus();
return false;}

}

function selectAll(){
if(document.form1.chkSel.checked==false){
		DeSelectAll();
}
else
{
selectAllNew();
}
}

function selectAllNew()
{
for(i=0;i<document.form1.elements.length;i++){
if(document.form1.elements[i].type=="checkbox"){
document.form1.elements[i].checked = true;
}
}
}

function DeSelectAll(){
for(i=0;i<document.form1.elements.length;i++){
if(document.form1.elements[i].type=="checkbox"){
document.form1.elements[i].checked = false;
}
}
}
