//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 SendQuery()
{
	var id=document.getElementById('name').value;
	var ml=document.getElementById('email').value;
	var rml=document.getElementById('remail').value;
	var sbj=document.getElementById('subject').value;
	var elink=document.getElementById('lnk').value;
	
	var msg=document.getElementById('comments').value;
	
	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;};
	
	//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+"&remail="+rml+"&elink="+elink+"&sub="+sbj, include_terminado);
	//document.getElementById('name').value='';
	document.getElementById('remail').value='';
	//document.getElementById('comments').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 open_win2(id)
{
window.open("view_proimg.php?uid="+id,"_blank","scrollbars=no,width=430,height=420")
}


function close_addPrice()
{
window.opener.location.reload();
self.close();
}

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;
}
}
}


/////////////////////////////////////////////IMAGE GALLERY//////

function selectAllimg(){
if(document.iview.chkSel.checked==false){
		DeSelectAllimg();
}
else
{
selectAllNewimg();
}
}

function selectAllNewimg()
{
for(i=0;i<document.iview.elements.length;i++){
if(document.iview.elements[i].type=="checkbox"){
document.iview.elements[i].checked = true;
}
}
}

function DeSelectAllimg(){
for(i=0;i<document.iview.elements.length;i++){
if(document.iview.elements[i].type=="checkbox"){
document.iview.elements[i].checked = false;
}
}
}


function sendLink(){
document.getElementById("query").style.display="inline";
}
function closeit(){
document.getElementById("search").style.display="none";
}



