//widgetServer = "localhost";
widgetServer = "sibetap01.ext.nokia.com";

var JQ="";
var jQTag=document.getElementsByTagName('script');

	for (i=0;i<jQTag.length ;i++ )
	{
		
		 JQ=JQ+","+jQTag[i].src;
	}

	
if (JQ.indexOf('jquery')==-1)
{
	
	JQStr='<script src="http://'+widgetServer+'/nps_widget/js/jquery-latest.js" type="text/javascript"></script>';
	document.write(JQStr);
}



var idSuffix="";
var tmpCount="";
var tempdatacnt;

//var $J = jQuery.noConflict();


var indexes = new Array();


var XssHttpRequestCount=0;
var XssHttpRequestWatchList=[];
var X=function(){this.ins=++XssHttpRequestCount;this.u;this.so;this.w;this.wc=0;this.to=30;this.responseText=null;this.responseXML=null;this.status=null;this.readyState=0;};
X.prototype.onreadystatechange=function(){};
X.prototype.onerror=function(){};
X.prototype.onload=function(){};
X.prototype.ss=function(s){this.status=s;};
X.prototype.srs=function(a){if(this.readyState<a||a==0){this.readyState=a;this.onreadystatechange();if(this.readyState=='2'){this.srs(3);eval("if(typeof XssHttpRequest"+this.ins+"Loaded!='undefined'){this.responseText=XssHttpRequest"+this.ins+"Loaded;this.ss('200');}else{alert('invalidresponsefromserver.');}");this.so.parentNode.removeChild(this.so);this.srs(4);this.onload();}}};
X.prototype.open=function(m,u,n){this.u=u;this.so=document.createElement('script');this.so.setAttribute('id','XssHttpRequest'+this.ins);if(navigator.userAgent.indexOf('Safari')){this.so.setAttribute('charset','utf-8');}};
X.prototype.send=function(){this.srs(1);this.so.setAttribute('type','text/javascript');this.so.setAttribute('src',this.u+((this.u.indexOf('?')!=-1)?'&':'?')+'XssHttpRequestVar=XssHttpRequest'+this.ins+'Loaded');this.so=document.getElementsByTagName('head')[0].appendChild(this.so);XssHttpRequestWatchList[this.ins]=this;this.w=setInterval('XssHttpRequestWatchList['+this.ins+'].wl()',1000);};
X.prototype.wl=function(){this.wc++;eval("if(typeof XssHttpRequest"+this.ins+"Loaded!='undefined'){clearInterval(this.w);this.srs(2);}else if(this.wc==this.to){clearInterval(this.w);this.onerror('TimedOut');}");};
var XssHttpRequest=X;


		/**
         * Get all the Project details (based on number of projects added) 
         * @param {String} widgetCount 
         * @returns all the parameters that a widget script contains , e.g. version,projId,projName	,bgURL ,bgTopURL,bgBotURL ,border ,fontColor,projLang
         */

function getProjectDetails(widgetCount)
{
//	alert("getProjectDetails: "+widgetCount);
	Nversion="";
	NprojId    = ""; 
	NprojName  = "";
	NbgURL     = "";
	NbgTopURL  = "";
	NbgBotURL  = "";
	Nborder    = "";
	NfontColor = "";
	NprojLang="";
	NpsEvnt="";
	NpsEmail="";
	NpsEmailChange="";
	NpsThanksMsg="";
	NpsdisplayName="";
	feedback_mandatory="";
	var scriptTag=document.getElementsByTagName('script');

		
		 var ScriptHTML=scriptTag[widgetCount].innerHTML;
		 //alert("ScriptHTML: "+ScriptHTML);

		 
		 if (ScriptHTML.indexOf('nps_project_id')!=-1)
		 {
		
			//alert("got prohject Id");
			getScriptHTML=scriptTag[widgetCount].innerHTML;
			splitText=getScriptHTML.split(";");

			for (j=0;j<(splitText.length-1) ;j++ )
			{
				
				if ((splitText[j]!=null)||(splitText[j]!="undefined")||(splitText[j]!=""))
				{
					
				splitTxt=splitText[j].split('=');
				trimText=splitTxt[0].replace(/^\s+|\s+$/g,"");
				
				replaceTxt=splitTxt[1].replace('"','');
				replaceText= replaceTxt.replace('"','');
				
				if (trimText=="nps_version")
				{
					
				   replaceText=replaceText.replace(/^\s+|\s+$/g,"");
				   Nversion=replaceText;
				   
				}
				else if (trimText=="nps_project_id")
				{
				   replaceText=replaceText.replace(/^\s+|\s+$/g,"");
				   NprojId=replaceText;
				  
				}
				else if (trimText=="nps_language")
				{
					 replaceText=replaceText.replace(/^\s+|\s+$/g,"");
					 NprojLang=replaceText;
					 //alert("before conversion: "+NprojLang);
					 NprojLang=NprojLang.toLowerCase();
					 //alert("after: "+NprojLang);

					 
					 
				}
				else if (trimText=="nps_project_name")
				{
				   replaceText=replaceText.replace(/^\s+|\s+$/g,"");
				   NprojName=replaceText;
				  
				}
				else if (trimText=="nps_background_url")
				{
				   replaceText=replaceText.replace(/^\s+|\s+$/g,"");
				   NbgURL=replaceText;
				}
				else if (trimText=="nps_background_top_url")
				{
					replaceText=replaceText.replace(/^\s+|\s+$/g,"");
					NbgTopURL=replaceText;	
				}
				else if (trimText=="nps_background_bottom_url")
				{
					replaceText=replaceText.replace(/^\s+|\s+$/g,"");
					NbgBotURL=replaceText;
				}
				else if (trimText=="nps_border")
				{	
				   replaceText=replaceText.replace(/^\s+|\s+$/g,"");
				   Nborder=replaceText;
				}
				else if (trimText=="nps_font_color")
				{
				   replaceText=replaceText.replace(/^\s+|\s+$/g,"");
				   NfontColor=replaceText;
				}

				else if (trimText=="nps_event")
				{
				   replaceText=replaceText.replace(/^\s+|\s+$/g,"");
				   NpsEvnt=replaceText;
				}
				else if (trimText=="nps_email_default")
				{
				   replaceText=replaceText.replace(/^\s+|\s+$/g,"");
				   NpsEmail=replaceText;
				}
				else if (trimText=="allow_change_nps_email_default")
				{
				   replaceText=replaceText.replace(/^\s+|\s+$/g,"");
				   NpsEmailChange=replaceText;
				}

				else if (trimText=="thankmsg")
				{
				   replaceText=replaceText.replace(/^\s+|\s+$/g,"");
				   NpsThanksMsg=replaceText;

				}
				else if (trimText=="display_name")
				{
				   replaceText=replaceText.replace(/^\s+|\s+$/g,"");
				   NpsdisplayName=replaceText;

				}
				else if (trimText=="feedback_mandatory")
				{
				   replaceText=replaceText.replace(/^\s+|\s+$/g,"");
				   feedback_mandatory=replaceText;

				}
				
				}



			}
			

		 }
	
	//alert("NpsEvnt: "+NpsEvnt);
	NprojId    = (NprojId != undefined) ? NprojId : -1; 
	NprojName  = (NprojName != undefined) ? NprojName : "this";
	NbgURL     = (NbgURL != undefined) ? NbgURL : "";
	NbgTopURL  = (NbgTopURL != undefined) ? NbgTopURL : "";
	NbgBotURL  = (NbgBotURL != undefined) ? NbgBotURL : "";
	Nborder    = (Nborder != undefined) ? Nborder : "";
	NfontColor = (NfontColor != undefined) ? NfontColor : "";
	NprojLang  = (NprojLang != undefined && NprojLang != "") ? NprojLang : "en";
	NpsEvnt  = (NpsEvnt != undefined && NpsEvnt != "") ? NpsEvnt : "onmouseover";
	NpsEmail = (NpsEmail != undefined) ? NpsEmail : "";
	NpsEmailChange = (NpsEmailChange != undefined) ? NpsEmailChange : "";
	NpsThanksMsg = (NpsThanksMsg != undefined) ? NpsThanksMsg : "";
	NpsdisplayName = (NpsdisplayName != undefined) ? NpsdisplayName : "";
	feedback_mandatory  = (feedback_mandatory != undefined && feedback_mandatory != "") ? feedback_mandatory : "no";
	
	
	if (document.getElementById('NPSWidgetLink'))
	{
	
	
	if (NpsEvnt=="onclick")
	{
		document.getElementById('NPSWidgetLink').href="javascript: showNPSWidget();";
	}
	else if (NpsEvnt!="onclick"&&NpsEvnt!="onmouseover")
	{
		document.getElementById('NPSWidgetLink').href="javascript:void(0);";
		//document.getElementById('NPSWidgetLink').setAttribute("onmouseover","javascript: showWidget();");
		document.getElementById('NPSWidgetLink').onmouseover=function(){showNPSWidget();}

	}
	else
	{
		document.getElementById('NPSWidgetLink').href="javascript:void(0);";
		document.getElementById('NPSWidgetLink').onmouseover=function(){showNPSWidget();}

	}
	}
	

	optionalParams(NbgURL,NbgTopURL,NbgBotURL,NfontColor,Nborder);
	createNPS(NprojId,NprojName,NbgURL,NbgTopURL,NbgBotURL,Nborder,NfontColor,NprojLang,idSuffix,NpsEmail,NpsEmailChange,NpsThanksMsg,NpsdisplayName,feedback_mandatory);
}
		
		/**
         * Initiate the insertion of NPS Widget
         * @param {String} count( how many widgets user has added ) 
         * @returns call all methods from here only like: npsCSS,optionalParams,createNPS,recs,elemSniffer,npsform etc..
         */
