// These are the variables; you can change these if you want
var expDays = 9999;  // How many days to remember the setting
var standardStyle = '2'; // This is the number of your standard style sheet; this will be used when the user did not do anything.
var nameOfCookie = 'switchstyle'; // This is the name of the cookie that is used.
var TIMER = 5; // Globals for dialog box
var SPEED = 10;
var WRAPPER = 'external-container';

// These are the names of your different .css files; use the name exactly as on your Web site
var ScreenCSS_1 = 'pink.css';
var ScreenCSS_2 = 'blue.css';
var ScreenCSS_3 = 'yellow.css';
var ScreenCSS_4 = 'green.css';
var ScreenCSS_5 = 'grey.css';

// This is the main function that does all the work
function switchStyleOfUser(){
	var fontSize = GetCookie(nameOfCookie);
	if (fontSize == null) {
		fontSize = standardStyle;
	}
	if (fontSize == "1") { document.write('<link rel="stylesheet" type"text/css" href="css/colors/'+ScreenCSS_1+'" media="screen">'); }
	if (fontSize == "2") { document.write('<link rel="stylesheet" type"text/css" href="css/colors/'+ScreenCSS_2+'" media="screen">'); }
	if (fontSize == "3") { document.write('<link rel="stylesheet" type"text/css" href="css/colors/'+ScreenCSS_3+'" media="screen">'); }
	if (fontSize == "4") { document.write('<link rel="stylesheet" type"text/css" href="css/colors/'+ScreenCSS_4+'" media="screen">'); }
	if (fontSize == "5") { document.write('<link rel="stylesheet" type"text/css" href="css/colors/'+ScreenCSS_5+'" media="screen">'); }

	var fontSize = "";
	return fontSize;
}

// This will call the main function.  Do not remove this, because otherwise this script will do nothing...
document.write(switchStyleOfUser());

var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

// Function to get the settings of the user
function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

// Function to get the settings of the user
function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

// Function to remember the settings
function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}

