/**
 * Home page inline scripts start.
 */
function forumLogout() {
	window.location = "FormFiller.do?opt=logout";
}
/** Home page inline scripts End. Ticker - Ajax js Start. */
// Creating Ajax Object Based on Browser
function GetXmlHttpObject() {
	var xmlHttp = null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	if (xmlHttp == null) {
		alert("Your browser does not support AJAX!");
		return null;
	}
		
	return xmlHttp;
}
// Utility Method - Trim the Sting in Java Script
function trim(str) {
	str = str.replace(/^\s+/g, "");// strip leading
	return str.replace(/\s+$/g, "");// strip trailing
}
// JavaScript Document used in HomeNews.jsp
function SetTabStyle(column, leftcontent) {
	var masterTable = document.getElementById(leftcontent);
	tableList = masterTable.getElementsByTagName('TABLE');
	var lengthh = tableList.length;
	// alert('The table length '+ lengthh );
	for (i = 0; i < lengthh; i++) {
		oTable = tableList.item(i);
		// Retrieve the rows collection for the table.
		var aRows = oTable.rows;
		// Retrieve the cells collection for the first row.
		var aCells = aRows[0].cells;
		var columnTab = column + "Tab";
		var anchorTag = document.getElementById("A_" + oTable.id);
		if (oTable.id == columnTab) {
			aCells[0].className = "tabl_bg";
			aCells[1].className = "tabm_bg";
			aCells[2].className = "tabr_bg";
		} else {
			aCells[0].className = "tabl_nbg";
			aCells[1].className = "tabm_nbg";
			aCells[2].className = "tabr_nbg";
		}
	}
}
function showLayer(id) {
	document.getElementById(id).style.display = 'block';
	document.getElementById("news1").style.display = 'block'
	document.getElementById("news2").style.display = 'none'
	document.getElementById("news3").style.display = 'none'
	document.getElementById("news4").style.display = 'none'
	document.getElementById("news5").style.display = 'none'

}
function showLayer1(id) {
	document.getElementById(id).style.display = 'block';
	document.getElementById("news6").style.display = 'block'
	document.getElementById("news7").style.display = 'none'
	document.getElementById("news8").style.display = 'none'
	document.getElementById("news9").style.display = 'none'
	document.getElementById("news10").style.display = 'none'

}
function hideLayer(id) {
	document.getElementById(id).style.display = 'none';
}


function getErrorString(key) {
	// alert("Method get Error String Called");
	var pollErrResHttp = GetXmlHttpObject();
	var url = ctxtPath+"/jsp/getErrorString.jsp?KEY=" + key + "&lang=" + lang;
	//alert(url);
	pollErrResHttp.onreadystatechange = getErrStr(pollErrResHttp);
	pollErrResHttp.open("POST", url, true);
	pollErrResHttp.send(null);
}
function getErrStr(pollErrResHttp) {
	if (pollErrResHttp.readyState == 4) {
		var popHTML = trim(pollErrResHttp.responseText);
		if (popHTML != "") {
			// Just show the response text using utility dojo function.
		} else {
			popHTML = 'Missing/Invalid Field Value,Please Check!';
		}

		displayErrorPopupDialog(popHTML);
	} // end of main if
}
function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + date.toGMTString();
	} else
		expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
	  var nameSG = name + "=";
	  var nuller = '';
	  if (document.cookie.indexOf(nameSG) == -1)
	    return nuller;
	  var ca = document.cookie.split(';');
	  for(var i=0; i<ca.length; i++) {
		  var c = ca[i];
		  while (c.charAt(0)==' ') {
			  c = c.substring(1,c.length);
		  }
		  if (c.indexOf(nameSG) == 0) {
			  return c.substring(nameSG.length,c.length);  
		  }
	  }
	  return null; 
}