function npsInit(count) {


	 
	 //alert("tmpCount IF Start: "+tmpCount+" Count: "+count);
	var nps_pro_id="";
	var Fnps_pro_id="";
	setuserStyle();
	
	for (sh=0;sh<count ;sh++ )
	{
	 idSuffix = Math.floor(Math.random()*101);
	 indexes[sh]=idSuffix;

	 var scriptTag=document.getElementsByTagName('script');
	 //alert("script tag nps init: "+scriptTag.length);
	 for (t=0;t<scriptTag.length ;t++ )
	 {
		
		 var ScriptHTML=scriptTag[t].innerHTML;
		  //alert("ScriptHTML nps init: "+ScriptHTML);
		 if ((ScriptHTML.indexOf('nps_project_id')!=-1)&&(ScriptHTML.indexOf('nps')!=-1))
		 {
			splitText=ScriptHTML.split(";");
			for (j=0;j<(splitText.length-1) ;j++ )
			{
	
				if ((splitText[j]!=null)||(splitText[j]!="undefined")||(splitText[j]!=""))
				{
					
				splitTxt=splitText[j].split('=');
				trimText=splitTxt[0].replace(/^\s+|\s+$/g,"");
				
				replaceTxt=splitTxt[1].replace('"','');
				replaceText= replaceTxt.replace('"','');
				
				if (trimText=="nps_project_id")
				{
					
				   replaceText=replaceText.replace(/^\s+|\s+$/g,"");
				   nps_pro_id=replaceText;
				   
				}
				}
			}

			if ((tmpCount=="undefined")||(tmpCount=="")||(tmpCount==null))
			{
			
				//alert("tmpCount IF: "+tmpCount);
				//alert("T IF: "+t);
				tmpCount=tmpCount+","+t;
				// get Project Optional Parameters
				Fnps_pro_id=Fnps_pro_id+","+nps_pro_id;
				if ((tempdatacnt=="undefined")||(tempdatacnt=="")||(tempdatacnt==null))
				{
					getProjectDetails(t);
					tempdatacnt=tempdatacnt+","+t;
					break;
				}
				else if(((tempdatacnt!="undefined")||(tempdatacnt!="")||(tempdatacnt!=null))&&(tempdatacnt.indexOf(t)==-1))
				{
					getProjectDetails(t);
					tempdatacnt=tempdatacnt+","+t;
					break;
				
				}
				
				break;
			
			}

			else if ((tmpCount.indexOf(t)==-1)&&(tmpCount!="")&&(Fnps_pro_id!=""))
			{
				
			//	alert("tmpCount ELSE: "+tmpCount);
				//alert("T ELSE: "+t);
				tmpCount=tmpCount+","+(t);
				Fnps_pro_id=Fnps_pro_id+","+nps_pro_id;
				// get Project Optional Parameters
				if ((tempdatacnt=="undefined")||(tempdatacnt=="")||(tempdatacnt==null))
				{
					getProjectDetails(t);
					tempdatacnt=tempdatacnt+","+t;
					break;
				}
				else if(((tempdatacnt!="undefined")||(tempdatacnt!="")||(tempdatacnt!=null))&&(tempdatacnt.indexOf(t)==-1))
				{
					getProjectDetails(t);
					tempdatacnt=tempdatacnt+","+t;
					break;
				
				}
				break;
			}
		 }
	 }
	pageURL   = window.location.href; // Page URL where the widget script is embedded
	version   = "2.0"; // Current widget version
	rated     = 0; // Flag to indicate whether user has rated during this session (defaulted for now)
	// Vars for email validation
	emailEmpty   = "Your email address (opt.)";
	emailInvalid = "Invalid email address";
	temp = "";
	

	// Test: Fix for Quirks Mode
	// var testdiv = document.getElementById('nps-sidebar' + idSuffix);
	// compensateWidth(testdiv);

	// How many stylesheets are loaded?
	//recs();
	//elemSniffer();
	npsform();
	}


}
		 /**
         * Handle the possibility of multiple onload events on a page by "chaining" them together
         */