// Function to remove the settings
function DeleteCookie (name) {
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = GetCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

// This function is used when the user gives his selection
function doRefresh(){
	location.reload();
}

function cookieSet(){
	if($('remember_me').checked==true){
		var login_name=$('log-in1').value;
		var login_pass=$('log-in2').value;
		SetCookie('loginname',login_name);
		SetCookie('loginpass',login_pass);
	} else {
		DeleteCookie('loginname');
		DeleteCookie('loginpass');
	}
}

function retriveUser()
{
	var val=GetCookie('loginname');
	var val2=GetCookie('loginpass');
	var login_name=$('log-in1').value;
	if(login_name) {
		// do nothing
	} else if(val==null) {
		$('remember_me').checked=false;
		$('log-in1').value="";
		$('log-in2').value="";
	} else { 
		$('remember_me').checked=true;
		$('log-in1').value=val;
		$('log-in2').value=val2;
	}
}

//---------------------------------------------------------------------------------------------------------------
// Another Common Functions
//---------------------------------------------------------------------------------------------------------------
function setOp(op,extra){
		document.opForm.op.value=op;
		document.opForm.extra.value=extra;
		document.opForm.submit();
}

new Ajax.PeriodicalUpdater('', 'ajax.php?af=updateUser', {   method: 'get', frequency: 50, decay: 1 }); 

//--------------------------------------------------------------------------------------------------------------------
// Form Validator 
//--------------------------------------------------------------------------------------------------------------------

function validate(formName) {

	var elm,id,name,lname,value,retvalue,element,label;
	var emailFilter=/^.+@.+\..{2,3}$/;
	retvalue = true;
	elementsForms = document.forms[formName].getElementsByTagName("input"); 
	for (var intCounter = 0; intCounter < elementsForms.length; intCounter++) 
	{ 
		elm = elementsForms[intCounter];
		name = elm.getAttribute("name");
		id = elm.className;
		lname = 'req_'+name;
		element = document.forms[formName].elements[name];
		label = $(lname);
		if(id == 'req_value') {
			if(element.value == '') {
				label.className="error";
				retvalue = false;
			} else {
				label.className="";
			}
		} else if(id == 'req_digit') {
			if(element.value == '') {
				label.className="error";
				retvalue = false;
			} else if(isNaN(element.value)) {
				label.className="error";
				retvalue = false;
			} else {
				label.className="";
			}
		} else if(id == 'req_file') {
			if(element.value == '' && document.forms[formName].elements[name+'_old'].value == '') {
				label.className="error";
				retvalue = false;
			} else {
				label.className="";
			}
		} else if(id == 'req_email') {
			element.value = element.value.replace(/^\s+|\s+$/g,""); // trim the white spces
			if(element.value == '') {
				label.className="error";
				retvalue = false;
			} else if (!(emailFilter.test(element.value))) {
				label.className="error";
				retvalue = false;
			} else {
				label.className="";
			}
		} else if(id == 'req_password') {
			label_pwd_agn = $('req_password_again');
			if(element.value == '') {
				label.className="error";
				label_pwd_agn.setAttribute("class","error");
				retvalue = false;
			} else if(element.value.length < 4) {
				label.innerHTML = 'Weak Password :';
				label.className="error";
				label_pwd_agn.setAttribute("class","error");
				retvalue = false;
			} else if(element.value	!= 	document.forms[formName].password_again.value) {
				label.innerHTML = 'Passwords differs :';
				label.className="error";
				label_pwd_agn.setAttribute("class","error");
				retvalue = false;
			} else {
				label.innerHTML = 'Password :';
				label.className="";
				label_pwd_agn.setAttribute("class","");
			}
		}
	}
	return retvalue;
}
function closeAccount(){
	var closeReson = $('closeReason').value;
	if(closeReson == ''){
		$('req_answer[closeReason]').className="error";
		return false;
	}
	else{
		$('req_answer[closeReason]').className="";
		return true;	
	}
}

//---------------------------------------------------------------------------------------------------------------------------
// Dialog Box functions
//---------------------------------------------------------------------------------------------------------------------------
// calculate the current window width //
function pageWidth() {
  return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

// calculate the current window height //
function pageHeight() {
  return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}

// calculate the current window vertical offset //
function topPosition() {
  return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}

// calculate the position starting at the left of the window //
function leftPosition() {
  return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}

// build/show the dialog box, populate the data and call the fadeDialog function //
function showDialog(id) {

  var dialog;
  var dialogcontent;
  var dialogmask;
  if(!$('dialogBox')) {
    dialog = document.createElement('div');
    dialog.id = 'dialogBox';
    dialogcontent = document.createElement('div');
    dialogcontent.id = 'dialog-content';
    dialogmask = document.createElement('div');
    dialogmask.id = 'dialog-mask';
    document.body.appendChild(dialogmask);
    document.body.appendChild(dialog);
    dialog.appendChild(dialogcontent);;
    dialogmask.setAttribute('onclick','hideDialog()');
    dialogmask.onclick = hideDialog;
  } else {
    dialog = $('dialogBox');
    dialogcontent = $('dialog-content');
    dialogmask = $('dialog-mask');
    dialogmask.style.visibility = "visible";
    dialog.style.visibility = "visible";
  }
  dialog.style.opacity = .00;
  dialog.style.filter = 'alpha(opacity=0)';
  dialog.alpha = 0;
  var width = pageWidth();
  var height = pageHeight();
  var left = leftPosition();
  var top = topPosition();
  var dialogwidth = dialog.offsetWidth;
  var dialogheight = dialog.offsetHeight;
  var topposition = top + (height / 2) - (dialogheight / 2);
  var leftposition = left + (width / 2) - (dialogwidth / 2);
  dialog.style.top = topposition + "px";
  dialog.style.left = leftposition + "px";
  dialogcontent.className = 'dialogcontent';
  var content = $(WRAPPER);
  dialogmask.style.height = content.offsetHeight + 'px';
  dialog.timer = setInterval("fadeDialog(1)", TIMER);
  dialogAjax(id) // call Ajax dunction to laod
  return false;
}

function repositionDialog() {
    dialog = $('dialogBox');
	var width = pageWidth();
	var left = leftPosition();
	var dialogwidth = dialog.offsetWidth;
	var leftposition = left + (width / 2) - (dialogwidth / 2);
	dialog.style.left = leftposition + "px";
}

// hide the dialog box //
function hideDialog() {
  var dialog = $('dialogBox');
  clearInterval(dialog.timer);
  dialog.timer = setInterval("fadeDialog(0)", TIMER);
}

// fade-in the dialog box //
function fadeDialog(flag) {
  if(flag == null) {
    flag = 1;
  }
  var dialog = $('dialogBox');
  var value;
  if(flag == 1) {
    value = dialog.alpha + SPEED;
  } else {
    value = dialog.alpha - SPEED;
  }
  dialog.alpha = value;
  dialog.style.opacity = (value / 100);
  dialog.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(dialog.timer);
    dialog.timer = null;
    document.body.setAttribute('onResize','repositionDialog()');
	document.body.onResize = "repositionDialog";
} else if(value <= 1) {
    dialog.style.visibility = "hidden";
    $('dialog-mask').style.visibility = "hidden";
    clearInterval(dialog.timer);
	window.onResize = "";
  }
}


function dialogAjax(id) {
	
	new Ajax.Request('ajax.php?af=dialogAjax&key='+id, {
		onLoading:function(transport) {
			$('dialog-content').innerHTML=$('loadingAjaxContent').innerHTML;
		},					 
		onSuccess: function(transport) {
			$('dialog-content').innerHTML=transport.responseText;
		}
	});
}

/* 
	SearchField 
	written by Alen Grakalic, provided by Css Globe (cssglobe.com)
	please visit http://cssglobe.com/post/1202/style-your-websites-search-field-with-jscss/ for more info
*/

this.searchfield = function(){
	
	// CONFIG 
	// this is id of the search field you want to add this script to. 
	// You can use your own id just make sure that it matches the search field in your html file.
	var id = "search";

	// Text you want to set as a default value of your search field.
	//var defaultText = "Search areapal";
	var defaultText;
	text=$('search_text').value;
	if(text=="")
		defaultText="Search areapal";
	else
		defaultText=text;
	// set to either true or false
	// when set to true it will generate search suggestions list for search field based on content of variable below
	var suggestion = false;
	
	// static list of suggestion options, separated by comma
	// replace with your own
	var suggestionText = "search,areapal,something text"; 
	
	// END CONFIG (do not edit below this line, well unless you really, really want to change something :) )

	var field = $(id);	
	var classInactive = "sf_inactive";
	var classActive = "sf_active";
	var classText = "sf_text";
	var classSuggestion = "sf_suggestion";
	this.safari = ((parseInt(navigator.productSub)>=20020000)&&(navigator.vendor.indexOf("Apple Computer")!=-1));
	if(field && !safari){
		field.value = defaultText;
		field.c = field.className;		
		field.className = field.c + " " + classInactive;
		field.onfocus = function(){
			this.className = this.c + " "  + classActive;
			this.value = (this.value == "" || this.value == defaultText) ?  "" : this.value;
		};
		field.onblur = function(){
			this.className = (this.value != "" && this.value != defaultText) ? this.c + " " +  classText : this.c + " " +  classInactive;
			this.value = (this.value != "" && this.value != defaultText) ?  this.value : defaultText;
			clearList();
		};
		if (suggestion){
			
			var selectedIndex = 0;
						
			field.setAttribute("autocomplete", "off");
			var div = document.createElement("div");
			var list = document.createElement("ul");
			list.style.display = "none";
			div.className = classSuggestion;
			list.style.width = field.offsetWidth + "px";
			div.appendChild(list);
			field.parentNode.appendChild(div);	

			field.onkeypress = function(e){
				
				var key = getKeyCode(e);
		
				if(key == 13){ // enter
					selectList();
					selectedIndex = 0;
					return false;
				};	
			};
				
			field.onkeyup = function(e){
			
				var key = getKeyCode(e);
		
				switch(key){
				case 13:
					return false;
					break;			
				case 27:  // esc
					field.value = "";
					selectedIndex = 0;
					clearList();
					break;				
				case 38: // up
					navList("up");
					break;
				case 40: // down
					navList("down");		
					break;
				default:
					startList();			
					break;
				};
			};
			
			this.startList = function(){
				var arr = getListItems(field.value);
				if(field.value.length > 0){
					createList(arr);
				} else {
					clearList();
				};	
			};
			
			this.getListItems = function(value){
				var arr = new Array();
				var src = suggestionText;
				var src = src.replace(/, /g, ",");
				var arrSrc = src.split(",");
				for(i=0;i<arrSrc.length;i++){
					if(arrSrc[i].substring(0,value.length).toLowerCase() == value.toLowerCase()){
						arr.push(arrSrc[i]);
					};
				};				
				return arr;
			};
			
			this.createList = function(arr){				
				resetList();			
				if(arr.length > 0) {
					for(i=0;i<arr.length;i++){				
						li = document.createElement("li");
						a = document.createElement("a");
						a.href = "javascript:void(0);";
						a.i = i+1;
						a.innerHTML = arr[i];
						li.i = i+1;
						li.onmouseover = function(){
							navListItem(this.i);
						};
						a.onmousedown = function(){
							selectedIndex = this.i;
							selectList(this.i);		
							return false;

						};					
						li.appendChild(a);
						list.setAttribute("tabindex", "-1");
						list.appendChild(li);	
					};	
					list.style.display = "block";				
				} else {
					clearList();
				};
			};	
			
			this.resetList = function(){
				var li = list.getElementsByTagName("li");
				var len = li.length;
				for(var i=0;i<len;i++){
					list.removeChild(li[0]);
				};
			};
			
			this.navList = function(dir){			
				selectedIndex += (dir == "down") ? 1 : -1;
				li = list.getElementsByTagName("li");
				if (selectedIndex < 1) selectedIndex =  li.length;
				if (selectedIndex > li.length) selectedIndex =  1;
				navListItem(selectedIndex);
			};
			
			this.navListItem = function(index){	
				selectedIndex = index;
				li = list.getElementsByTagName("li");
				for(var i=0;i<li.length;i++){
					li[i].className = (i==(selectedIndex-1)) ? "selected" : "";
				};
			};
			
			this.selectList = function(){
				li = list.getElementsByTagName("li");	
				a = li[selectedIndex-1].getElementsByTagName("a")[0];
				field.value = a.innerHTML;
				clearList();
			};			
			
		};
	};
	
	this.clearList = function(){
		if(list){
			list.style.display = "none";
			selectedIndex = 0;
		};
	};		
	this.getKeyCode = function(e){
		var code;
		if (!e) var e = window.event;
		if (e.keyCode) code = e.keyCode;
		return code;
	};
	
};

// script initiates on page load. 

this.addEvent = function(obj,type,fn){
	if(obj.attachEvent){
		obj['e'+type+fn] = fn;
		obj[type+fn] = function(){obj['e'+type+fn](window.event );}
		obj.attachEvent('on'+type, obj[type+fn]);
	} else {
		obj.addEventListener(type,fn,false);
	};
};
addEvent(window,"load",searchfield);





function ProfileSettingShowHide(id){
		if(id == "1"){
			document.getElementById("ProfilePersonalSetting").style.display= "block";
			document.getElementById("ShowButton").style.display= "none";
			document.getElementById("HideButton").style.display= "block";
		}else{
			document.getElementById("ProfilePersonalSetting").style.display="none";
			document.getElementById("ShowButton").style.display= "block";
			document.getElementById("HideButton").style.display= "none";
		}
}



function ShowAppGarageToogle(){
		
		if($('AppSettingsToogle').style.display == "block"){
			$('AppSettingsToogle').style.display = "none";
		}
		$('AppGarageToogle').style.display 	 = "block";
}

function ShowAppSettingsToogle(){

		if($('AppGarageToogle').style.display == "block"){
			$('AppGarageToogle').style.display = "none";
		}
		$('AppSettingsToogle').style.display = "block";

}

function HideToogle(id){
	if($(id).style.display == "block"){
		$(id).style.display = "none";
	}else{
		$(id).style.display = "none";
	}
}



/*Start Code Tool Tip Added by Anega Prabhu on 04.05.09 for  docbar tool tip display Purpose*/
var offsetfromcursorX=13 //Customize x offset of tooltip
var offsetfromcursorY=10 //Customize y offset of tooltip

var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth, thecolor){
	var tipobj=$("dhtmltooltip");
	var pointerobj=$("dhtmlpointer");
	
	if (ns6||ie){
		if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
		if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
		tipobj.innerHTML=thetext
		enabletip=true
		return false
	}
}

