function creatContainerDiv(id,url,title)
{
	// get body
	var objBody = document.getElementsByTagName("body").item(0);

	// if specific container doesn't already exist
	if(!document.getElementById(id+'Container'))
	{
		// create the cover (transparency)
		var cover=document.createElement("div");
		cover.setAttribute('id',id+"Cover");
		cover.setAttribute('rel',"Cover");
		cover.style.position="absolute";
		cover.style.left=0;
		cover.style.top=0;
		cover.style.zIndex=1;
		cover.style.display='none';
		objBody.appendChild(cover);

		// create container
		var dvContainer=document.createElement('div');
		dvContainer.style.display='none';
		dvContainer.setAttribute('id',id+"Container");
		dvContainer.setAttribute('rel',"Container");
		objBody.appendChild(dvContainer);
		Element.hide(id+'Container');
		dvContainer=$(id+'Container');
		dvContainer.style.position="absolute";
		dvContainer.style.zIndex=1;
		objBody.appendChild(dvContainer);
	}

	// get page and screen sizes
	var arrPageSize=getPageSize();
	var screenHeight=(document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight);
	var screenWidth=(document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth);
	if(id == "signupDiv")
	{
		var leftPos = parseInt((screenWidth-400)/2);
	}
	else
	{
		var leftPos = parseInt((screenWidth-300)/2);
	}

	// set opacity and references
	var cvrOpacity = '0.75';
	var ctrOpacity = '1.0';
	var cover      = $(id+'Cover');
	var contr      = $(id+'Container');

	// set cover/container background colors and opacities
	cover.style.backgroundColor='black';
	cover.setOpacity(cvrOpacity);
	contr.style.backgroundColor='transparent';
	contr.setOpacity(ctrOpacity);
	
	// setup the innerHTML for the pop-up
	Element.setInnerHTML(id+'Container',"<table align=left border=0 cellspacing=0 cellpadding=0 style='background-color: transparent;'><tr><td colspan=3 height=5 bgcolor='#000000'></td></tr><tr><td width=5 bgcolor='#000000'></td><td><table align=center border=0 cellspacing=0 cellpadding=3px bgcolor=white><tr><td align=left width=70% style='padding-left:15px'><span id='"+id+"Title' class='containerTitle'></span></td><td align=right width=30%><img id='idImgTopClose"+id+"' src='"+WEB_ROOT+"images/closelabel.gif' style='cursor:pointer;' onClick='closeContainerDiv(\""+id+"\")' alt='' />&nbsp;</td></tr><tr><td width=95% colspan=2 height='100%' align='center' bgcolor='white'><div id='"+id+"' class='BlueBold11px' style='text:align:left;'></div></td></tr><tr><td width='100%' bgcolor='white' colspan='2' align='right'><img id='idImgBottomClose"+id+"' src='"+WEB_ROOT+"images/closelabel.gif' style='cursor:pointer;' onClick='closeContainerDiv(\""+id+"\")' alt='' />&nbsp;</td></tr></table></td><td width=5 bgcolor='#000000'></td></tr><tr><td colspan=3 height=5 bgcolor='#000000'></td></tr></table>");

	// set the left offset and height for the container
	$(id+'Container').style.left=leftPos+'px';
	//Element.setHeight(id+'Container', 300);

	//Element.setWidth(id+'Container', 500);

	// get page scroll height and set offsets accordingly for container and id div
	var arrPageScroll=getPageScroll();
	if(id == "signupDiv")
	{
		Element.setTop(id+'Container',arrPageScroll[1]+100);
	}
	else
	{
		Element.setTop(id+'Container',arrPageScroll[1]+150);
	}
	//Element.setTop(id+'Container',50);
	//Element.setHeight(id, 300);

	// set the cover element's height and width
	Element.setHeight(id+'Cover', arrPageSize[1]);
	Element.setWidth(id+'Cover', arrPageSize[0]);

	//Element.setWidth(id, 460);

	// set id div's overflow
	$(id).style.overflow='auto';

	// if title is test
	if (!(/^\s*$/.test(title) || /^\s*undefined\s*$/.test(title)))
	{
		// reset it to supplied value
		$(id+'Title').innerHTML=title;
	}
	
	// hide/show various elements
	//hideSelectBoxes();
	Element.show(id+'Container');
	Element.show(id+'Cover');

	// loop through
	for (var x=1;x<6;x++)
	{
		// and setup timeouts
		setTimeout("if($('idImgTopClose"+id+"')) { $('idImgTopClose"+id+"').src='"+WEB_ROOT+"images/closelabel.gif'; } if($('idImgBottomClose"+id+"')) { $('idImgBottomClose"+id+"').src='"+WEB_ROOT+"images/closelabel.gif'; } ",x*1000);
	}

	// if the url is not a test/blank url
	
	if(id == "loginDiv")
	{
		var emailCookie = Get_Cookie("property_login_check");
		if(emailCookie == "null") emailCookie = '';
		$(id).innerHTML = '<table cellpadding="0" width="300" cellspacing="10" border="0" align="left">'
							+'<tr>'
								+'<td height="2" colspan="2" align="center" style="color:#FF0000; font-weight:bold; size:10px;" id="showMessageLogin"></td>'
							+'</tr>'
							+'<tr>'
								+'<td width="90" align="left" valign="middle" class="text6"><b>Email ID:</b></td>'
							  +'<td width="210" align="left" valign="middle" class="text6"><input type="text" id="email" name="email" value="'+emailCookie+'" class="text_box" size="20" onkeypress="clearErrorMessage();"></td>'
						  +'</tr>'
							+'<tr>'
								+'<td align="left" valign="middle" class="text6"><b>Password:</b></td>'
								+'<td align="left" valign="middle" class="text6"><input type="password" id="password" name="password" value="" class="text_box" size="22" onkeypress="clearErrorMessage();"></td>'
						  +'</tr>'
							+'<tr>'
								+'<td align="left" valign="middle" class="text6" colspan="2"><input type="checkbox" name="remember" id="remember" value="1" checked="checked" />&nbsp; Remember Me</td>'
						  +'</tr>'
							+'<tr>'
								+'<td class="text6">&nbsp;</td>'
								+'<td align="left" valign="bottom" height="30"><input type="button" name="save" id="save" value="Login" class="button_class" style="width:70px;" onclick="loginNow();" /></td>'
							+'</tr>'
							+'<tr>'
								+'<td align="left" valign="middle" class="text6" colspan="2"><br />If you don\'t have an account , Please <span class="text7"><input type="button" name="Signup" id="Signup" value="Signup" class="button_class" style="width:70px;" onclick="closeContainerDiv(\'loginDiv\'); show_signup_pop();" /></span><br /><br /><span class="text7"><a href="javascript:void(0)" onclick="location.href=WEB_ROOT+\'forgot.php\';">Forgot your username or password ?</a></span></td>'
						  +'</tr>'
						+'</table>';
	}
	else if(id == "signupDiv")
	{
		$(id).innerHTML = '<table width="400" border="0" align="center" cellpadding="5" cellspacing="0">'
							+'<tr>'
								+'<td colspan="2" align="center" id="showMessageLogin" style="color:#FF0000; font-weight:bold; size:10px;"></td>'
							+'</tr>'
						  +'<tr>'
							+'<td width="35%" align="right" valign="middle" class="text6">Full Name: </td>'
							+'<td width="65%" align="left" valign="middle" ><input type="text" name="first_name" class="text_box" id="first_name" value="" size="20" onkeypress="clearErrorMessage();" /></td>'
						  +'</tr>'
						  +'<tr>'
							+'<td align="right" valign="middle" class="text6">Username:</td>'
							+'<td align="left" valign="middle" ><input type="text" name="last_name" class="text_box" id="last_name" value="" size="20" onkeypress="clearErrorMessage();" /></td>'
						  +'</tr>'
						   +'<tr>'
							+'<td align="right" valign="middle" class="text6">E-mail: </td>'
							+'<td align="left" valign="middle"><input type="text" name="email" class="text_box" id="email" value="" size="20" onkeypress="clearErrorMessage();" /><span class="text6">No Spam</span></td>'
						  +'</tr>'
						   +'<tr>'
							+'<td align="right" valign="middle" class="text6">Password :</td>'
							+'<td align="left" valign="middle" ><input type="password" name="password" class="text_box" id="password" size="20" onkeypress="clearErrorMessage();" /></td>'
						  +'</tr>'
						   +'<tr>'
							+'<td align="right" valign="middle" class="text6">Retype Password:</td>'
							+'<td align="left" valign="middle" ><input type="password" name="r_password" class="text_box" id="r_password" size="20" onkeypress="clearErrorMessage();" /></td>'
						  +'</tr>'
							+'<tr>'
							+'<td>&nbsp;</td>'
							+'<td align="right" style="padding-right:100px;"><input type="button" name="submit" value="Signup" class="button_class" onclick="signupNow();" /></td>'
						  +'</tr>'
						  +'<tr>'
							+'<td colspan="2" align="left" class="text6">By clicking sign up , you acknowledge that you have read and agree to the terms of the user agreement.</td>'
						  +'</tr>'
						  +'<tr>'
							+'<td colspan="2" align="left" class="text6">We promise to protect your privacy. Your email address will remain strictly confedential and will not be sold to anyone. Please see our privacy policy for more information about how we protect your privacy.</td>'
						  +'</tr>'
						+'</table>';
	}
	else
	{
		if (!(/^\s*$/).test(url) && url!='undefined')
		{
			// pull the page
			AjaxRequest.get({
				'url'				:url,
				'onLoading'			:function(req){ $(id).innerHTML="";},
				'onSuccess'			:function(req){
										$(id).innerHTML=req.responseText;
									},
				'onError'			:function(req){ closeContainerDiv(id); }
			})
		}
	}
}