function addOnloadEvent(func) {
	if (typeof window.addEventListener != "undefined")
		window.addEventListener("load", func, false);
	else
		if (typeof window.attachEvent != "undefined") {
			window.attachEvent("onload", func);
		}
		else {
			if (window.onload != null) {
				var oldOnload = window.onload;
				window.onload = function(e) {
				oldOnload(e);
				window[func]();
			};
		}
	else
		window.onload = func;
	}
}

		/**
         * Parse the URL for the widget's version number
         */

function getWidgetVersion(scriptURL) {
	var tmp = new Array();
	var ver = new Array();
	var tmp = scriptURL.split("NPSWidget-");
	var ver = tmp[1].split(".js?");
	return ver[0];
}
		/**
         * Parse the URL for the specified parameter
         */

function getURLParam(scriptURL, param) {
	param = param.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]" + param + "=([^&#]*)";
	var regex = new RegExp(regexS);
	var results = regex.exec(scriptURL);
	if (results == null)
		return "";
	else
		return results[1];
}

		/**
         * Initiate Optional params like adding css and css rules
         */
	function optionalParams(NbgURL,NbgTopURL,NbgBotURL,NfontColor,Nborder){
	
	if (NfontColor != "") userFontColor(NfontColor);

	userBorder(Nborder);

	if (NbgURL != "") return userBackground("all",NbgURL,NbgTopURL,NbgBotURL,Nborder);
	if (NbgTopURL != "" && NbgBotURL != "") return userBackground("top-bot",NbgURL,NbgTopURL,NbgBotURL,Nborder);
	if (NbgTopURL != "" && NbgBotURL == "") return userBackground("top",NbgURL,NbgTopURL,NbgBotURL,Nborder);
	if (NbgTopURL == "" && NbgBotURL != "") return userBackground("bot",NbgURL,NbgTopURL,NbgBotURL,Nborder);
	
}
		/**
         * Added this new method to resolve the ID, Class Selector issue in "BetaLabs"
         * @returns adds css rules to the DOM to override the style of beta labs 
		 * works fine outside beta labs also 
         */
function setuserStyle() {
	var node = document.createElement("style");
	node.setAttribute("type", "text/css");
	node.setAttribute("media", "all");
	
	var selector   = "#betainfo ul.nps-recs li";
	var properties = "cursor: pointer;margin: 0;padding: 0;display: inline;line-height: 30px;";
	
	addCSSRule(node, selector, properties);
	document.getElementsByTagName("head")[0].appendChild(node);

	var node = document.createElement("style");
	node.setAttribute("type", "text/css");
	node.setAttribute("media", "all");
	
	var selector   = "#betadownload ul.nps-recs li";
	var properties = "cursor: pointer;margin: 0;padding: 0;display: inline;line-height: 30px;";
	
	addCSSRule(node, selector, properties);
	document.getElementsByTagName("head")[0].appendChild(node);
	
}

		 /**
         * Apply the font color if user has provided in the script 
         * nps_font_color = "336699";
         */

function userFontColor(NfontColor) {

	var node = document.createElement("style");
	node.setAttribute("type", "text/css");
	node.setAttribute("media", "screen"); 

	var selector   = "div.nps-recommend"+idSuffix;
	var properties = "color: #" + NfontColor + ";";
	addCSSRule(node, selector, properties);

	var selector   = "div.nps-close"+idSuffix+" a";
	addCSSRule(node, selector, properties);

	document.getElementsByTagName("head")[0].appendChild(node);
}

		 /**
         * Apply the border style if user has provided in the script 
         * nps_border = "y";
         */

function userBorder(Nborder) {
	var node = document.createElement("style");
	node.setAttribute("type", "text/css");
	node.setAttribute("media", "screen"); 

	if (Nborder == "y")
		var properties = "border: 1px solid #000000;";
	else
		var properties = "border: 1px solid #CCCCCC;";

	var selector = "div.nps-sidebar"+idSuffix;
	addCSSRule(node, selector, properties);

	var selector = "div.nps-fb-box"+idSuffix;
	addCSSRule(node, selector, properties);

	document.getElementsByTagName("head")[0].appendChild(node);
}
		 /**
         * Apply the background style if user has provided in the script 
         * nps_background_url = "";
		 * nps_background_top_url = "";
		 * nps_background_bottom_url = "http://sibetaq01.ext.nokia.com/nps_widget/backgrounds/green1x1.gif";
         */



function userBackground(type,NbgURL,NbgTopURL,NbgBotURL) {

	var node = document.createElement("style");
	node.setAttribute("type", "text/css");
	node.setAttribute("media", "screen"); 

	if (Nborder == "y") {
		borderSize = "1px";
		leftMargin = "-5px";
	}
	else {
		borderSize = "0px";
		leftMargin = "-4px";
	}

	// Top and bottom background image(s)
	if (type == "all" || type == "top-bot") {
		if (type == "all")
			var bg = "url(" + NbgURL + ") repeat 0px 0px;";
		else
			var bg = "url(" + NbgTopURL + ") repeat 0px 0px;";

		var selector   = "div.nps-sidebar"+idSuffix;
		var properties = "border: " + borderSize + " solid #000000; background: " + bg;

		addCSSRule(node, selector, properties);

		if (type == "all")
			var ypos = "-70px;";
		else {
			var bg = "url(" + NbgBotURL + ") repeat 0px 0px;";
			var ypos = "0px;";
		}

		var selector   = "div.nps-fb-box"+idSuffix;
		var properties = "border: " + borderSize + " solid #000000; background: " + bg + " background-position: 0px " + ypos;

		addCSSRule(node, selector, properties);

		var selector   = "div.nps-tabs-box"+idSuffix+" div.nps-fb-box"+idSuffix;
		var properties = "margin: 3px -4px 0px " + leftMargin + ";";

		addCSSRule(node, selector, properties);
	}

	// Top only background image
	if (type == "top") {
		var bg = "url(" + NbgTopURL + ") repeat 0px 0px;";

		var selector   = "div.nps-sidebar"+idSuffix;
		var properties = "border: " + borderSize + " solid #000000; background: " + bg;

		addCSSRule(node, selector, properties);
	}

	// Bottom only background image
	if (type == "bot") {
		var bg = "url(" + NbgBotURL + ") repeat 0px 0px;";

		var selector   = "div.nps-fb-box"+idSuffix;
		var properties = "border: " + borderSize + " solid #000000; background: " + bg;

		addCSSRule(node, selector, properties);

		var selector   = "div.nps-tabs-box"+idSuffix+" div.nps-fb-box"+idSuffix;
		var properties = "margin: 3px -4px 0px " + leftMargin + ";";

		addCSSRule(node, selector, properties);
	}

	document.getElementsByTagName("head")[0].appendChild(node);
}


		 /**
         * Add CSS style to HTML DOM
         * @param node, selector, properties
		 * node= style element
		 * selector= class or ID selector e.g. div .nps OR div #nps
		 * properties= style (e.g. margin: 3px -4px 0px 10px)
         
         */



function addCSSRule(node, selector, properties) {
	if (document.styleSheets) { // IE
		var lastSheet = document.styleSheets[document.styleSheets.length - 1];
		if (lastSheet && typeof lastSheet.addRule != 'undefined') {
			lastSheet.addRule('\r\n' + selector, properties);
		}
		else { // Non-IE
			node.appendChild(document.createTextNode('\r\n' + selector + ' {\r\n\t' + properties + '\r\n}'));
		}
	}
	else { // Non-IE
		node.appendChild(document.createTextNode('\r\n' + selector + ' {\r\n\t' + properties + '\r\n}'));
	}
}


		 /**
         * Browser/OS detection
         */
var NPSBrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// For newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// For older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS: [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
NPSBrowserDetect.init();



		 /**
         * Handles IE6&7, Chrome (Mozilla), Safari css issues
         * 
         *
         
         
         */


function npsCSS(newSuffix){
	var npsbrow = NPSBrowserDetect.browser;
	var npsbrowver = NPSBrowserDetect.version;
	//alert("Browser: "+npsbrow+" : Version: "+npsbrowver);
	targethead = document.getElementsByTagName("head")[0];

	browserCSS = "";
	if ((npsbrow == "Explorer") && (npsbrowver == "6")) {
		browserCSS = "_ie6-2.0";
	} else if ((npsbrow == "Explorer") && (npsbrowver == "7")) {
		browserCSS = "_ie7-2.0";
	}
	else if ((npsbrow == "Explorer") && (npsbrowver == "8")) {
		browserCSS = "_ie8-2.0";
	}
	else if ((npsbrow == "Firefox") && (npsbrowver == "3.5")){ 
		browserCSS = "_firefox-2.0";
	}
	else if (npsbrow == "Mozilla") {
		browserCSS = "_chrome-2.0";
	} 
	else if ((npsbrow == "Safari")&& (npsbrowver>4)) {
		browserCSS = "_safari4-2.0";
	}
	else if (npsbrow == "Safari") {
		browserCSS = "_safari-2.0";
	}


	if (browserCSS != "") {

	
		var npscssbrowser = document.createElement("link");
		npscssbrowser.setAttribute("rel","stylesheet");
		npscssbrowser.setAttribute("media","screen");
		
		npscssbrowser.setAttribute("href","http://" + widgetServer + "/nps_widget/css/nps" + browserCSS + ".css");
		if (browserCSS=="_chrome-2.0")
		{
			document.getElementById('nps-fb-submit'+newSuffix).style.marginTop="10px";
			document.getElementById('nps-fb-submit'+newSuffix).style.paddingTop="0px";
		}
		targethead.appendChild(npscssbrowser);
	}

	if (document.compatMode && document.compatMode == "BackCompat") {

		var npscssquirks = document.createElement("link");
		npscssquirks.setAttribute("rel","stylesheet");
		npscssquirks.setAttribute("media","screen");

		if ((npsbrow == "Explorer") && (npsbrowver == "6")) {
			quirksCSS = "_ie6qm-2.0";
		} else if ((npsbrow == "Explorer") && (npsbrowver == "7")) {
			quirksCSS = "_ie6qm-2.0";
		} else if (npsbrow == "Firefox") {
			quirksCSS = "_ffqm-2.0";
		} else if (npsbrow == "Mozilla") {
			quirksCSS = "_chromeqm-2.0";
		} else if (npsbrow == "Safari") {
			quirksCSS = "_safariqm-2.0";
		}



		npscssquirks.setAttribute("href","http://" + widgetServer + "/nps_widget/css/nps" + quirksCSS + ".css");
		targethead.appendChild(npscssquirks);
	}
}


		/**
         * Handles the insertion of the actual ratings code. 
         * Added some code to get localized text from server side php script
		 *
         
         * @returns localized text from the properties file using Ajax and PHP
         */

function createNPS(NprojId,NprojName,NbgURL,NbgTopURL,NbgBotURL,Nborder,NfontColor,NprojLang,newSuffix,NewNpsEmail,NewNpsEmailChange,NpsThanksMsg,NpsdisplayName,feedback_mandatory){
	writeJS(NprojLang,NprojId,NewNpsEmail,NewNpsEmailChange,NpsThanksMsg,feedback_mandatory);
	npsCSS(newSuffix);
	var recDiv = document.getElementById("nps-recommend" + newSuffix);

	var targetelem = document.getElementById("nps-tabs-box" + newSuffix);
		// This will need to be replaced once the markup is complete and the script is needed to create the markup
		
		if (document.getElementById('NPSWidgetLink'))
		{
	
		var NpsCloseDiv=document.createElement('div');
		NpsCloseDiv.className="closeDiv";
		NpsCloseDiv.style.marginLeft="80%";
		NpsCloseDiv.id="closeMiniDiv"+newSuffix;
		NpsCloseDiv.innerHTML="<a href='javascript:hideNPSPopup();' style='text-decoration:none;'>Close <img src='http://"+widgetServer+"/nps_widget/images/icon_close.gif' border='0'/></a>";
		recDiv.appendChild(NpsCloseDiv);
		}

		var rateHdr = document.createElement("div");
		rateHdr.setAttribute("id","nps-rec" + newSuffix);
		rateHdr.style.display="block";
		rateHdr.className = "nps-rec";


		(function($) {
		$.getJSON("http://"+widgetServer+"/nps_widget/scripts/Jsonp.php?url=http://" + widgetServer + "/nps_widget/l10n/getLang.php&lang="+NprojLang+"&jsoncallback=?", function(data){
		$.each(data.texts, function(i,item){
		// Determine which text to display based on whether the user has submitted a rating or not
		if (rated == 0) {

			if (NpsdisplayName=="")

			{
				rateHdr.innerHTML=item.nps_question + "<b>'"+NprojName+"'</b>" + item.nps_question_1;
			}
			else
			{
				rateHdr.innerHTML=item.nps_question + "<b>'"+NpsdisplayName+"'</b>" + item.nps_question_1;
			}
			//var hdrTxt = document.createTextNode(item.nps_question + "<b>"+NprojName+"</b>" + item.nps_question_1);
		}
		else {
			var hdrTxt = document.createTextNode("You have already submitted a rating.");
		}

		recDiv.appendChild(rateHdr);
		//rateHdr.appendChild(hdrTxt);

		var recULDiv=document.createElement('div');

		
		var recUL = document.createElement("ul");
		recUL.style.marginLeft="0px";
		recUL.setAttribute("id","nps-recs" + newSuffix);
		recUL.className = "nps-recs";
		
		recULDiv.appendChild(recUL);
		recDiv.appendChild(recULDiv);
	
	var recsArray = new Array();
	// ******************* 	li class value	rel			rec		text for inside anchor and title attr	<a> class values	
	recsArray[0]  = new Array(	"",			"nps0",		"0",		"",											""	);
	recsArray[1]  = new Array(	"",			"nps1",		"1",		"",											""	);
	recsArray[2]  = new Array(	"",			"nps2",		"2",		"",											""	);
	recsArray[3]  = new Array(	"",			"nps3",		"3",		"",											""	);
	recsArray[4]  = new Array(	"",			"nps4",		"4",		"",											""	);
	recsArray[5]  = new Array(	"",			"nps5",		"5",		"",											""	);
	recsArray[6]  = new Array(	"",			"nps6",		"6",		"",											""	);
	recsArray[7]  = new Array(	"",			"nps7",		"7",		"",											""	);
	recsArray[8]  = new Array(	"",			"nps8",		"8",		"",											""	);
	recsArray[9]  = new Array(	"",			"nps9",		"9",		"",											""	);
	recsArray[10] = new Array(	"",			"nps10",	"10",		"",											""	);

	for (i = 0; i < recsArray.length; i++){
		var recLI = document.createElement("li");
		var recA = document.createElement("a");
		var recSpan = document.createElement("span");
		var aTxt = document.createTextNode(recsArray[i][2]);
		recUL.appendChild(recLI);
		recLI.appendChild(recA);
		recLI.className = recsArray[i][0];

		// If the user hasn't submitted a rating yet then create the recommendation URL
		if (rated == 0) {
			recA.appendChild(recSpan);
			recA.setAttribute("rel", recsArray[i][1]);
			recA.setAttribute("href", "http://" + widgetServer + "/nps_widget/scripts/recommend.php?version=2.0&projid=" + NprojId + "&pageurl=" + pageURL + "&rec=" + recsArray[i][2]+"&idSuffix="+newSuffix+"&lan="+NprojLang);
			//recA.setAttribute("onclick","postData('http://" + widgetServer + "/nps_widget/scripts/recommend.php?version=2.0&projid=" + NprojId + "&pageurl=" + pageURL + "&rec=" + recsArray[i][2]+"&idSuffix="+newSuffix+"&lan="+NprojLang+"')");
			
			recA.setAttribute("title", recsArray[i][3]);
			recA.className = recsArray[i][4];
		}

		recSpan.appendChild(aTxt);
	}		

	// Insert labels below the NPS rating scale
	var labelsHdr = document.createElement("div");
	labelsHdr.setAttribute("id","nps-labels" + newSuffix);
	labelsHdr.className = "nps-labels";
	recDiv.appendChild(labelsHdr);

	// Create labels
	var labelsSpan = document.createElement("span");
	labelsSpan.setAttribute("id","not" + newSuffix);
	var notTxt = document.createTextNode(item.nps_not);
	//var notTxt = document.createTextNode("Not at all");
	labelsHdr.appendChild(labelsSpan);
	labelsSpan.appendChild(notTxt);

	var labelsSpan = document.createElement("span");
	labelsSpan.setAttribute("id","neutral" + newSuffix);
	labelsSpan.className = "nps-neutral";
	var neuTxt = document.createTextNode(item.nps_neutral);
	//var neuTxt = document.createTextNode("Neutral");
	labelsHdr.appendChild(labelsSpan);
	labelsSpan.appendChild(neuTxt);

	var labelsSpan = document.createElement("span");
	labelsSpan.setAttribute("id","extremely" + newSuffix);
	labelsSpan.className = "nps-extremely";
	var extTxt = document.createTextNode(item.nps_extremely);
	//var extTxt = document.createTextNode("Extremely");
	labelsHdr.appendChild(labelsSpan);
	labelsSpan.appendChild(extTxt);

	var labelsHdr = document.createElement("div");
	labelsHdr.setAttribute("id","nps-labels-2" + newSuffix);
	labelsHdr.className = "nps-labels-2";
	recDiv.appendChild(labelsHdr);

	var labelsSpan = document.createElement("span");
	labelsSpan.setAttribute("id","likely" + newSuffix);
	labelsSpan.className = "nps-likely";
	var likTxt = document.createTextNode(item.nps_likely);
	labelsHdr.appendChild(labelsSpan);
	labelsSpan.appendChild(likTxt);

	var labelsSpan = document.createElement("span");
	labelsSpan.setAttribute("id","likely-2" + newSuffix);
	labelsSpan.className = "nps-likely-2";
	var likTxt = document.createTextNode(item.nps_likely);
	labelsHdr.appendChild(labelsSpan);
	labelsSpan.appendChild(likTxt);

	// Clear
	var clearDiv = document.createElement("div");
	clearDiv.setAttribute("style","clear:both;");
	recDiv.appendChild(clearDiv);
		
	recs("nps-recs" + newSuffix);
	elemSniffer(NpsThanksMsg);
	showWRTWidget();


		  });
		 
		
		});

		})(jQuery);//



}


		 /**
         * Handles the rating hover states
         * 
         *
         
         
         */

function recs(Recid){

	if (!document.getElementById) return false;
	var numberlist = document.getElementById(Recid);

	var numbers = numberlist.getElementsByTagName("a");
	for (i = 0; i < numbers.length; i++){

		numbers[i].onmouseover = function(){
			var rel = this.getAttribute("rel");

			// Calculate the y position for the number graphic
			var ypos = (rel.substring(3) * 20) + 20;
			numberlist.style.backgroundPosition = '0 -' + ypos + 'px';
		}

		numbers[i].onmouseout = function(){
			numberlist.style.backgroundPosition = '0 0';
			return false;
		}

	}
}

		 /**
         * Handles tab event behaviors
         * 
         *
         
         
         */

function elemSniffer(NpsThanksMsg){

	if (!document.getElementsByTagName){

		return false;
	}

	var anchors = document.getElementsByTagName("a");
	for (i = 0; i < anchors.length; i++){
		anchors[i].onclick = function(){
			var rel = this.getAttribute("rel");
			if ((rel) && (isRating != -1)){
				var isRating = rel.indexOf("nps");
				var url = this.getAttributeNode("href").nodeValue;
				if (isRating != -1){
					this.removeAttributeNode(this.getAttributeNode("href")); 
					postData(url,NpsThanksMsg);


				}
			}
		}
	}
}
		/**
         * Ajax functions ... consider a JSON solution to handle the cross domain security restrictions placed on the JavaScript XMLHttpRequest object 
         * 
       
         */

function getHTTPObject(){
	var xhr = false;
	if (window.XssHttpRequest){
		var xhr = new XssHttpRequest();
		if (xhr.overrideMimeType){
			xhr.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject){
		try{
			var xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try{
				var xhr = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e){
				xhr = false;
			}
		}		
	}
	return xhr;
}

		 /**
         * XMLHTTP Call to POST data ( recommendation data insert into database)
         * 
         *
         
         
         */

function postData(url,NpsThanksMsg){
	var finalIndex="";
	var FinalLan="";
	// added by shishir kamal
		
		getSuffix=url.split("&");

		for (i=0;i<getSuffix.length ;i++ )
		{
			if (getSuffix[i].indexOf('idSuffix')!=-1)
			{

				getIndex=getSuffix[i].split("=");
				finalIndex=getIndex[1];

			}
			else if(getSuffix[i].indexOf('lan')!=-1)
			{
				SelctedLanguage=getSuffix[i].split("=");
				FinalLan=SelctedLanguage[1];
			}
		}

	// finish adding 
	var request = getHTTPObject();
	if (request){
		displayLoading(finalIndex);
		request.onreadystatechange = function(){

			recResponse(request,finalIndex,FinalLan,NpsThanksMsg);
		};
		request.open("POST", url, true);
		request.send(null);
	}
}

		 /**
         * XMLHTTP Call to POST data ( Feedback data insert into database)
         * 
         * @params url, idVal, widgetProjId
		 * url= feedback url
		 * idVal= current Id (Integer)
		 * widgetProjId= current widget Project Id
		 * Added these parameters to support Multiple widgets
         
         
         */

function postFeedback(url,idVal,widgetProjId,lan,NpsThanksMsg){

	//alert("post feedback: "+NpsThanksMsg);
	
	var parameters;

	parameters = "?fb-text=" + encodeURI(document.getElementById("nps-fb-text" + idVal).value) +
				 "&fb-email=" + encodeURI(document.getElementById("nps-fb-email" + idVal).value) +
				 "&version=" + encodeURI(version) +
				 "&projid=" + encodeURI(widgetProjId) +
				 "&pageurl=" + encodeURI(pageURL);



	url = url + parameters;

	

	postfbkData(url,idVal,lan,NpsThanksMsg);
}



function postfbkData(url,idVal,lan,NpsThanksMsg){

	var request = getHTTPObject();
	if (request){
		request.onreadystatechange = function(){
			//fbkResponse(request,idVal,lan,NpsThanksMsg);
			closeFeedback(idVal,lan,NpsThanksMsg);
		};
		request.open("POST", url, true);
		request.send(null);
	}
}
 		/**
         * Changed the Loading style to support Multiple widgets on one page
         * 
         *
         * 
         * 
         * @params finalIndex, adding id value using the index
         */
function displayLoading(finalIndex){

	var recDiv = document.getElementById("nps-recommend" + finalIndex);
	var recUL = document.getElementById("nps-recs" + finalIndex);
	var recHdr = document.getElementById("nps-rec" + finalIndex);
	recUL.style.display="none";
	recDiv.removeChild(recHdr);

	var labelsDiv = document.getElementById("nps-labels" + finalIndex);
	labelsDiv.style.display="none";

	var labelsDiv = document.getElementById("nps-labels-2" + finalIndex);
	labelsDiv.style.display="none";


	// Create progress image
	var Msg = document.createElement("span");
	Msg.setAttribute("id","nps-prog" + finalIndex);
	Msg.className = "nps-prog";
	var thxTxt = document.createTextNode("Processing");
	recDiv.appendChild(Msg);
	Msg.appendChild(thxTxt);
}

 		/**
         * Changed the Response style to support Multiple widgets on one page
         * 
         * 
         */

function recResponse(request,finalIndex,lan,NpsThanksMsg){

	if (document.getElementById('NPSWidgetLink'))
	{
	var NpsThanksMsg="'"+NpsThanksMsg+"'";
	var lan="'"+lan+"'";
	document.getElementById('closeMiniDiv'+finalIndex).innerHTML='<a href="javascript:closeFeedback('+finalIndex+','+lan+','+NpsThanksMsg+');" style="text-decoration:none;">Close <img src="http://'+widgetServer+'/nps_widget/images/icon_close.gif" border="0"/></a>';
	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
			}
		}

	 //code for IE
	 if (window.ActiveXObject)
		{

		
			if (curtop>350)
			{
				
				if (document.getElementById('nps_widget_script'))
				{
					document.getElementById('nps_widget_script').style.top="-300px";
				}
			
			}
			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_widget_script'))
				{
					document.getElementById('nps_widget_script').style.top="-300px";
				}
				
			
			}
		}
	}

	
	
	
	
	
	
	/*
	for (i=0;i< indexes.length;i++ )
	{

		if (indexes[i]!=finalIndex)
		{
			document.getElementById('nps-sidebar'+indexes[i]).style.display="none";
		}
	}
	*/
	 (function($) {
	$.getJSON("http://" + widgetServer + "/nps_widget/scripts/Jsonp.php?url=http://" + widgetServer + "/nps_widget/l10n/getLang.php&lang="+lan+"&jsoncallback=?", function(data){
		

		$.each(data.texts, function(i,item){


		   	var recDiv = document.getElementById("nps-recommend" + finalIndex);
			var prog = document.getElementById("nps-prog" + finalIndex);
			var Msg = document.createElement("span");
			Msg.setAttribute("id","nps-conf" + finalIndex);
			Msg.className = "nps-conf";
			var thxTxt = document.createTextNode(item.nps_why);

			var errorTxt = document.createTextNode("We're sorry, but we can't process your recommendation.");

			// Was == 4
			if (request.readyState == 1) {

					recDiv.removeChild(prog);
					recDiv.appendChild(Msg);
					Msg.appendChild(thxTxt);
					fade("nps-conf" + finalIndex);
					var npsbrow = NPSBrowserDetect.browser;
					var npsbrowver = NPSBrowserDetect.version;
					// Display the feedback box and set focus to the textarea
					document.getElementById("nps-fb-box" + finalIndex).style.display = "block";
					if ((npsbrow == "Explorer") && (npsbrowver == "6")) {
					document.getElementById("nps-sidebar" + finalIndex).style.marginBottom = "100px";
					}
					document.getElementById("nps-fb-text" + finalIndex).focus();
			}



		 });
		 
		
		});
		})(jQuery);//
	
	
}

		 /**
         * Show the Thank You message
         * 
         * @params request, idVal
		 * request= XMLHTTP Object
		 * idVal= current Id (Integer)
		 * 
		 * Added these parameters to support Multiple widgets
         
         
         */