function positiontip(e){
	if (enabletip){
		var nondefaultpos=false
		var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
		//Find out how close the mouse is to the corner of the window
		var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
		var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20
		
		var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
		var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY
		
		var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000
		
		var tipobj=$("dhtmltooltip");
		var pointerobj=$("dhtmlpointer");

		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<tipobj.offsetWidth){
			//move the horizontal position of the menu to the left by it's width
			tipobj.style.left=curX-tipobj.offsetWidth+"px"
			nondefaultpos=true
		} else if (curX<leftedge) {
			tipobj.style.left="5px"
		} else {
			//position the horizontal position of the menu where the mouse is positioned
			tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
			pointerobj.style.left=curX+offsetfromcursorX+"px"
		}
		
		//same concept with the vertical position
		if (bottomedge<tipobj.offsetHeight){
			tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
			nondefaultpos=true
		} else {
			tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
			pointerobj.style.top=curY+offsetfromcursorY+"px"
		}
		tipobj.style.visibility="visible"
		if (!nondefaultpos)
			pointerobj.style.visibility="visible"
		else
			pointerobj.style.visibility="hidden"
	}
}

function hideddrivetip(){
	var tipobj=$("dhtmltooltip");
	var pointerobj=$("dhtmlpointer");	
	if (ns6||ie){
		enabletip=false
		tipobj.style.visibility="hidden"
		pointerobj.style.visibility="hidden"
		tipobj.style.left="-1000px"
		tipobj.style.backgroundColor=''
		tipobj.style.width=''
	}
}