/** tab js end. poll js start. */
var pollHttpReq = GetXmlHttpObject();
function submitPoll(pollId, polPopTitle) {
	loadingWaitDialog();
	var pollOptionValue;
	var j = document.userPollForm.pollOption.length;
	var count = 0;
	var url;
	document.userPollForm.txnID.value = "4001";
	var txnID = document.userPollForm.txnID.value;
	for (i = 0; i < j; i++) {
		if (document.userPollForm.pollOption[i].checked) {
			pollOptionValue = document.userPollForm.pollOption[i].value;
			count++;
			url = "txnController?txnID=" + txnID + "&pollOption="
					+ pollOptionValue + "&pollID=" + pollId + "&lang=" + lang;
			pollHttpReq.open("GET", url, true);
			pollHttpReq.onreadystatechange = function() {
				setSubmitButton(pollId, pollOptionValue, polPopTitle);
			};
			pollHttpReq.send(null);
		}
	}
	if (count == 0) {
		getErrorString("POLL_OPINION_REQUIRED");
	}
}
function setSubmitButton(pollId, pollOptionValue, pollPopTitle) {
	if (pollHttpReq.readyState == 4) {
		if (pollHttpReq.status == 200) {
			document.getElementById("PollButton").disabled = "true";
			document.getElementById("pollResultId").style.display = "block";
			document.getElementById("pollResultId").innerHTML = '<a  href="javascript:viewPollResults('
					+ pollId
					+ ', pollPopupTitle);" style="cursor:pointer"><i>'
					+ viewPollResultString + '</i></a>';
			var radioObj = document.userPollForm.pollOption;
			var radioLength = radioObj.length;
			for ( var i = 0; i < radioLength; i++) {
				radioObj[i].disabled = true;
			}

			viewPollResults(pollId, pollPopTitle);
			createCookie("rpdubaiPoll", pollId + "_$_" + pollOptionValue, 60);
		} else
			displayErrorPopupDialog("Error from server.." + pollHttpReq.status);
	}
}
function viewPollResults(pollId, pollPopTitle) {
	loadingWaitDialog();
	if (pollHttpReq.readyState == 4 || pollHttpReq.readyState == 0) {
		var url = "txnController?txnID=4002" + "&pollID=" + pollId + "&lang="
				+ lang;
		pollHttpReq.open("GET", url, true);
		pollHttpReq.onreadystatechange = function() {
			getPollResultHtml(pollPopTitle);
		};
		pollHttpReq.setRequestHeader("If-Modified-Since",
				"Sat, 1 Jan 2000 00:00:00 GMT");
		pollHttpReq.send(null);
	}
}
function getPollResultHtml(pollPopupTitle) {
	var popHTML;
	if (pollHttpReq.readyState == 4) {
		if (pollHttpReq.status == 200) {
			popHTML = pollHttpReq.responseText;
		} else {
			popHTML = 'Error from server...' + pollHttpReq.status;
		}
		displayPopupDialog(popHTML, pollPopupTitle);
	}
}
/** poll js end. */
function switchLang(){
	var curLoc = window.location.href;
	var newLoc;
	if(curLoc.indexOf("lang=0") != -1){
		newLoc = curLoc.replace("lang=0","lang=1");
	}else if(curLoc.indexOf("lang=1") != -1){
		newLoc = curLoc.replace("lang=1","lang=0");
	}else if(curLoc.indexOf("?") != -1){
		newLoc = curLoc + "&lang=1";
	}else{
		newLoc = curLoc + "?lang=1";
	}
	window.location.href=newLoc;
}

/** news popup using dojo. Start.* */
var popupRecReq = GetXmlHttpObject();
function showNewsPopup(id, tabLabel) {
	loadingWaitDialog();
	if (popupRecReq.readyState == 4 || popupRecReq.readyState == 0) {
		var url = ctxtPath + "/ajaxSearch.do?method=getNewsonId&newsId=" + id
				+ "&lang=" + lang;
		popupRecReq.open("GET", url, true);
		popupRecReq.onreadystatechange = function() {
			showNewsdiv(tabLabel);
		};
		popupRecReq.setRequestHeader("If-Modified-Since",
				"Sat, 1 Jan 2000 00:00:00 GMT");
		popupRecReq.send(null);
		0
	}
}