function fbkResponse(request,idVal,lan,NpsThanksMsg){
	//alert("thanks value: "+NpsThanksMsg);
	document.getElementById("nps-sidebar" + idVal).style.marginBottom = "10px";
	 if (document.getElementById('NPSWidgetLink'))
	{
	 document.getElementById('closeMiniDiv'+idVal).innerHTML="<a href='javascript:hideNPSPopup();' style='text-decoration:none;'>Close <img src='http://"+widgetServer+"/nps_widget/images/icon_close.gif' border='0'/></a>";
	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
			}
		}

	 //code for IE
	 if (window.ActiveXObject)
		{

		
			if (curtop>350)
			{
				
				if (document.getElementById('nps_widget_script'))
				{
					document.getElementById('nps_widget_script').style.top="-100px";
				}
			
			}
			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_widget_script'))
				{
					document.getElementById('nps_widget_script').style.top="-100px";
				}
				
			
			}
		}
	}


(function($) {	
$.getJSON("http://" + widgetServer + "/nps_widget/scripts/Jsonp.php?url=http://" + widgetServer + "/nps_widget/l10n/getLang.php&lang="+lan+"&jsoncallback=?", function(data){
		

		$.each(data.texts, function(i,item){

			  var recDiv = document.getElementById("nps-recommend" + idVal);
	var Msg = document.createElement("span");
	Msg.setAttribute("id","nps-conf" + idVal);
	Msg.className = "nps-conf";
	
	if(NpsThanksMsg=="")
	{
	
	var thxTxt = document.createTextNode(item.nps_thanks);
	}
	else
	{
		//var NpsThanksMsg='"'+NpsThanksMsg+'"';
		NpsThanksMsg=truncate(NpsThanksMsg, "37");
		var thxTxt = document.createTextNode(NpsThanksMsg);
	}

	var errorTxt = document.createTextNode("We're sorry, but we can't process your feedback.");

	// First remove element if it exists so we don't show multiple messages
	if (document.getElementById("nps-conf" + idVal)){
		var recSpan = document.getElementById("nps-conf" + idVal);
		recDiv.removeChild(recSpan);



	/*
	for (i=0;i< indexes.length;i++ )
	{
		console.log("indexes>>>>>>>>>>> "+indexes[i]);
		console.log("idVal>>>>>>>>>>> "+idVal);
		if (indexes[i]!=idVal)
		{
			document.getElementById('nps-sidebar'+indexes[i]).style.display="block";
		}
	}

	*/
	}

	Msg.setAttribute("id","nps-conf-success" + idVal);
	Msg.className = "nps-conf-success";

	// Was == 4
	if (request.readyState == 1) {
//		if (request.status == 200 || request.status  == 304) {
			recDiv.appendChild(Msg);
			Msg.appendChild(thxTxt);
			fade("nps-conf-success" + idVal);

			// Hide the feedback box
			document.getElementById("nps-fb-box" + idVal).style.visibility = "hidden";
//		} else {
//			fbkDiv.removeChild(statIMG);
//			fbkDiv.insertBefore(Msg, document.getElementById("nps-fb-close-link" + idSuffix));
//			Msg.appendChild(errorTxt);
//			fade("nps-fb-conf" + idSuffix);
//		}
	}


		 });
		 
		
		});

		})(jQuery);//

	
}
		 /**
         * Handles fade effect once ratings have been submitted
         * 
		 * 
		 */