function closeContainerDiv(id)
{
	// if the div doesn't exist
	if (!($(id)))
	{
		// just fail gracefully
		return;
	}

	// do final close-out
	doDivFinalClosing(id);
}

function doDivFinalClosing(id)
{
	if(!(/^\s*$/.test(id) || /^\s*undefined\s*$/.test(id)))
	{
		Element.hide(id+'Container');
		Element.hide(id+'Cover');
	}
	var arr=document.getElementsByTagName("Div");
	for(var i=arr.length-1;i>=0;i--)
	{
		if(arr[i].getAttribute("rel")=="Container")
		{
			if(arr[i].style.display!='none')
			{
				hideSelectBoxes();
				break;
			}
			else
			{
				showSelectBoxes();
			}
		}
		else
		{
			showSelectBoxes();
		}
	}
	if(!(/^\s*$/.test(id) || /^\s*undefined\s*$/.test(id)))
	{
		$(id+'Cover').parentNode.removeChild($(id+'Cover'));
		$(id+'Container').parentNode.removeChild($(id+'Container'));
	}
}

// Removes leading whitespaces
function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

// Removes leading and ending whitespaces
function trim( value ) {
	return LTrim(RTrim(value));
}

function editMyProfile()
{
	AjaxRequest.get({
		'url'				:WEB_ROOT+"ajax_request.php?mode=editMyProfile",
		'onLoading'			:function(req){ $('myAccountDetails').innerHTML="";},
		'onSuccess'			:function(req){
								$('myAccountDetails').innerHTML=req.responseText;
							},
		'onError'			:function(req){  }
	})
}