function showNewsdiv(tabLabel) {
	if (popupRecReq.readyState == 4 && popupRecReq.status == 200) {
		var xmldoc = popupRecReq.responseXML;
		var x = xmldoc.getElementsByTagName("news");
		var newsHeadline = x[0].getElementsByTagName("newsHeadline")[0].childNodes[0].nodeValue;
		var imageUrl = x[0].getElementsByTagName("imageUrl")[0].childNodes[0].nodeValue;
		var imageUrl2 = x[0].getElementsByTagName("imageUrl2")[0].childNodes[0].nodeValue;
		var engCaps1 = x[0].getElementsByTagName("engCaps1")[0].childNodes[0].nodeValue;
		var engCaps2 = x[0].getElementsByTagName("engCaps2")[0].childNodes[0].nodeValue;
		var arbCaps1 = x[0].getElementsByTagName("arbCaps1")[0].childNodes[0].nodeValue;
		var arbCaps2 = x[0].getElementsByTagName("arbCaps2")[0].childNodes[0].nodeValue;
		var news_Source = x[0].getElementsByTagName("news_Source")[0].childNodes[0].nodeValue;
		var newsDetails = x[0].getElementsByTagName("newsDetails")[0].childNodes[0].nodeValue;
		var dir = "ltr";
		var caps1, caps2;
		if (lang == 0) {
			if (engCaps1 != ' ') {
				caps1 = '<div id="engCaps1">' + engCaps1 + '</div>';
			}
			if (engCaps2 != ' ') {
				caps2 = '<div id="engCaps2">' + engCaps2 + '</div>';
			}
		} else {
			if (arbCaps1 != ' ') {
				caps1 = '<div id="arbCaps1">' + arbCaps1 + '</div>';
			}
			if (arbCaps2 != ' ') {
				caps2 = '<div id="arbCaps2">' + arbCaps2 + '</div>';
			}
			dir = "rtl";
		}

		var popHTML = '<div class="newpopupbox" dir="'
				+ dir
				+ '" style="width:710px;height:390px;overflow:auto;">'
				+ '<div id="newsBody"><div id="newsHeadLine" class="pop_title"  dir="'
				+ dir + '">' + newsHeadline + '</div><div class="popcontent">'
		/* 
		 * Show news source only if news-tab rera-in-news selected.
		 * JS variable 'reraInNewsLabel' is defined in HomeNews.jsp and news.jsp. 
		 * And values assigned to this variable is different for home page and inner News page.
		 */		
		if(tabLabel && 	tabLabel == reraInNewsLabel) {
			popHTML = popHTML+ '<div class="newsItem" id="newsSource">';
			if (homeNewsSourceLabel)
				popHTML = popHTML + homeNewsSourceLabel + ' : ';
	
			if (news_Source)
				popHTML = popHTML + news_Source;
			popHTML = popHTML + '<br><br></div>';
		}
		
		if (imageUrl != ' ') {
			popHTML = popHTML + '<div id="imageUrl"><img src="' + ctxtPath
					+ sharedFolderPath + '/News/' + imageUrl
					+ '" border=0></div>';
		}
		if (imageUrl2 != ' ') {
			popHTML = popHTML + '<div id="imageUrl2"><img src="' + ctxtPath
					+ sharedFolderPath + '/News/' + imageUrl2
					+ '" border=0></div>';
		}

		if (caps1)
			popHTML = popHTML + caps1;
		if (caps2)
			popHTML = popHTML + caps2;
		popHTML = popHTML + '<div id="newsDetails">' + newsDetails
				+ '</div></div></div></div>';
		//display the pop-up title as news-tab selected.
		displayPopupDialog(popHTML, tabLabel);
	}
}

