/**********************************************************************************************/
/*This file contains javascript functions that are being used in various scripts*/
/**********************************************************************************************/

//Javascript functions used for Res/Com interchange in various fields
team = new Array(
		new Array(
			new Array("Below  7 lacs", 1),
			new Array("7 to 15 lacs", 2),
			new Array("15 to 25 lacs", 3),
			new Array("25 to 40 lacs", 4),
			new Array("40 to 60 lacs", 5),
			new Array("60 to 100 lacs", 6),
			new Array("1 to 1.5 crores", 7),
			new Array("1.5 to 2 crores", 8),
			new Array("2 to 2.5 crores", 9),
			new Array("2.5 to 5 crores", 12),
			new Array("5 to 10 crores", 13),
			new Array("10 to 15 crores", 14),
                        new Array("15 to 20 crores", 15),
			new Array("20 to 25 crores", 16),
                        new Array("25 to 30 crores", 17),
			new Array("30 to 35 crores", 18),
                        new Array("35 to 40 crores", 19),
			new Array("40 to 45 crores", 20),
                        new Array("45 to 50 crores", 21),
			new Array("50 to 55 crores", 22),
                        new Array("55 to 60 crores", 23),
			new Array("60 to 65 crores", 24),
                        new Array("65 to 70 crores", 25),
			new Array("70 to 75 crores", 26),
                        new Array("75 to 80 crores", 27),
			new Array("80 to 85 crores", 28),
                        new Array("85 to 90 crores", 29),
			new Array("90 to 95 crores", 30),
                        new Array("95 to 100 crores", 31),
			new Array("Above 100 crores", 10),
			new Array("On Request", 11)
			),
		new Array(
			new Array("Below 4000", 1),
			new Array("4000 to 6,000", 2),
			new Array("6,000 to 10,000", 3),
			new Array("10,000 to 15,000", 4),
			new Array("15,000 to 20,000", 5),
			new Array("20,000 to 25,000", 6),
			new Array("25,000 to 40,000", 7),
			new Array("40,000 to 70,000", 8),
			new Array("70,000 to 1 lac", 9),
			new Array("1 lac to 1.5 lacs", 10),
			new Array("1.5 lacs to 2 lacs", 11),
			new Array("2 lacs to 5 lacs", 12),
			new Array(" 5 lacs to 10 lacs", 13),
			new Array("Above 10 lacs", 14),
			new Array("On Request", 15)
			)
		);

/*This function checks for the validity of emailId*/
/* this Added By Sandeep Beniwal For Proper Email Validation*/

