widgetServer = "sibetap01.ext.nokia.com";
//widgetServer = "localhost";
var flg=0;

function writeJS(projLang,NprojId,NewNpsEmail,NewNpsEmailChange,NpsThanksMsg,feedback_mandatory){
	var lan="'"+projLang+"'";
	var NpsThanksMsg="'"+NpsThanksMsg+"'";
	var feedback_mandatory="'"+feedback_mandatory+"'";

	var str = '';
	
	str+='		<div id="nps-sidebar' + idSuffix + '" class="nps-sidebar nps-sidebar'+idSuffix+'" style="margin-top:10px;text-align:left;width:212px;">';
	str+='			<div id="nps-recommend' + idSuffix + '" class="nps-recommend nps-recommend'+idSuffix+'">';
	
	str+='			<\/div>';
	str+='				<div id="nps-tabs-box' + idSuffix + '" class="nps-tabs-box nps-tabs-box'+idSuffix+'">';
	str+='					<div id="nps-fb-box' + idSuffix + '" class="nps-fb-box nps-fb-box'+idSuffix+'">';
	str+='						<form method="post" id="nps-form' + idSuffix + '" class="nps-form" name="nps-form" action="javascript:validate('+idSuffix+','+NprojId+','+lan+','+NpsThanksMsg+','+feedback_mandatory+');">';
	str+='							<fieldset class="nps-fieldset">';
	str+='								<legend class="nps-legend">NPS Feedback Form<\/legend>';
	str+='								<label for="nps-fb-text' + idSuffix + '" id="nps-fb-text-label' + idSuffix + '" class="nps-fb-text-label">Feedback:<\/label>';
	if (document.getElementById('betadownload'))
	{
		str+='								<textarea id="nps-fb-text' + idSuffix + '" class="nps-fb-text" name="fb-text" rows="" cols=""><\/textarea>';
	}
	else
	{
		str+='<textarea id="nps-fb-text' + idSuffix + '" style="margin-left:2px;width:95%;" class="nps-fb-text" name="fb-text" rows="" cols=""><\/textarea>';
	}
	if (document.getElementById('betadownload'))
	{
	
	if (NewNpsEmail!="")
	{
		if (NewNpsEmailChange=="yes")
		{
			str+='<input type="text" value="'+NewNpsEmail+'" id="nps-fb-email' + idSuffix + '" style="width:125px;height:17px;" class="nps-fb-email" name="fb-email" \/>';
		}
		else
		{
			str+='<input type="text" value="'+NewNpsEmail+'" id="nps-fb-email' + idSuffix + '" style="width:125px;height:17px;" class="nps-fb-email" name="fb-email" readonly \/>';
		}
		
	}
	else
	{
		str+='<input type="text" value="Your email address (opt.)" id="nps-fb-email' + idSuffix + '" style="width:125px;height:17px;" class="nps-fb-email" name="fb-email" onfocus="updateContents(this);" \/>';
	}
	}
	else
	{
		if (NewNpsEmail!="")
		{
		if (NewNpsEmailChange=="yes")
		{
			str+='<input type="text" value="'+NewNpsEmail+'" id="nps-fb-email' + idSuffix + '" style="width:140px;height:17px;margin-left:2px;" class="nps-fb-email" name="fb-email" \/>';
		}
		else
		{
			str+='<input type="text" value="'+NewNpsEmail+'" id="nps-fb-email' + idSuffix + '" style="width:140px;height:17px;margin-left:2px;" class="nps-fb-email" name="fb-email" readonly \/>';
		}
		
		}
		else
		{
			str+='<input type="text" value="Your email address (opt.)" id="nps-fb-email' + idSuffix + '" style="width:125px;height:17px;margin-left:2px;" class="nps-fb-email" name="fb-email" onfocus="updateContents(this);" \/>';
		}
	}
	str+='								<input type="submit" id="nps-fb-submit' + idSuffix + '" class="nps-fb-submit" value="Submit" \/>';
	str+='							<\/fieldset>';
	str+='						<\/form>';
	if (!document.getElementById('NPSWidgetLink'))
	{
		
	str+='						<div id="nps-feedback' + idSuffix + '" class="nps-feedback">';
	str+='							<div id="nps-fb-close-link' + idSuffix + '" class="nps-close nps-close'+idSuffix+'"><a href="javascript:closeFeedback('+idSuffix+','+lan+','+NpsThanksMsg+');" id="nps-fb-close' + idSuffix + '">Close<\/a><\/div>';
	str+='						<\/div>';

	}
	
	str+='					<\/div>';
	str+='				<\/div>';
	str+='		<\/div>';

	document.write(str);

	
	
}