var TimeToFade = 300.0;

function fade(eid){
	var element = document.getElementById(eid);
	if (element == null){
		return;
	}
	if (element.FadeState == null){
		if (element.style.opacity == null || element.style.opacity == "" || element.style.opacity == "1"){
			element.FadeState = -2;
		} else {
			element.FadeState = 2;
		}
	}
	if (element.FadeState == 1 || element.FadeState == -1){
		element.FadeState = element.FadeState == 1 ? -1 : 1;
		element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
	} else {
		element.FadeState = element.FadeState == 2 ? -1 : 1;
		element.FadeTimeLeft = TimeToFade;
		setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "')", 33);
	} 
}

function animateFade(lastTick, eid){ 
	var curTick = new Date().getTime();
	var elapsedTicks = curTick - lastTick;
	var element = document.getElementById(eid);

 	if (element.FadeTimeLeft <= elapsedTicks){
		element.style.opacity = element.FadeState == 1 ? '1' : '0';
		element.style.filter = 'alpha(opacity = ' + (element.FadeState == 1 ? '100' : '0') + ')';
		element.FadeState = element.FadeState == 1 ? 2 : -2;
		return;
	}
 	element.FadeTimeLeft -= elapsedTicks;
	var newOpVal = element.FadeTimeLeft/TimeToFade;
	if (element.FadeState == 1){
		newOpVal = 1 - newOpVal;
	}
	element.style.opacity = newOpVal;
	element.style.filter =  'alpha(opacity = ' + (newOpVal*100) + ')';
 	setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
}

