//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(signup){
	
	var myConn = new XHConn();
	var email;
	email = document.getElementById('txtusernm').value;

	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");

	var include_terminado = function (oXML){ 

 //  alert(oXML.responseText);
	
	if(oXML.responseText == 1){
	
	//alert("Email Already Exists, Please Choose a different Email");

	document.getElementById('txtusernm').style.background='red';

	document.getElementById('txtusernm').style.color='white';

	document.getElementById('err').innerHTML = '<font color=red size=1>Username already exists, Please choose a different username!</font>';

	
	document.getElementById('err').className = 'reveal';

	document.signup.txtusernm.focus();
	document.getElementById('submit').disabled = true;

    //document.getElementById('imgsubmit').enabled=false;

	document.signup.txtusernm.focus();

	}

	else

	{

	document.getElementById('txtusernm').style.background='white';

	document.getElementById('txtusernm').style.color='red';

	document.getElementById('txtusernm').className = 'hidden';
	document.getElementById('err').innerHTML = '';

	document.getElementById('submit').disabled = false;

	}

	};

	myConn.connect("CHKUSR.php", "GET", "email="+email, include_terminado);
}


function checkEmailAd(frmAd){
	
	var myConn = new XHConn();
	var email;
	email = document.getElementById('txtemail').value;

	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");

	var include_terminado = function (oXML){ 

 //  alert(oXML.responseText);
	
	if(oXML.responseText == 1){
	
	//alert("Email Already Exists, Please Choose a different Email");

	document.getElementById('txtemail').style.background='red';

	document.getElementById('txtemail').style.color='white';

	document.getElementById('err').innerHTML = '<font color=red size=1>This Email already exists in our Database!</font>';

	
	document.getElementById('err').className = 'reveal';

	document.frmAd.txtemail.focus();
	document.frmAd.submit.disabled = true;

    //document.getElementById('imgsubmit').enabled=false;

	document.frmAd.txtemail.focus();

	}

	else

	{

	document.getElementById('txtemail').style.background='white';

	document.getElementById('txtemail').style.color='green';

	document.getElementById('txtemail').className = 'hidden';
	document.getElementById('err').innerHTML = '';

	document.frmAd.submit.disabled = false;

	}

	};

	myConn.connect("CHKUSR.php", "GET", "email2="+email, include_terminado);
}


function checkSecruityImg(frmAd){
	
	//alert('sfd');
	var myConnSecure = new XHConn();
	var secureword;
	secureword = document.frmAd.txtSecurityCode.value;
    if (!myConnSecure) alert("XMLHTTP not available. Try a newer/better browser.");

	var include_terminado = function (oXML){ 

   //alert(oXML.responseText);
	
	if(oXML.responseText == 1){
	
	//alert("Email Already Exists, Please Choose a different Email");

	document.frmAd.txtSecurityCode.style.background='red';

	document.frmAd.txtSecurityCode.style.color='white';

	document.getElementById('errCode').innerHTML = '<font color=red size=1>Wrong Code Entered ! Please Enter the Correct Code.</font>';

	
	document.getElementById('errCode').className = 'reveal';

	document.frmAd.txtSecurityCode.focus();
	document.frmAd.submit.disabled = true;

    //document.getElementById('imgsubmit').enabled=false;

	document.frmAd.txtSecurityCode.focus();

	}

	else

	{

	document.frmAd.txtSecurityCode.style.background='white';

	document.frmAd.txtSecurityCode.style.color='green';

	document.frmAd.txtSecurityCode.className = 'hidden';
	document.getElementById('errCode').innerHTML = '';

	document.frmAd.submit.disabled = false;

	}

	};

	myConnSecure.connect("chkSecure.php", "GET", "secure="+secureword, include_terminado);
}


function checkEmailNew()
{
	var email;

	email = document.getElementById('emailNew').value;
	//alert(email);
	
	var myConn = new XHConn();

	

	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");

	var include_terminado = function (oXML){ 

	if(oXML.responseText == '1'){

	document.getElementById('emailNew').style.background='red';

	document.getElementById('emailNew').style.color='white';

	document.getElementById('err').innerHTML = '<font color=red>Email all ready exist in database</font>';

	document.getElementById('err').className = 'reveal';

	document.getElementById('imgsubmit').disabled = true;

	}

	else

	{

	document.getElementById('emailNew').style.background='white';

	document.getElementById('emailNew').style.color='black';

	document.getElementById('err').innerHTML = '';

	document.getElementById('err').className = 'hidden';

	document.getElementById('imgsubmit').disabled = false;

	}

	};

	myConn.connect("checkemail.php", "GET", "email="+email, include_terminado);
}