function initnps()
{
	version="";
	projId    = ""; 
	projName  = "";
	bgURL     = "";
	bgTopURL  = "";
	bgBotURL  = "";
	border    = "";
	fontColor = "";
	projLang="";

	var scriptTag=document.getElementsByTagName('script');

	for (i=0;i<scriptTag.length ;i++ )
	{
		 var ScriptHTML=scriptTag[i].innerHTML;
		 if (ScriptHTML.indexOf('nps_project_id')!=-1)
		 {
			flg=flg+1;
		
		}
	}


	
	if (flg!=0)
	{
		try
		{
			npsInit(flg);
		}
		catch (e)
		{
		  
		}

	}
	else
	{
		alert("No Widget Added");
	}
}
 function showNPSWidget()
	{
		
	if (document.getElementById('overlay'))
	{
	var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		//alert("Width: "+pageWidth+" Height: "+pageHeight);
		
		document.getElementById('overlay').style.height=pageHeight+"px";
		document.getElementById('overlay').style.width=pageWidth+"px";

	}
		
		if(document.getElementById('nps_widget_script'))
		{
			document.getElementById('nps_widget_script').style.display="block";	
		}
		if (document.getElementById('NPSWidgetLink'))
		{
			document.getElementById('NPSWidgetLink').style.display="none";
		}
		
		//document.getElementById('nps_widget_script').style.display="block";
		//document.getElementById('NPSWidgetLink').style.display="none";
		
		var obj=document.getElementById("feedbackWidgetDiv");
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			curleft = obj.offsetLeft
			curtop = obj.offsetTop
			while (obj = obj.offsetParent) {
				curleft += obj.offsetLeft
				curtop += obj.offsetTop
			}
		}
	//return [curleft,curtop];


	  if (window.ActiveXObject)
		{

			if (curtop>350)
			{
				
				if ((document.getElementById('nps-recs'+idSuffix).style.display=="none")&&(document.getElementById('nps-fb-box'+idSuffix).style.visibility=="hidden"))
				{
					document.getElementById('nps_widget_script').style.top="-100px";
				}
				else if (document.getElementById('nps-recs'+idSuffix).style.display=="none")
				{
				  document.getElementById('nps_widget_script').style.top="-300px";
				}
				else
				{
					document.getElementById('nps_widget_script').style.top="-120px";
				}
				
			}
			else
			{
				document.getElementById('nps_widget_script').style.top="12px";
			}

		}
// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation && document.implementation.createDocument)
		{
			if (curtop>350)
			{
				if ((document.getElementById('nps-recs'+idSuffix).style.display=="none")&&(document.getElementById('nps-fb-box'+idSuffix).style.visibility=="hidden"))
				{
				  document.getElementById('nps_widget_script').style.top="-100px";
				}
				else if (document.getElementById('nps-recs'+idSuffix).style.display=="none")
				{
					document.getElementById('nps_widget_script').style.top="-300px";
				}
				else
				{
					document.getElementById('nps_widget_script').style.top="-120px";
				}
			}
		}
	 //document.getElementById('nps_widget_script').style.top="-"+(curtop-300)+"px";
	 if (document.getElementById('overlay'))
	 {
		  document.getElementById('overlay').style.display="block";
	 }
	
	 
	}

	function hideBox(){
		if (document.getElementById('overlay'))
		{
			document.getElementById('overlay').style.display="none";
			document.getElementById('nps_widget_script').style.display="none";
			return false;
		}
    
}

initnps();