// Form behaviors
function npsform(){
	var selects = document.getElementsByTagName("select");
	var textareas = document.getElementsByTagName("textarea");
	var inputs = document.getElementsByTagName("input");
	var buttons = document.getElementsByTagName("button");

	for (i = 0; i < textareas.length; i++){
		textareas[i].onclick = function(){
			var currid = document.getElementById(this.id);
			if ((currid) && (currid.id == "nps-fb-text" + idSuffix)){
				var currval = this.value;
				if (currval == "Please enter feedback"){
					document.getElementById(this.id).value = "";
				}
			}
		}
	}
	for (i = 0; i < inputs.length; i++){
		inputs[i].onclick = function(){
			var currid = document.getElementById(this.id);
			if ((currid) && (currid.id == "nps-fb-email" + idSuffix)){
				var currval = this.value;
				if (currval == "Your email address (opt.)"){
					document.getElementById(this.id).value = "";
				}
			}
		}
	}
	for (i = 0; i < inputs.length; i++){
		inputs[i].onblur = function(){
			var currid = document.getElementById(this.id);
			if ((currid) && (currid.id == "nps-fb-email" + idSuffix)){
				var currval = this.value;
				if (currval == ""){
					document.getElementById(this.id).value = "Your email address (opt.)";
				}
			}
		}
	}
}