function saveMyProfile()
{
	AjaxRequest.get({
		'url'				:WEB_ROOT+"ajax_request.php?mode=saveMyProfile&first_name="+$F('first_name')+"&last_name="+$F('last_name')+"&email="+$F('email')+"&password="+$F('password'),
		'onLoading'			:function(req){ $('myAccountDetails').innerHTML="";},
		'onSuccess'			:function(req){
								if(req.responseText == "Email Error")
								{
									AjaxRequest.get({
										'url'				:WEB_ROOT+"ajax_request.php?mode=editMyProfile&first_name="+$F('first_name')+"&last_name="+$F('last_name')+"&email="+$F('email')+"&password="+$F('password'),
										'onLoading'			:function(req){ $('myAccountDetails').innerHTML="";},
										'onSuccess'			:function(req){
																$('myAccountDetails').innerHTML=req.responseText;
															},
										'onError'			:function(req){  }
									})
								}
								else if(req.responseText == "Username Error")
								{
									AjaxRequest.get({
										'url'				:WEB_ROOT+"ajax_request.php?mode=editMyProfile&first_name="+$F('first_name')+"&last_name="+$F('last_name')+"&email="+$F('email')+"&password="+$F('password'),
										'onLoading'			:function(req){ $('myAccountDetails').innerHTML="";},
										'onSuccess'			:function(req){
																$('myAccountDetails').innerHTML=req.responseText;
															},
										'onError'			:function(req){  }
									})
								}
								
								else
								{
									cancelEditMyProfile();
								}
							},
		'onError'			:function(req){  }
	})
}

function cancelEditMyProfile()
{
	AjaxRequest.get({
		'url'				:WEB_ROOT+"ajax_request.php?mode=displayMyProfile",
		'onLoading'			:function(req){ $('myAccountDetails').innerHTML="";},
		'onSuccess'			:function(req){
								$('myAccountDetails').innerHTML=req.responseText;
							},
		'onError'			:function(req){  }
	})
}