document.onmousemove=positiontip
/*End Code Tool Tip Added by Anega Prabhu on 04.05.09 for  docbar tool tip display Purpose*/

/*Start code for Adv Search by anega prabhu on 06.07.09*/
function AdvSearch(){
			$('AdvSearch').style.display = "block";
}
function HideAdvSearch(){
			$('AdvSearch').style.display = "none";
}



function loadCity(key) {
	$('city').style.display = "block";
	new Ajax.Request('ajax.php?af=loadCityforSearch&key='+key, {
		 onSuccess: function(transport) { 
		 	 var respose = transport.responseText;
			 $('cityDropDown').innerHTML=respose;
		 } 	 
	}); 
}

function loadArea(key) {
	$('area').style.display = "block";
	new Ajax.Request('ajax.php?af=loadAreaforSearch&key='+key, {
		 onSuccess: function(transport) { 
		 	 var respose = transport.responseText;
			 $('areaDropDown').innerHTML=respose;
		 } 
	}); 
}

function loadState(key) {
	$('state').style.display = "block";
	new Ajax.Request('ajax.php?af=loadStateforSearch&key='+key, {
		 onSuccess: function(transport) { 
		 	 var respose = transport.responseText;
			$('stateDropDown').innerHTML=respose;
			 loadCity($('usr_state').value);
		 } 	 
	}); 
}
/*Ends code for Adv Search by anega prabhu on 06.07.09*/