/** Sign In popup. Start.* */
var loginPageCallerVar = '';
function showSignInPopup(signInPopupTitle, loginPgeCaller) {
	loginPageCallerVar = loginPgeCaller;
	var dir = "ltr";
	var boxStyle = "padding:10px 5px 0px 10px;width:235px;height:220px;";
	var floatRtLt = "right";
	if (lang == 1) {
		dir = "rtl";
		boxStyle = "padding:5px 10px 0px 10px;width:235px;height:220px;";
		floatRtLt = "left";
	}
	//Get email from cookie - "Remember Me".
	var rememberEmail = readCookie("emailaddress");
	var rememberPassword = readCookie("password");
	var checked = '';
	if(!rememberEmail || rememberEmail == null || rememberEmail =='') {
		rememberEmail = '';
		rememberPassword = '';
	}
	else {
		checked = 'checked="true"';
	}
	 
	var signinpopHTML = '<div dir="'
			+ dir
			+ '"><div class="dojopopupbox" style="'
			+ boxStyle
			+ '" dir="'
			+ dir
			+ '">'
			+ '<div  dir="'
			+ dir
			+ '">'
			+ emailAddrLabel
			+ ':</div>'
			+ '<div  dir="'
			+ dir
			+ '"><input type="text" style="width:180px" name="emailaddress" id="emailaddress" onkeypress="clearalerts(\'email\'); clearalerts(\'pass\');" value=""/></div>'
			+ '<div style="height:15px;"><span class="style1"><font color="#FF0000" id="emaildec"></font></span></div>'
			+ '<div>'
			+ passLabel
			+ ':</div>'
			+ '<div  dir="'
			+ dir
			+ '"><input type="password" style="width:180px" name="password1" id="password1" onkeypress="clearalerts(\'email\'); clearalerts(\'pass\'); submitenter(this,event);" value=""/></div>'
			+ '<div style="height:15px;"><span class="style1" style="height:5px;"><font color="#FF0000" name="passworddec" id="passworddec"></font></span></div>'
			+ '<div><input id="rememberMe" name="rememberMe" type="checkbox" '
			+ checked
			+ ' >&nbsp Remember Me</div>'
			+ '<br/><div dir="'
			+ dir
			+ '"><div><input type="button" class="button_n" onclick="javascript:validateLogin();" value="'
			+ signInLabel
			+ '"></div>'
			+ '<div class="style1"  dir="'
			+ dir
			+ '"><a href=\"'
			+ ctxtPath
			+'/home/forgotPassword.do?lang=0\">'
			+ forPassLabel
			+ '</a></div><hr/>'
			+ '<div  dir="'
			+ dir
			+ '"><input type="button" class="button_n" value="'
			+ regLabel
			+ '" onclick=location.href=\"'
			+ ctxtPath
			+ '/registration.do?method=viewUserRegistrationPage&lang=0\"></div>'
			+ '<div dir="'
			+ dir
			+ '"><img id="loadImage" style="float:'
			+ floatRtLt
			+';" src="'
			+ ctxtPath
			+ '/images/1X1white.gif" border="0"></img></div><br/></div></div>';
	//alert(signinpopHTML);
	displayPopupDialog(signinpopHTML, signInPopupTitle);
	if(document.getElementById("emailaddress"))
		document.getElementById("emailaddress").value = rememberEmail;
	if(document.getElementById("password1"))
		document.getElementById("password1").value = rememberPassword;

}

/** dojo utility function common for all popup dialog using dojo. * */
function displayPopupDialog(popHTML, popTitle) {
	displayPopupDialog(popHTML, popTitle, null, null);
}

// Dojo pop up dialog core function.
var dojoPopupDialogVar;
function getDojoDialog(){
	if(dojoPopupDialogVar != undefined && dojoPopupDialogVar != null)
		return dojoPopupDialogVar;
	else{
		dojoPopupDialogVar = new dijit.Dialog();
		this.dojoPopupDialogVar.id = 'dojoDialog';
	}
}
function dojoPopupDialog(popHTML, ppupTitle, dialogWidth, dialogHeight) {
	hideDialogPopup();
	var dojoDialog = getDojoDialog();
	if (dojoDialog != null && popHTML != null) {
		if (dialogWidth != null && dialogWidth != '')
			dojoDialog.style.width = dialogWidth;
		if (dialogHeight != null && dialogHeight != '')
			dojoDialog.style.height = dialogHeight;
		if (ppupTitle != null)
			dojoDialog.attr('title', ppupTitle);
		dojoDialog.attr('content', popHTML);
		dojoDialog.show();
	}
}
function hideDialogPopup(){
	var djDialg = getDojoDialog();
	if(djDialg){
		djDialg.hide();
	}
}
// Function to show loading delay of data in popup for dojo.
function loadingWaitDialog() {
	var ppupTitle = 'Loading';
	if(lang==1)
		ppupTitle = '&#1578;&#1581;&#1605;&#1610;&#1604'; 
	var popHTML = '<div><img src=\"' + ctxtPath + '/images/rel_interstitial_loading.gif\"/></div>';
	dojoLoadWaitDialog(popHTML, ppupTitle, '240px', '180px');	
}
// Function to show loading delay of data in popup for dojo.
function dojoLoadWaitDialog(popHTML, ppupTitle, dialogWidth, dialogHeight) {
	displayPopupDialog(popHTML, ppupTitle, dialogWidth, dialogHeight);
}

// this function can be used to switch between dojo or YUI pop up dialog.
function displayPopupDialog(popHTML, ppupTitle, dialogWidth, dialogHeight) {
	dojoPopupDialog(popHTML, ppupTitle, dialogWidth, dialogHeight);
}
function displayErrorPopupDialog(popHTML) {
	// Global variable.
	var errorTitle;
	if (lang == null || lang == 0) {
		errorTitle = 'Error!';
	} else {
		// In Arabic.
		errorTitle = '&#1582;&#1591;&#1571;!';
	}
	displayPopupDialog(popHTML, errorTitle);
}
/** Sign In popup. End.* */