// Close the feedback form
function closeFeedback(IdVal,lan,NpsThanksMsg) {
		
	  	 if (document.getElementById('NPSWidgetLink'))
		{
		document.getElementById('closeMiniDiv'+IdVal).innerHTML="<a href='javascript:hideNPSPopup();' style='text-decoration:none;'>Close <img src='http://"+widgetServer+"/nps_widget/images/icon_close.gif' border='0'/></a>";
		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
			}
		}

	 //code for IE
	 if (window.ActiveXObject)
		{

		
			if (curtop>350)
			{
				
				if (document.getElementById('nps_widget_script'))
				{
					document.getElementById('nps_widget_script').style.top="-100px";
				}
			
			}
			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_widget_script'))
				{
					document.getElementById('nps_widget_script').style.top="-100px";
				}
				
			
			}
		}
	}
	document.getElementById("nps-fb-box" + IdVal).style.visibility = "hidden";
	document.getElementById("nps-sidebar" + IdVal).style.marginBottom = "10px";
	(function($) {
	$.getJSON("http://" + widgetServer + "/nps_widget/scripts/Jsonp.php?url=http://" + widgetServer + "/nps_widget/l10n/getLang.php&lang="+lan+"&jsoncallback=?", function(data){
		
		
		$.each(data.texts, function(i,item){


	var recDiv = document.getElementById("nps-recommend" + IdVal);
	var Msg = document.createElement("span");
	Msg.setAttribute("id","nps-conf" + IdVal);
	Msg.className = "nps-conf";
	if (NpsThanksMsg=="")
	{
		var thxTxt = document.createTextNode(item.nps_thanks);
	}
	else
	{
		//var NpsThanksMsg='"'+NpsThanksMsg+'"';
		NpsThanksMsg=truncate(NpsThanksMsg, "37");
		var thxTxt = document.createTextNode(NpsThanksMsg);
	}
	

	// First remove element if it exists so we don't show multiple messages
	if (document.getElementById("nps-conf" + IdVal)){
		var recSpan = document.getElementById("nps-conf" + IdVal);
		recDiv.removeChild(recSpan);
	}

	Msg.setAttribute("id","nps-conf-success" + IdVal);
	Msg.className = "nps-conf-success";

	recDiv.appendChild(Msg);
	Msg.appendChild(thxTxt);
	fade("nps-conf-success" + IdVal);

	/*
	for (i=0;i< indexes.length;i++ )
	{
		if (indexes[i]!=IdVal)
		{
			document.getElementById('nps-sidebar'+indexes[i]).style.display="block";
		}
	}

	  */
	// Hide the feedback box
	


		 });
		 
		
		});

		})(jQuery);//

}