//for popup window by rajaraman
function openPopUp() {

  var dialog;
  var dialogcontent;
  var dialogmask;
  if(!$('dialogBox')) {
    dialog = document.createElement('div');
    dialog.id = 'dialogBox';
    dialogcontent = document.createElement('div');
    dialogcontent.id = 'dialog-content';
    dialogmask = document.createElement('div');
    dialogmask.id = 'dialog-mask';
    document.body.appendChild(dialogmask);
    document.body.appendChild(dialog);
    dialog.appendChild(dialogcontent);;
    dialogmask.setAttribute('onclick','hideDialog()');
    dialogmask.onclick = hideDialog;
  } else {
    dialog = $('dialogBox');
    dialogcontent = $('dialog-content');
    dialogmask = $('dialog-mask');
    dialogmask.style.visibility = "visible";
    dialog.style.visibility = "visible";
  }
  dialog.style.opacity = .00;
  dialog.style.filter = 'alpha(opacity=0)';
  dialog.alpha = 0;
  var width = pageWidth();
  var height = pageHeight();
  var left = leftPosition();
  var top = topPosition();
  var dialogwidth = dialog.offsetWidth;
  var dialogheight = dialog.offsetHeight;
  var topposition = top + (height / 2) - (dialogheight / 2);
  var leftposition = left + (width / 2) - (dialogwidth / 2);
//  dialog.style.top = topposition + "px";
  dialog.style.top = "27px";//added by rajaraman
  dialog.style.left = leftposition + "px";
  dialogcontent.className = 'dialogcontent';
  var content = $(WRAPPER);
  dialogmask.style.height = content.offsetHeight + 'px';
  dialog.timer = setInterval("fadeDialog(1)", TIMER);
  popUpAjax() // call Ajax dunction to laod
  return false;
}