function isEmail(str)
{
   var regex = /^[-_.a-z0-9]+@(([-_a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mobi|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;

return regex.test(str);
}
/*End Here*/
function checkemail(emailadd)
{
//this is replaced by sandeep Beniwal for proper email validation.
/*		var result = false;
        var theStr = new String(emailadd);
        var index = theStr.indexOf("@");
        if (index > 0)
        {
        var pindex = theStr.indexOf(".",index);
        if ((pindex > index+1) && (theStr.length > pindex+2))
                result = true;
        }
                                                                                                
        return result;
*/
	if (emailadd.length>100)
	{
		//alert("The Email-ID Too Long!")
		return false;
	}
	else if (emailadd.length<8)
	{
		//alert("The Email-ID Too Small!")
		return false;
	}
	else
	{
	return isEmail(trim(emailadd));
	}
}
/*Checks for the existence of invalid characters in username*/
function invalid_user(username)
{
	var invalidchar = new Array('#','\'','"','\\','/',' ','!','$','%','^','&','*','?');
	var invalid=0;
	for(i=0;i<username.length;i++)
	{
		for(j=0;j<invalidchar.length;j++)
		{
			if (username.charAt(i)==invalidchar[j])
			{
				invalid=1;
				break;
			}
		}
	}
	return invalid;
}

/*This function trims input string*/                                                    
function trim(inputString) {
	if (typeof inputString != "string") { return inputString; }
   	var retValue = inputString;
   	var ch = retValue.substring(0, 1);
   	while (ch == " ") {
      		retValue = retValue.substring(1, retValue.length);
      		ch = retValue.substring(0, 1);
   	}
   	ch = retValue.substring(retValue.length-1, retValue.length);
   	while (ch == " ") {
      		retValue = retValue.substring(0, retValue.length-1);
      		ch = retValue.substring(retValue.length-1, retValue.length);
   	}
   	while (retValue.indexOf("  ") != -1) {
      		retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
   	}
   	return retValue;
}

/*This function checks for the validity of floating-point numbers*/
function isint(str)
{
	var flag=0;
	for(var i=0;i < str.length;i++)
	{
		if((str[i]>=0 && str[i]<=9)||str[i]==".")
			flag=1;
		else
			return 0;
	}
	return flag;
}

/*Checks for the validity of integers*/
function isint2 (str)
{
	var i = parseInt (str);

	if (isNaN (i))
	return false;

	i = i . toString ();
	if (i != str)
	return false;

	return true;
}

/*This function is used for checking validity of phone number and pincode in the sense that they should consist digits only*/
function isint1(str)
{
	var flag=1;
	/*if(str.length < 6)
		flag=0;*/
	for(var i=0;i < str.length;i++)
	{
		if(str[i]>=0 && str[i]<=9)
			flag=1;
                       	else
                               	return 0;
	}
	return flag;
}

/* Javascript functions for images on subheader and their mouseover effects....
   Added by Sumit on 13 Aug 2005					*/

function MM_preloadImages() { //v3.0
	//Function Call added to check whether Residential or Commercial cookie is set
	//cookie_start(); //commenting function as this function uses old search bar.
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/

function setCookie_exp(name, value, expires, path, domain, secure) {
	
	var curCookie = name + "=" + escape(value) +((expires) ? "; expires=" + expires.toGMTString() : "") +((path) ? "; path=" + path : "") +((domain) ? "; domain=" + domain : "") +((secure) ? "; secure" : "");
	document.cookie = curCookie;
//	alert(document.cookie);
}


/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}


/*
   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
     create cookie)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*/

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}


function cookie_start()
{
	var now = new Date();
	now.setTime(now.getTime() + 30 * 24 * 60 * 60 * 1000);
	current = getCookie('RES_COM');
	if(current == 'RES')
	{
//		changetype('com',1);
		if(document.search_form)
		{
			if(document.search_form.type)
				document.search_form.type.options[0].value = 'R';
		//if(document.search_form)
			if(document.search_form.Mode.options)
				document.search_form.Mode.options[1].text = 'Rent';
		}
		//change_images('RES');	
		setStyleByClass('*','formcomm','background-color','#000000','formres');
	}
	else if(current == 'COM')
	{
//		changetype('res',1);
		if(document.search_form)
		{
			if(document.search_form.Mode.options)
                        	document.search_form.Mode.options[1].text = 'Lease';
		//if(document.search_form)
			if(document.search_form.type)
                        	document.search_form.type.options[0].value = 'C';
		}
		//change_images('COM');
		setStyleByClass('*','formres','background-color','#000000','formcomm');
		
	}
	else
	{
		setCookie_exp('RES_COM','RES',now,'/')
//		change_images('blue');
	
	}
	
}

// setStyleByClass: given an element type and a class selector,
// style property and value, apply the style.
// args:
//  t - type of tag to check for (e.g., SPAN)
//  c - old class name
//  p - CSS property
//  v - value
//  w - new class name
var ie = (document.all) ? true : false;

function toggleCookie(arg)
{
	var now = new Date();
        fixDate(now);
        now.setTime(now.getTime() + 30 * 24 * 60 * 60 * 1000);
	setCookie_exp('RES_COM', arg, now,'/')

}
function setStyleByClass(t,c,p,v,w){
	var now = new Date();
        fixDate(now);
        now.setTime(now.getTime() + 30 * 24 * 60 * 60 * 1000);
	if(w == 'formres')
	{
		setCookie_exp('RES_COM', 'RES', now,'/')
		if(document.getElementById("test2"))
                {
                        cross_slide=document.getElementById? document.getElementById("test2") : document.all.test2
cross_slide2=document.getElementById? document.getElementById("test3") : document.all.test3
                        var leftrightslide='<nobr>'+res_slide.join(imagegap)+'</nobr>'
cross_slide.innerHTML=cross_slide2.innerHTML=leftrightslide
                                                                                                               
                        fillup(1,leftrightslide);
                }

		/*if(document.getElementById("bedroomtag"))
		{
			document.getElementById("bedroomtag").style.visibility="visible";
		}*/
		
			
//		if(document.getElementById("bedroomdd"))
//			document.getElementById("bedroomdd").innerHTML="<select class=textboxes1 name=bedroom><option value=0 selected>Select</option><option value=1>1</option><option value=2>2</option><option value=3>3</option><option value=4>4</option> <option value=5>5</option><option value=6>6</option><option value=7>7</option><option value=8>8</option><option value=9>9</option><option value=10>9+</option></select>";
		var com = new Array('res1','res2','res3','res4','bdr','formheadres','labelres');
	        var res = new Array('com1','com2','com3','com4','bdrcom','formheadcom','labelcom');
	}		
	else
	{
//		alert(12);
		setCookie_exp('RES_COM', 'COM', now,'/');
                if(document.getElementById("test2"))
                {
			cross_slide=document.getElementById? document.getElementById("test2") : document.all.test2
cross_slide2=document.getElementById? document.getElementById("test3") : document.all.test3
			var leftrightslide='<nobr>'+com_slide.join(imagegap)+'</nobr>'
cross_slide.innerHTML=cross_slide2.innerHTML=leftrightslide

			fillup(1,leftrightslide);
                }
		/*if(document.getElementById("bedroomtag"))
		{
			document.getElementById("bedroomtag").style.visibility="hidden";
		}*/
//		if(document.getElementById("bedroomdd"))
//			document.getElementById("bedroomdd").innerHTML="";
		var res = new Array('res1','res2','res3','res4','bdr','formheadres','labelres');
	        var com = new Array('com1','com2','com3','com4','bdrcom','formheadcom','labelcom');
	}

	var elements;
//	alert(ie);
//	ie = false;
	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
//	alert(elements.length);
}

function changetype(type,check)
{
//	alert('type'+type+'check'+check);
	var restype = new Array(),comtype= new Array(),rescount=0,comcount=0;
	var cookiecol = getCookie('RES_COM');
	var flag = 0;
	if(document.search_form)
		var typedd = document.search_form.type;
	switch(type)
	{
		case 'com':
/*			if(typedd)
				typedd.options[0].value = 'C';*/
			if(check == 1)
                        {
                                return;
                        }

			if(cookiecol == 'COM')
				return;
			break;
		case 'res':
/*			if(typedd)
                                typedd.options[0].value = 'R';*/
			if(check == 1)
			{
				break;
			}
                        if(cookiecol == 'RES')
                                return;
			break;
	}
	if(typedd)
	{
			
	switch(cookiecol)
	{
		case 'RES':
			var diff = 'C';
			break;
		case 'COM':
			var diff = 'R';
			break;
	}
	if(check == 1)
		var diff='C';
	for(var i=0;i<typedd.options.length-1;i++)
	{
		if(typedd.options[i].value == 'L')
			break;

		if(typedd.options[i].value == diff)
		{
                        flag = 1	
		}
		switch(flag)
		{
			case 0:
				restype[rescount++] = typedd.options[i];
				break;
			case 1:
				comtype[comcount++] = typedd.options[i];
				break;
		}
	}
	var a=0,b=0;
	var total = typedd.options.length;
	for(var i=0;i<total-1;i++)
	{
		if(typedd.options[i].value == 'L')
                        break;

		if(i < comcount)
		{
			typedd.options[i] = new Option(comtype[a++].text);
			typedd.options[i].value = comtype[a-1].value;
			typedd.options[i].selected = comtype[a-1].selected;
		}
/*		if(i == comcount)
		{
			typedd.options[i] = new Option(comtype[0].text);
			typedd.options[i].value = comtype[0].value;
			typedd.options[i].selected = comtype[0].selected;
		}*/
		if(i >= comcount)
		{
			typedd.options[i] = new Option(restype[b++].text);
			typedd.options[i].value = restype[b-1].value;
			typedd.options[i].selected = restype[b-1].selected;
		}
		if(typedd.options[i].value == 'L' || typedd.options[i].value == 'R' || typedd.options[i].value== 'C')
		{
			typedd.options[i].className = 'boldclass';
		}
				
	}
	if(check != 1)
		typedd.options[0].selected = true;
	
	}
}

function change_images(RES_COM)
{
	var images = document.getElementsByTagName('IMG');
	switch(RES_COM)
	{
		case 'COM':
		for(var i=0;i<images.length;i++)
		{
			oldsrc = images[i].src;
			newsrc = oldsrc.replace(/_res/i,'_com');
			images[i].src = newsrc;
			images[i].onmouseover = onmousechangesrc;
			images[i].onmouseout = overmousechangesrc;
		}
		if(document.getElementById('maintabres') && document.getElementById('maintabcom'))
		{
			document.getElementById('maintabres').style.cursor = 'pointer';
			document.getElementById('maintabcom').style.cursor = 'default';
		}
		break;
		case 'RES':
		for(var i=0;i<images.length;i++)
                {
                        oldsrc = images[i].src;
                        newsrc = oldsrc.replace(/_com/i,'_res');
                        images[i].src = newsrc;
                        images[i].onmouseover = onmousechangesrc;
                        images[i].onmouseout = overmousechangesrc;
                }
		if(document.getElementById('maintabres') && document.getElementById('maintabcom'))
                {
                        document.getElementById('maintabres').style.cursor = 'default';
                        document.getElementById('maintabcom').style.cursor = 'pointer';
                }

		break;
	}
}

function onmousechangesrc()
{
//	alert(this);
	this.src = this.src.replace(/_res/i,'_res01');
	this.src = this.src.replace(/_com/i,'_com01');
}
	
function overmousechangesrc()
{
//	alert(this);
	this.src = this.src.replace(/_res01/i,'_res');
	this.src = this.src.replace(/_com01/i,'_com');
}

function replaceAll( str, from, to ) {
    var idx = str.indexOf( from );


    while ( idx > -1 ) {
        str = str.replace( from, to );
        idx = str.indexOf( from );
    }

    return str;
}

function setCookie()
{
        if(document.browse_property.Mode[0].checked)
        {
                var value='S';
                                                                                                                             
        }
        else
        {
                var value='R';
                                                                                                                             
        }
                                                                                                                             
        var now = new Date();
        fixDate(now);
        now.setTime(now.getTime() + 30 * 24 * 60 * 60 * 1000);
        setCookie_exp('deal_mode', value, now,'/')
        return true;
}
/*3 Functions copied from propadmin.js for reloading parent*/
function reloadParent()
{
        var func = "Reload()";
        window.opener.Timer(func);
}
                                                                                                 
function Timer(func)
{
                                                                                                 
        setTimeout(func,1000);
//      alert("Doing now");
//window.location.href = window.location.href;
}
                                                                                                 
function Reload()
{
        window.location.href = window.location.href;
}

/*Function for appending cat_code.... specifically made to be used with popups of main_payment.htm*/
function change_value(new_code)
{
        docF= window.opener.document.form1;
        docF.cat_code.value= docF.cat_code.value+','+new_code;
	prop_id=docF.PROP_ID.value;
	str= window.opener.location.href;
	end= str.indexOf('&from');
	if(end == -1)
	{
		original_href=str;
	}
	else
	{
		original_href=str.substr(0,end-1);
	}
	window.opener.location.href= original_href+'&from=popup&PROP_ID='+prop_id+'&cat_code='+docF.cat_code.value;
     // alert(window.opener.location.href);
        this.close(); 
}
/*ADD START 15.06.2006 (Tripti) For checking if someone has searched without entering locality*/
function check_city_empty()
{
	var docF=document.search_form;
	var name1="city";
	for(var i=0; i<docF.elements.length ; i++)
	{
		if(docF.elements[i].name == name1)
		{
			var flag=0;
			for(var j=1;j<docF.elements[i].options.length;j++)
			{
				if(docF.elements[i].options[j].selected)
				{
					flag=1;
				}
			}
			if(!flag)
			{
				alert("Please select City");
				docF.elements[i].focus();
				return false;
			}
		}
	}
	if(docF.type.value == 'L')
	{
		alert("Please select one option under LAND");
		return false;
	}
}
/*ADD END 15.06.2006 (Tripti) For checking if someone has searched without entering locality*/
/*
Function name   :       setTypevalue
Created by      :       Gunjan Kathuria
Date            :       19 Dec 2006
Description     :       This function sets the cookie and reloads the page when a property type is selected from select and cookie RES_COM is not of Property Type
*/
function setTypevalue()
{
var type_search=document.search_form.type.value;
resarray= new Array('R','1','2','3','4','5','22','23','80');
comarray= new Array('C','6','7','9','10','11','12','13','14','15','16','17','18','19','20','21','81');
var x = getCookie("RES_COM")
        if(x=='COM')
                for(var i=0;i<resarray.length;i++)
                        if(resarray[i]==type_search)
                        {
                                setCookie_exp('getType',type_search);
                                location.href="/Residential";
                        }
if(x=='RES')
                for(var i=0;i<comarray.length;i++)
                        if(comarray[i]==type_search)
                        {
                                setCookie_exp("getType",type_search);
                                location.href="/Commercial";
                        }
}

function setCityBudgetCookie(city,budget,mode)
{
	var now = new Date();
        fixDate(now);
        now.setTime(now.getTime() + 1 * 60 * 1000);

	if (city != 0)
	{
		for(i=0;i<city.options.length;i++)
		{
			if(city.options[i].selected == true)
			{
				arg = city.options[i].value;
        			setCookie_exp('QS_CITY', arg, now,'/')
				break;
			}
		}
	}
	if(budget != 0)
	{
                for(i=0;i<budget.options.length;i++)
                {
                        if(budget.options[i].selected == true)
                        {
                                arg = budget.options[i].value;
			        setCookie_exp('QS_BUDGET', arg, now,'/')
                                break;
                        }
                }
	}
	if(mode != 0)
	{
		arg = mode
	        setCookie_exp('QS_MODE', arg, now,'/')
	}
}

/*
Function name   :       checkNPerror
Created by      :       Puneet Chawla
Date            :       3 Apr 2007
Description     :       This function checks for any errors introduced by mismatched selection in case of New Projects
*/
function checkNPerror()
{

	var type = document.search_form.type;
	var mode = document.search_form.Mode;
	var show_newprojects = document.search_form.prop_newprojects;
	 if(show_newprojects)
		if ((type.value=='23' || type.value=='26' || show_newprojects.checked) && !(mode[0].checked || mode[0].selected))	//new project selected with Rent/PG Selected
	{
		var err = document.getElementById('error_msg');
		if(err)
			document.getElementById('error_msg').style.display="";
		else
			alert('Please Select "Buy" to View New Project Properties');
	}
	else
	{
		var err = document.getElementById('error_msg');
                if(err)
			document.getElementById('error_msg').style.display="none";
	}
}

function check_property(val)
{
        var base=document.search_form;
        if(val==1)
        {
                base.prop_all.checked=true;
                base.prop_owner.checked=false;
                base.prop_builder.checked=false;
                base.prop_broker.checked=false;
                base.prop_newprojects.checked=false;
        }
        if(val==2)
        {
                if(base.prop_owner.checked && base.prop_builder.checked && base.prop_broker.checked && base.prop_newprojects.checked)   //all except 'All' checked
                {
                        base.prop_all.checked=true;
                        base.prop_owner.checked=false;
                        base.prop_builder.checked=false;
                        base.prop_broker.checked=false;
                        base.prop_newprojects.checked=false;
                }
                if(!base.prop_owner.checked && !base.prop_builder.checked && !base.prop_broker.checked && !base.prop_newprojects.checked)
                {
                        base.prop_all.checked=true;
                        base.prop_owner.checked=false;
                        base.prop_builder.checked=false;
                        base.prop_broker.checked=false;
                        base.prop_newprojects.checked=false;
                }
                else
                {
                        base.prop_all.checked=false;
                }
                checkNPerror();
        }
}

function check_type(index_type)
{
	if(!index_type)
	var index_type = document.search_form.type.value;
	if(index_type=='C' || (index_type >= 6 && index_type<= 21) || index_type==25 || index_type==81) //commercial
	{
		document.search_form.prop_newprojects.checked=false;
		document.search_form.prop_newprojects.disabled=true;
		if(document.search_form.bedroom)
			document.search_form.bedroom.disabled=true;
		if(document.search_form.Mode.options)
		{
			document.search_form.Mode.options[1].text = 'Lease';	
			document.search_form.Mode.options[2] = null;	
		}
	}
	else
	{
		document.search_form.prop_newprojects.disabled=false;
		if(document.search_form.bedroom)
			document.search_form.bedroom.disabled=false;
		if(document.search_form.Mode.options)
		{
			document.search_form.Mode.options[1].text = 'Rent';	
			document.search_form.Mode.options[2] = new Option('PG');
			document.search_form.Mode.options[2].value = 'P';
		}		
	}
}

function MM_openBrWindow(theURL,winName,features)  //v2.0
{
	window.open(theURL,winName,features);
}

function togglePostPropertyDD(x)
{
	if(x=='C')
	{
		document.getElementById('PostPropertyDDCom').disabled=false;
		document.getElementById('PostPropertyDDCom').style.display='block';

		document.getElementById('PostPropertyDDRes').disabled=true;
		document.getElementById('PostPropertyDDRes').style.display='none';

		document.getElementById('ModeDDCom').disabled=false;
		document.getElementById('ModeDDCom').style.display='block';

		document.getElementById('ModeDDRes').disabled=true;
		document.getElementById('ModeDDRes').style.display='none';
	}
	else
	{
		document.getElementById('PostPropertyDDCom').disabled=true;
		document.getElementById('PostPropertyDDCom').style.display='none';

		document.getElementById('PostPropertyDDRes').disabled=false;
		document.getElementById('PostPropertyDDRes').style.display='block';

		document.getElementById('ModeDDCom').disabled=true;
		document.getElementById('ModeDDCom').style.display='none';

		document.getElementById('ModeDDRes').disabled=false;
		document.getElementById('ModeDDRes').style.display='block';
	}
}

//Function Added for  T.Arora
function isName1(string)
{
var i,j,k;
        var invalidchar = new Array('/','#','"','\\','!','@','$','%','^','&','*','?',':','`','(',')','_','+)','=','{','}','[',']','|','<','>',';','-','+','~','1','2','3','4','5','6','7','8','9','0');
        var invalid=0;
        for( i=0;i<string.length;i++)
        {
                for( j=0;j<invalidchar.length;j++)
                {

                        if (string.charAt(i) == invalidchar[j])
                        {
                                return false;

                        }
                }
        }
        return true;
}

function check_numbers()
{
        var docF1=document.ajax_form;
        var count=0;
        for(var i=0;i<docF1.elements.length;i++)
        {
                if(docF1.elements[i].name=="compare_chkbx[]")
                {
                        //alert(docF1.elements[i].name);
                        if(docF1.elements[i].checked==true)
                                count++;
                }

                //docF1.elements[i].checked=false;
        }
	//alert(count);
        if(count<2)
        {
                docF1.Compare.disabled=true;
                docF1.Compare_1.disabled=true;
        }
        else if(count>=2 && count<4)
        {
	//alert('a');
                docF1.Compare.disabled=false;
                docF1.Compare_1.disabled=false;
                for(var i=0;i<docF1.elements.length;i++)
                {
                        if(docF1.elements[i].name=="compare_chkbx[]")
                        {
                                //if(docF1.elements[i].checked==false)
                                        docF1.elements[i].disabled=false;
                        }
                }

        }
        else if(count==4)
        {
                docF1.Compare.disabled=false;
                docF1.Compare_1.disabled=false;
                for(var i=0;i<docF1.elements.length;i++)
                {
                        if(docF1.elements[i].name=="compare_chkbx[]")
                        {
                                if(docF1.elements[i].checked==false)
                                        docF1.elements[i].disabled=true;
                        }
                }       

        }
        /*else if(count>4)
        {
                for(var i=0;i<docF1.elements.length;i++)
                {
                        if(docF1.elements[i].name=="chb[]")
                        {
                                if(docF1.elements[i].checked==false)
                                        docF1.elements[i].disabled=true;
                        }
                }
        }*/
        //else
        //{
        
        //}
}
function submit_compare_form()
{
        var docF1=document.ajax_form;
        var count=0;
	var val= new Array();//array();
        for(var i=0;i<docF1.elements.length;i++)
        {
                if(docF1.elements[i].name=="compare_chkbx[]")
                {
                        //alert(docF1.elements[i].name);
                        if(docF1.elements[i].checked==true)
			{
				//alert(docF1.elements[i].value);
				val[count]=docF1.elements[i].value;
                                count++;
			
			}
                }

                //docF1.elements[i].checked=false;
        }
	var error=0;
	var prop_id='';
	var tmp_min_val=0;
	var tmp_bucket_arr= new Array();
	var prop_id_arr= new Array();
	for(var i=0;i<val.length;i++)
	{
		tmp=val[i].split('*');
		tmp_bucket_arr[i]=tmp[1];
		prop_id_arr[i]=tmp[0];
	}
	tmp_min_val=tmp_bucket_arr[0];
	for(var i=0;i<tmp_bucket_arr.length;i++)
	{
		if(i!=tmp_bucket_arr.length-1)
		{
			if(tmp_bucket_arr[i]!=tmp_bucket_arr[i+1])
			{
				error=1;
			}
			if(tmp_bucket_arr[i]<tmp_min_val)
				tmp_min_val=tmp_bucket_arr[i];
		}
	}
	if(!error)
	{
		for(var i=0;i<prop_id_arr.length;i++)
		{
			prop_id+=prop_id_arr[i]+",";
		}
        	window.open('compare.php?PROP_IDS='+prop_id,'','width=760,height=570,scrollbars=yes');
	}
	else
	{
		
			alert("Please select properties of similar type in order to compare them. For eg: \nResidential Apartment with Residential Apartment Or\nCommercial Shops with Commercial Shops");
			return false;
	}
}
/*
Function to open a given script in a new window
*/
function open_new_window(path)
{
        window.open(path,'','width=770,height=570,scrollbars=yes,resizable=1');
        return false;
}

function check_search()
{
        var base=document.search_form;
        if(base.Mode.value=="-1" && base.city.value=="0" && base.type.value=="0" && base.Budget.value=="0" && base.bedroom.value=="0")
        {
                alert("User,kindly select one criterion for the search");
                return false;
        }
        else 
                return true;
}
function fillSelectFromArray(selectCtrl, itemArray)
{
        var i, j;
        var prompt;
        if(selectCtrl=="" || selectCtrl==0)
                selectCtrl=document.search_form.Budget;
        if(itemArray==0 || itemArray=="")
                itemArray=0;
        // empty existing items
        if (selectCtrl)
                for (i = selectCtrl.options.length-1; i >= 0; i--) 
                {
                        selectCtrl.options[i] = null;
                }
        goodPrompt="INR";
        badPrompt="INR";
        prompt = (itemArray != null) ? goodPrompt : badPrompt;
        if (prompt == null) 
        {
                j = 0;
        }
        else 
        {
                if(selectCtrl)  
                        selectCtrl.options[0] = new Option(prompt);
                j = 1;
        }       
	 if (itemArray != null) 
        {
                // add new items
                for (i = 0; i < itemArray.length; i++) 
                {
                        selectCtrl.options[j] = new Option(itemArray[i][0]);
                        if (itemArray[i][1] != null) 
                        {
                                selectCtrl.options[j].value = itemArray[i][1];
                        }
                        j++;
                }
                // select first item (prompt) for sub list
                selectCtrl.options[0].value = 0;
                selectCtrl.options[0].selected = true;
        }
}