function validEmail(email) {
	var valid = false;
	var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(email)) valid = true;
	return valid;
}

function validate(idVal,widgetProjId,lan,NpsThanksMsg) {
	//alert("validfate: "+NpsThanksMsg);
	var valid = false;
	var form = document.getElementById("nps-form" + idVal);
	var email = document.getElementById("nps-fb-email" + idVal);
	var fb_textbox=document.getElementById("nps-fb-text"+idVal);
	// Set class to it's default
	email.className = "nps-fb-email";
	if (fb_textbox.value==""&&feedback_mandatory=="yes")
	{
	   //fb_textbox.className = "nps-fb-text-invalid";
	   
		 fb_textbox.className = "nps-fb-text-invalid";
		 valid = false;
	 	   
	}
	
	else if ((email.value != emailEmpty) && (email.value != emailInvalid)){ 
		
		// Make sure error text isn't in the email field
		if (!validEmail(email.value)) {
			email.className = "nps-fb-email-invalid";
			temp = email.value; // Store user's entry for re-use
			email.value = emailInvalid;
			valid = false;
			
		}
		else
		{
			valid=true;
		}
	}
	//else { // Error text is in email field so re-instate invalid css class
		else if (email.value == emailEmpty) {
		
			email.className = "nps-fb-email";
			valid = true;
			
		}
		else if (email.value == emailInvalid)
		 {
		
			email.className = "nps-fb-email-invalid";
			valid = false;
			
		}

		else
		{
		
			valid= true;
		}
	//}

	//if (valid) // Form is valid so let's submit
	if(valid)
	{
		postFeedback('http://' + widgetServer + '/nps_widget/scripts/feedback.php',idVal,widgetProjId,lan,NpsThanksMsg);
	}
}



function updateContents(field) {

	//var field=document.getElementById(field.id);
	if (field.value == emailEmpty) { // Check if field contains email error text
		if (temp != "")
			field.value = temp;
		else
			field.value = "";

		//field.setAttribute('onblur','restoreContents("'+fieldId+'")');
		
	}

	field.onblur=function(){restoreContents(field);}

	
}

function restoreContents(field) {
	
	//var fieldId=document.getElementById(fieldId.id);
	if (field.value != emailInvalid) { // Check if field contains email error text
		
			if (field.value=="")
			{
				field.value = emailEmpty;
			}
			
	}
}

		/**
         * Get Localized Text (based on number of projects added) 
    
         * @param {String} projLang: Project language defined in the script on nps.php , if no it will take default English (en) 
         * @returns all the localized texts define in the properties file
         */

function compensateWidth(el, targetWidth) {

	var removeUnit = function(str) {
		if (str.indexOf('px')) {
			return str.replace('px', '') * 1;
		}
		else { 
			return 0;
		}
	}

	if (document.compatMode && document.compatMode == "BackCompat") {

alert("targetWidth=" + targetWidth);
alert("el.offsetWidth=" + el.offsetWidth);

		if (targetWidth && el.offsetWidth < targetWidth) {
			el.width = targetWidth;
		}
		else if (el.className) {
			var borders  = removeUnit(el.style.borderLeftWidth) + removeUnit(el.style.borderRightWidth);
			var paddings = removeUnit(el.style.paddingLeft)     + removeUnit(el.style.paddingRight);
			el.width = el.offsetWidth + borders + paddings + 'px';

alert("el.width=" + el.width);
		}
	}
}
function hideNPSPopup()
{
	if (document.getElementById('nps_widget_script'))
	{
		document.getElementById('nps_widget_script').style.display="none";
		document.getElementById('NPSWidgetLink').style.display="block";
	}
}
function showWRTWidget()
{
	
	if (document.getElementById('WRTloadingImage'))
	{
		document.getElementById('WRTloadingImage').style.display="none";	
		document.getElementById('nps_widget_div').style.display="block";
	}
}

function truncate(str, limit) {

	
	var bits, i;

	bits = str.split('');

	if (bits.length > limit) {
		for (i = bits.length - 1; i > -1; --i) {
			if (i > limit) {
				bits.length = i;
			}
			else if (' ' === bits[i]) {
				bits.length = i;
				break;
			}
		}
		bits.push('...');
	}
	return bits.join('');
}