function openPopUpHome() {
	var standardStyle = '2'; // This is the number of your standard style sheet; this will be used when the user did not do anything.
	var nameOfCookie = 'switchstyle'; // This is the name of the cookie that is used.
	var TIMER = 5; // Globals for dialog box
	var SPEED = 10;
	var WRAPPER = 'external-containerhome';

  var dialog;
  var dialogcontent;
  var dialogmask;
  if(!$('dialogBox')) {
    dialog = document.createElement('div');
    dialog.id = 'dialogBox';
    dialogcontent = document.createElement('div');
    dialogcontent.id = 'dialog-content';
    dialogmask = document.createElement('div');
    dialogmask.id = 'dialog-mask';
    document.body.appendChild(dialogmask);
    document.body.appendChild(dialog);
    dialog.appendChild(dialogcontent);;
    dialogmask.setAttribute('onclick','hideDialog()');
    dialogmask.onclick = hideDialog;
  } else {
    dialog = $('dialogBox');
    dialogcontent = $('dialog-content');
    dialogmask = $('dialog-mask');
    dialogmask.style.visibility = "visible";
    dialog.style.visibility = "visible";
  }
  dialog.style.opacity = .00;
  dialog.style.filter = 'alpha(opacity=0)';
  dialog.alpha = 0;
  var width = pageWidth();
  var height = pageHeight();
  var left = leftPosition();
  var top = topPosition();
  var dialogwidth = dialog.offsetWidth;
  var dialogheight = dialog.offsetHeight;
  var topposition = top + (height / 2) - (dialogheight / 2);
  var leftposition = left + (width / 2) - (dialogwidth / 2);
//  dialog.style.top = topposition + "px";
  dialog.style.top = "27px";//added by rajaraman
  dialog.style.left = leftposition + "px";
  dialogcontent.className = 'dialogcontent';
  var content = $(WRAPPER);
  dialogmask.style.height = content.offsetHeight + 'px';
  dialog.timer = setInterval("fadeDialog(1)", TIMER);
  popUpAjax() // call Ajax dunction to laod
  return false;
}