function confirmSignup(){
	
	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('err').className = 'reveal';

	document.getElementById('submit').disabled = true;

	document.getElementById('email').style.background='white';

	document.getElementById('email').style.color='black';

	document.getElementById('err').innerHTML = '';

	document.getElementById('err').className = 'hidden';

	document.getElementById('submit').disabled = false;
}



function chkEmail(email){

if ((email.value==null)||(email.value=="")){

		alert("Please Enter your Email ID")

		email.focus()

		return false

}

if (echeck(email.value)==false){

email.value=""

email.focus()

return false

}



}

function chkPassword(pass){



if ((pass.value==null)||(pass.value=="")){

		alert("Please Enter your Password")

		pass.focus()

		return false

}



}



function showTestimonial(id)

{

	if(document.getElementById('booking'+id).className == 'hidden'){



	document.getElementById('btnBooking'+id).value = 'Hide Testimonial'; 

	document.getElementById('booking'+id).className = 'reveal'; 

	

	}

	else

	{

		document.getElementById('btnBooking'+id).value = 'Show Testimonial';

		document.getElementById('booking'+id).className = 'hidden'; 

		

	}

}



//email validation script

function echeck(str) {



		var at="@"

		var dot="."

		var lat=str.indexOf(at)

		var lstr=str.length

		var ldot=str.indexOf(dot)

		if (str.indexOf(at)==-1){

		   alert("Invalid E-mail ID")

		   return false

		}



		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){

		   alert("Invalid E-mail ID")

		   return false

		}



		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){

		    alert("Invalid E-mail ID")

		    return false

		}



		 if (str.indexOf(at,(lat+1))!=-1){

		    alert("Invalid E-mail ID")

		    return false

		 }



		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){

		    alert("Invalid E-mail ID")

		    return false

		 }



		 if (str.indexOf(dot,(lat+2))==-1){

		    alert("Invalid E-mail ID")

		    return false

		 }

		

		 if (str.indexOf(" ")!=-1){

		    alert("Invalid E-mail ID")

		    return false

		 }



 		 return true					

}







function deleteMultipl()

{

	

	if(confirm("Do you Really want to Delete?")==true)

	{



		//CheckIsSelected();

		

		document.location.href="property.php";

		return true;

	}

   else

   return false;

	

}

function deleteeventMultipl()

{

	

	if(confirm("Do you Really want to Delete?")==true)

	{



		//CheckIsSelected();

		

		document.location.href="event.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('Do you really want to delete?');

}





/**

 * 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



//Booking details showing using AJAX

function showBookingOld(id)

{

document.getElementById('booking'+id).className = 'reveal'; 

alert(id);

}



function open_win(id)

{

window.open("proImg.php?uid="+id,"_blank","scrollbars=yes,width=400,height=420")

}



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]+"')";

	

}



function xmlhttpPost(strURL,callerFunction) {

    var xmlHttpReq = false;

    var self = this;

    // Mozilla/Safari

    if (window.XMLHttpRequest) {

        self.xmlHttpReq = new XMLHttpRequest();

    }

    // IE

    else if (window.ActiveXObject) {

        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");

    }

    self.xmlHttpReq.open('get', strURL, true);

    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    self.xmlHttpReq.onreadystatechange = function() {

        if (self.xmlHttpReq.readyState == 4) {

            switch(callerFunction)

			{

				case 1 : upd_cal(self.xmlHttpReq.responseText); break;

		

			}	

        }

    }

    self.xmlHttpReq.send(null);

}

function chk_videotype()
{
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;}
if((strimg!="gif")&&(strimg!="png")&&(strimg!="jpg")){
alert("Please Select Only Gif, Jpg or Png Format");
document.reg.upldimg.focus();
return false;}

}


//////////////////////////////////////////////////////////////////////////////////////////////////