function show_login_pop()
{
	creatContainerDiv("loginDiv",WEB_ROOT+"ajax_request.php?mode=loginPop","Login");
}

function loginNow()
{
	if($F('email') == "")
	{
			
		alert("Please Enter The Email ID.");
		$('email').focus();
		return false;
	}
	if($F('email') !="")
	{
		
		
	var str=$F('email');
	var emailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|tv|biz))$/;
		if(!emailRe.test(str)) {
			alert("Please enter your valid email address.");
			$('email').focus();
			return false;
		}
   }
	
	if($F('password') == "")
	{
		alert("Please Enter The Password.");
		$('password').focus();
		return false;
	}
	
	var appendUrl = $("remember").checked == true ? "&remember=1" : "";
	AjaxRequest.post({
		'url'				:WEB_ROOT+"ajax_request.php?mode=loginNow&email="+$F('email')+"&password="+$F('password')+appendUrl,
		'onLoading'			:function(req){ },
		'onSuccess'			:function(req){
								if(req.responseText == "Login Error")
								{
									$('showMessageLogin').innerHTML='Invalid username or password';
								}
								else
								{
									location.href=req.responseText;
								}
							},
		'onError'			:function(req){  }
	})
}

function show_signup_pop()
{
	creatContainerDiv("signupDiv",WEB_ROOT+"ajax_request.php?mode=signupPop","Sign Up");
}

function signupNow()
{
	if($F('first_name') == "")
	{
		alert("Please Enter The First Name.");
		$('first_name').focus();
		return false;
	}
	if($F('last_name') == "")
	{
		alert("Please Enter The Last Name.");
		$('last_name').focus();
		return false;
	}
	if($F('email') == "")
	{
			
		alert("Please Enter The Email ID.");
		$('email').focus();
		return false;
	}
	if($F('email') !="")
	{
		
		
	var str=$F('email');
	var emailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|tv|biz))$/;
		if(!emailRe.test(str)) {
			alert("Please enter your valid email address.");
			$('email').focus();
			return false;
		}
   }
	
	if($F('password') == "")
	{
		alert("Please Enter The Password.");
		$('password').focus();
		return false;
	}
	if($F('r_password') == "")
	{
		alert("Please Re-enter The Password.");
		$('r_password').focus();
		return false;
	}
	if($F('password')!=$F('r_password'))
	{
		alert("Password and Retype Password doesn't match");
		return false;
	}
	AjaxRequest.post({
		'url'				:WEB_ROOT+"ajax_request.php?mode=signupNow&first_name="+$F('first_name')+"&last_name="+$F('last_name')+"&email="+$F('email')+"&password="+$F('password'),
		'onLoading'			:function(req){ },
		'onSuccess'			:function(req){
								if(req.responseText == "Email Error")
								{
									$('showMessageLogin').innerHTML='This email ID already exist.';
								}
								else if(req.responseText == "Username Error")
								{
									$('showMessageLogin').innerHTML='This username already exist.';
								}
								else
								{
									if($('writereviewLogin'))
									{
										alert("You have successfully completed signup process.");
										$('writereviewLogin').style.display = 'none';
										$('requiredLogin').value = '0';
										closeContainerDiv("signupDiv");
									}
									else
									{
										location.href=req.responseText;
									}
								}
							},
		'onError'			:function(req){}
	})
}

function clearErrorMessage()
{
	$('showMessageLogin').innerHTML = '';
}

function userImageUpload()
{
	creatContainerDiv("pictureDiv",WEB_ROOT+"ajax_request.php?mode=userImageUpload","Upload Pic");
}

function save_as_thumb(rid, type)
{
	AjaxRequest.post({
		'url'		:WEB_ROOT+"ajax_request.php?mode=save_as_thumb&rid="+rid+"&type="+type,
		'onLoading'	:function(req){ },
		'onSuccess'	:function(req){
						if(isNaN(req.responseText))
						{
							alert(req.responseText);
						}
						else
						{
							alert('Thanks for rating this review');
							if(type == "D")
								$('thumbs_dn').innerHTML = "("+req.responseText+")";
							else
								$('thumbs_up').innerHTML = "("+req.responseText+")";
						}
					},
		'onError'	:function(req){}
	})
}