function popUpAjax(){
	new Ajax.Request('popUpAjax.php?key=up', {
		onLoading:function(transport) {
			$('dialog-content').innerHTML=$('loadingAjaxContent').innerHTML;
		},					 
		onSuccess: function(transport) {
			$('dialog-content').innerHTML=transport.responseText;
		}
	});
}


function showDialogHome(id) {
	var standardStyle = '2'; // This is the number of your standard style sheet; this will be used when the user did not do anything.
	var nameOfCookie = 'switchstyle'; // This is the name of the cookie that is used.
	var TIMER = 5; // Globals for dialog box
	var SPEED = 10;
	var WRAPPER = 'external-containerhome';

  var dialog;
  var dialogcontent;
  var dialogmask;
  if(!$('dialogBox')) {
    dialog = document.createElement('div');
    dialog.id = 'dialogBox';
    dialogcontent = document.createElement('div');
    dialogcontent.id = 'dialog-content';
    dialogmask = document.createElement('div');
    dialogmask.id = 'dialog-mask';
    document.body.appendChild(dialogmask);
    document.body.appendChild(dialog);
    dialog.appendChild(dialogcontent);;
    dialogmask.setAttribute('onclick','hideDialog()');
    dialogmask.onclick = hideDialog;
  } else {
    dialog = $('dialogBox');
    dialogcontent = $('dialog-content');
    dialogmask = $('dialog-mask');
    dialogmask.style.visibility = "visible";
    dialog.style.visibility = "visible";
  }
  dialog.style.opacity = .00;
  dialog.style.filter = 'alpha(opacity=0)';
  dialog.alpha = 0;
  var width = pageWidth();
  var height = pageHeight();
  var left = leftPosition();
  var top = topPosition();
  var dialogwidth = dialog.offsetWidth;
  var dialogheight = dialog.offsetHeight;
  var topposition = top + (height / 2) - (dialogheight / 2);
  var leftposition = left + (width / 2) - (dialogwidth / 2);
  dialog.style.top = topposition + "px";
  dialog.style.left = leftposition + "px";
  dialogcontent.className = 'dialogcontent';
  var content = $(WRAPPER);
  dialogmask.style.height = content.offsetHeight + 'px';
  dialog.timer = setInterval("fadeDialog(1)", TIMER);
  dialogAjax(id) // call Ajax function to laod
  return false;
}


function HideLayermain(){
	if($('sgsthide').style.value != "1" &&  $('hint').style.display == "none"){
			
			$('hint').style.display = "none";
			
	}else if($('hint').style.display == "block" && $('sgsthide').style.value == ""){
		$('hint').style.display = "none";
	}
	if($('Smileys').style.display == "block" && $('smileyhidden').style.value != "1"){
		$('Smileys').style.display = "none";
	}
	$('sgsthide').style.value = "";
	$('smileyhidden').style.value = "";
}
//for popup window by rajaraman


function getBusiness(bId,userid,PUId){
         new Ajax.Request('ajaxhome.php?af=getBusiness&key='+bId+'&UserId='+userid+'&PUserId='+PUId, {
		onLoading:function(transport) {
//			$('Tempcommentid').innerHTML=$('loadingAjaxContent').innerHTML;
		},					 
		onSuccess: function(transport) {
		//alert(transport.responseText);
		$('businesspage').innerHTML=transport.responseText;
		$('businessmain').style.display = "none";
		}
	});
}