/** Contact Us popup for Location Map. * */
function showLocationMap() {
	var popHTML = '<div style="padding:0px;border:3px;solid #A9D2F1;">' + '<table><tr><td><img src="../images/routmap_ld.jpg"/></td></tr></table></div>';
	displayPopupDialog(popHTML, '', '380px', '381px');
}

/** Professional Listing popup. * */
function showDetails(companyName, address, phone, fax, email, websiteaddr,
		imagepath, aboutcompany, aboutservices) {
	loadingWaitDialog();
	companyName = unescape(companyName);
	address = unescape(address);
	aboutcompany = unescape(aboutcompany);
	aboutservices = unescape(aboutservices);
	var popHTML = '<table width="650" border="0" cellpadding="0" cellspacing="0" bordercolor="#D9EEF9">' + '<tr><td width="200"><div align="center"><div id="imagepath">';
	if (imagepath) {
		popHTML = popHTML 
		+'<img src="'+imagepath+'" height="150" width="150" border="0"  style="border: 3px solid #87AEDE;">';
	}

	popHTML = popHTML + '</div></div></td><td valign="top">';

	if (companyName) {
		popHTML = popHTML + '<div class="professional_headingnew">'
				+ companyName + '</div>';
	}
	if (address != undefined && address != null && trim(address) != '') {
		popHTML = popHTML + '<div style="padding-top:3px;padding-bottom:3px;">'
				+ address + '</div>';
	}
	if (phone != undefined && phone != null && trim(phone) != '') {
		if (phoneLabel)
			popHTML = popHTML
					+ '<div style="padding-top:5px;padding-bottom:5px;"><b>'
					+ phoneLabel + ' : </b>';
		popHTML = popHTML + phone + '<br /></div>';
	}
	if (fax != undefined && fax != null && trim(fax) != '') {
		if (faxLabel)
			popHTML = popHTML
					+ '<div style="padding-top:5px;padding-bottom:5px;"><b>'
					+ faxLabel + ' : </b>';
		popHTML = popHTML + fax + '</div>';
	}
	if (email != undefined && email != null && trim(email) != '') {
		if (emailLabel)
			popHTML = popHTML
					+ '<div style="padding-top:5px;padding-bottom:5px;"><b>'
					+ emailLabel + ' : </b>';
		popHTML = popHTML + email + '</div>';
	}
	if (websiteaddr != undefined && websiteaddr != null
			&& trim(websiteaddr) != '') {
		if (websiteLabel)
			popHTML = popHTML
					+ '<div style="padding-top:5px;padding-bottom:5px;"><b>'
					+ websiteLabel + ' : </b>';
		popHTML = popHTML + websiteaddr + '</div>';
	}

	popHTML = popHTML + '</td></tr><tr><td>&nbsp;</td></tr>';

	if (aboutcompany != undefined && aboutcompany != null
			&& trim(aboutcompany) != '') {
		if (aboutCompanyLabel)
			popHTML = popHTML
					+ '<tr bgcolor="#D9EEF9" height="20"><td colspan="2"><b>&nbsp;'
					+ aboutCompanyLabel + ' : </b>';
		popHTML = popHTML + '</td></tr><tr><td colspan="2" class="prof_Other">'
				+ aboutcompany + '</td></tr>';
	}

	popHTML = popHTML + '<tr><td>&nbsp;</td></tr>';

	if (aboutservices != undefined && aboutservices != null
			&& trim(aboutservices) != '') {
		if (abtServiceLabel)
			popHTML = popHTML
					+ '<tr bgcolor="#D9EEF9" height="20"><td colspan="2"><b>&nbsp;'
					+ abtServiceLabel;
		popHTML = popHTML
				+ ' : </b></td></tr><tr><td colspan="2" class="prof_Other">'
				+ aboutservices;
	}
	popHTML = popHTML + '</td></tr></table>';

	if (profPopupTitle != undefined && profPopupTitle != null
			&& trim(profPopupTitle) != '') {
		profPopupTitle = trim(profPopupTitle);
	}
	displayPopupDialog(popHTML, profPopupTitle, '', '327px');
}