function save_as_favorite(pid)
{
	AjaxRequest.post({
		'url'		:WEB_ROOT+"ajax_request.php?mode=save_as_favorite&pid="+pid,
		'onLoading'	:function(req){ },
		'onSuccess'	:function(req){
						alert(req.responseText);
						$('save_as_fav').innerHTML = "Saved to favourites";
					},
		'onError'	:function(req){}
	})
}

function DeleteFav(id)
{
	AjaxRequest.post({
		'url'		:WEB_ROOT+"ajax_request.php?mode=DeleteFav&id="+id,
		'onLoading'	:function(req){ },
		'onSuccess'	:function(req){
						alert('Do You really want to delete this property from your favorite list');
						$('del_fav_'+id).style.display = "none";
					},
		'onError'	:function(req){}
	})
}

/*function showHideSendToFriendBox()
{
	if($('send_to_friend_box').style.display == "none")
	{
		$('send_to_friend_box').style.display = "";
	}
	else
	{
		$('send_to_friend_box').style.display = "none";
	}
}*/

function showHideSendToFriendBox(pid,city,rid)
{
	//alert(pid);
	//alert(city);
	//alert(rid);
	creatContainerDiv("SendFriendDiv",WEB_ROOT+"ajax_request.php?mode=SendFriendPop&pid="+pid+"&city="+city+"&rid="+rid,"Send To Friend");
}

function SendNow()
{
	//alert($F('pid'))
	//alert($F('city'))
	//alert($F('rid'))
	
	if(trim($F('from_email')) == "")
	{
		alert("Please enter your email ID");	
		$('from_email').focus();
		return false;
	}
	if($F('from_email') !="")
	{
		var str=$F('from_email');
		var emailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|tv|biz))$/;
		if(!emailRe.test(str)) {
			alert("Please enter valid email address.");
			$('from_email').focus();
			return false;
		}
   }
	if(trim($F('to_email')) == "")
	{
		alert("Please enter your friend's email ID");	
		$('to_email').focus();
		return false;
	}
	if($F('to_email') !="")
	{
		var str=$F('to_email');
		var emailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|tv|biz))$/;
		if(!emailRe.test(str)) {
			alert("Please enter valid email address.");
			$('to_email').focus();
			return false;
		}
   }
	if(trim($F('friend_message')) == "")
	{
		alert("Please enter your message");	
		$('friend_message').focus();
		return false;
	}
	
	AjaxRequest.post({
		//'url'		:WEB_ROOT+"ajax_request.php?mode=send_to_friend&from_email="+$F('from_email')+"&to_email="+$F('to_email')+"&friend_message="+$F('friend_message'),
		'url'		:WEB_ROOT+"ajax_request.php?mode=send_to_friend&from_email="+$F('from_email')+"&to_email="+$F('to_email')+"&friend_message="+$F('friend_message')+"&pid="+$F('pid')+"&city="+$F('city')+"&rid="+$F('rid'),
		'onLoading'	:function(req){ },
		'onSuccess'	:function(req){
						//alert('Your suucessfully send this property to your friend.');
						//$('send_to_friend_box').style.display = "none";
						if(req.responseText == "Message Sent")
						{
							location.href = WEB_ROOT+"message.php?s=sf";
						}
					},
		'onError'	:function(req){}
	})
}

function checkLoginWriteReview()
{
	if(checkFormSubmit())
	{
		if($('requiredLogin').value == "1")
		{
			AjaxRequest.post({
				'url'				:WEB_ROOT+"ajax_request.php?mode=loginNow&email="+$F('email_r')+"&password="+$F('password_r'),
				'onLoading'			:function(req){ },
				'onSuccess'			:function(req){
										if(req.responseText == "Login Error")
										{
											alert('Invalid username or password');
										}
										else
										{
											writeReviewSubmit();
										}
									},
				'onError'			:function(req){  }
			})
		}
		else
		{
			writeReviewSubmit();
		}
	}
}

function showSuggestBox()
{
	var val = $F('search_name_city');
	
	AjaxRequest.post({
		'url'				:WEB_ROOT+"ajax_request.php?mode=showSuggestBox&keyword="+val,
		'onLoading'			:function(req){ },
		'onSuccess'			:function(req){
								str = req.responseText;
								responseTextArr = str.split("##$$##");
								$('restaurantSuggestBox').innerHTML = responseTextArr[1];
								changeDivHeight(responseTextArr[0]);
							},
		'onError'			:function(req){  }
	})
}