function getBusinessAd(bId,userid,PUId){
         new Ajax.Request('../../ajaxhome.php?af=getBusinessAd&key='+bId+'&UserId='+userid+'&PUserId='+PUId, {
		onLoading:function(transport) {
			$('Tempcommentid').innerHTML=$('loadingAjaxContent').innerHTML;
		},					 
		onSuccess: function(transport) {
		//alert(transport.responseText);
		$('businesspagecity').innerHTML=transport.responseText;
		$('businessmain').style.display = "none";
		}
	});
}



/*Starts Functions Starts for Suggest Api by anega prabhu*/
function ApiPopUpHome(userid,areaname) {
	$('Apisuggest').style.display = "block";
  	return false;
}

function ApiPopUpNormal(userid,areaname) {
	$('Apisuggest').style.display = "block";
  	return false;
}
function ApiClose(userid,areaname) {
	$('Apisuggest').style.display = "none";
  	return false;
}



		function validateAnswer(){
			var answer=$('txtApianswer').value;
			if(trim(answer)==''){
					$('txtApianswer').focus();
					$('answererror').style.display = "block";
					return false;	
			}else{
				document.apiAnswer.submit();
			}
		}

		function validateQuestion(){
			var question=$('question').value;
			if(trim(question)==''){
					$('question').focus();
					$('questionerror').style.display = "block";
					return false;	
			}else{
				document.apiQuestion.submit();
			}
		}


		function trim(str) {
			return ltrim(rtrim(str));
		}
		
		function ltrim(str) {
			for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
			return str.substring(k, str.length);
		}

		function rtrim(str) {
			for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
			return str.substring(0,j+1);
		}

		function isWhitespace(charToCheck) {
			var whitespaceChars = " \t\n\r\f";
			return (whitespaceChars.indexOf(charToCheck) != -1);
		}
		
		
	  function validateHomeAnswer(){
			var answer=$('Homeanswer').value;
			if(trim(answer)==''){
					$('Homeanswer').focus();
					$('Homeanswererror').style.display = "block";
					return false;	
			}else{
				document.HomeapiAnswer.submit();
			}
		}

		function validateHomeQuestion(){
			var question=$('Homequestion').value;
			if(trim(question)==''){
					$('Homequestion').focus();
					$('Homequestionerror').style.display = "block";
					return false;	
			}else{
				document.HomeapiQuestion.submit();
			}
		}
/*Ends Functions for Suggest Api by anega prabhu*/
	
	/*Logout Ad by anega prabhu on 18.11.09*/
	function OpenAdwindow(){
		window.open("logoutad.html",'welcome','width=240,height=400,toolbar=no,status=no,location=no,menubar=no,directories=no,scrollbars=no,resizable=no');
	}


function facebook_onlogin_ready() {
  // In this app, we redirect the user back to index.php. The server will read
  // the cookie and see that the user is logged in, and will deliver a new page
  // with content appropriate for a logged-in user.
  //
  // However, a more complex app could use this function to do AJAX calls
  // and/or in-place replacement of page contents to avoid a full page refresh.
 // 
 facebook_prompt_permission("email");
}

function facebook_prompt_permission(email, callbackFunc){
    // Check if user has permission, if not invoke dialog.
    FB.ensureInit(function() {
            //check is user already granted for this permission or not
            FB.Facebook.apiClient.users_hasAppPermission(email,
            function(result) {
                // prompt offline permission
                if (result == 0) {
                    // render the permission dialog
                    FB.Connect.showPermissionDialog(email,
                    function(result){
                        if (null == result)
                            //alert('no permissons granted');
							refresh_page();
                        else
                           // alert('permissions ' + result);
						   refresh_page();
                    }, true, null);
                } else {
                    // permission already granted.
					// alert("refrest last");
					refresh_page();
					callbackFunc(true);
                }
            });
    });
}

/*
 * Do a page refresh after login state changes.
 * This is the easiest but not the only way to pick up changes.
 * If you have a small amount of Facebook-specific content on a large page,
 * then you could change it in Javascript without refresh.
 */
function refresh_page() {
  window.location = 'home.php';
}

