// cdcdoc.js
// CDC (Tac Web) Document Feedback Form 
// Author: Jim Leonard
// Date: 10/31/2003

// name this window
window.name = "cco_main";
window.focus();


//var domnf	= 'http://tacwebtools.cisco.com/';
//var domnf   = 'http://www.cisco.com/';
//var domnf   = 'http://cco-stage.cisco.com/'; //Need to remove before moving to stage/prod Akhilesh(akmoghe)
var domnf   = 'http://' + location.host + '/';
var pathp	= 'public/support/feedback/';
var path	= 'kobayashi/support/feedback/';
//var sSub	= 'cgi-bin/feedback_dev_new/feedback2techdoc.pl';
//var sSub    = 'cgi-bin/fbdash/survey_submit.pl'; // Commented by Akhilesh Moghe (akmoghe) for FT3.0 changes
//var sSub    = 'cgi-bin/front.x/Support/FBDataCollector/survey_submit.pl'; //FBT3.0 Fields
var sSub    = 'cgi-bin/front.x/feedbk/survey_submit.pl'; 
var fUrl	= domnf + sSub;
var fUrlp	= domnf +	'p'	 + sSub;
var hUrl	= '/' +	path	 + 'need_help.html';
var hUrlp	= '/' +	pathp + 'need_help.html';
var dTtl	= document.title;
var dUrl	= document.URL;

var widthForm = '177';  
var wText = '14'
var hide;
var hn = '<input type=\"hidden\" name=';
var mc = 'class=\"modulecontent\"';
var ds = '&nbsp;&nbsp;'; 
var va = ' valign=\"middle\" ';
var registered;
var formSrc = new Array();


/* Tech docs variables

Added by bcross 30AUG2004

*/

//Constants to serve as indices into the formSrc array, depending on doctype
var FSIndex_Chapter = 0;
var FSIndex_NonChapter = 1;

//var strFBModuleCSSPath = '\"http://sitegen-dev-1.cisco.com/tdtsbook/td-book-fb.css\"'
var strFBModuleCSSPath = '\"http://www.cisco.com/public/support/feedback/js/tt/right/td-book-fb.css\"'

//The FSIndex value corresponding to the doctype for this instance.
var FSIndex = FSIndex_NonChapter;
/*
   
   End TD Variables

*/


// below added by Venkat(vkambham) on 06/21/2004

var dIap=getMeta('iaPath');
var dDid= getMeta('primaryObjectId');
var droadMap = getMeta('roadMap');  // Added by Akhilesh (akmoghe) on 09/21/2005
var dPawsId   = getMeta('document.id'); // Added by Akhilesh (akmoghe) on 09/21/2005

var dTyp;


//error checking added by BRKC(bcross) on 30SEP04
try
{
   dTyp= getMeta('docType');
}
catch(Exception)
{
   dTyp = 'UNKNOWN';
}
//Script will now paint Chapter style survey at the bottom of the page if
//docType contains "CHAPTER" and ioContentSource is CCIM-TD

try
{
   dIocs = getMeta('ioContentSource');  
}
catch(Exception)
{
   dIocs = 'UNKNOWN';
}


var emailnote;
if (dIocs == 'PAWS'){emailnote='single-tac-feedback,feedback2tacweb';}
if (dIocs == 'CCIM-TD'){emailnote='feedback2techdoc';}

// above added by Venkat(vkambham) on 06/21/2004 

if ( noFormByUrl() ) { hide=true; }

if ( !Templates )	{ var Templates=''		}
if ( !UserInputID )	{ var UserInputID=''	}
if ( !session )	{ var session=''		}

function divinate () {
	var rDir	= new RegExp('customer|partner|employee');
	registered = false;
	var f = document.feedback;
	if ( dUrl.match(rDir) ) { registered = true }
	dTtl = stripQuotes(dTtl);
	// not a registered doc public form cgi
	if (!registered) { fUrl = fUrlp }
}

// Execute on the onClick event for the button named Send so that the thanks
// window gets opened to the right size.
function openWindow(f) {
	var windowUrl;
	var windowPar;
	// survey_submit writes to this "thanks" window if a redirect_url is given
	if ( registered && underwhelmed(f) ) {
	windowUrl = domnf + path + 'blank.html';
	windowPar = "scrollbars=yes,width=300,height=200,left=100,top=100";
	}else {
	windowUrl = domnf + path + 'thanks.html';
	windowPar = "scrollbars=yes,width=300,height=170,left=200,top=200";
	}
   
	window.open( windowUrl, "thanks", windowPar );
}

// Check for low rating
function underwhelmed(f) {
	if (	(f.scale_711[2].checked == true) || 
		(f.scale_711[3].checked == true) || 
		(f.scale_711[4].checked == true)) 
		{
			return true;
		}else{
			return false;
	}
}

// Submit process
function submitFeedback() {
	// Sends feedback
	
	
   var f = document.feedback;
   
	if (f.submitswitch.value == "false") {
		openWindow(f);
      f.submit();
      f.reset();
      f.submitswitch.value="true";
	}else { 
		var tsktsk	= 'You have already submitted feedback. If you would like to '
					+ 'make another submission, please click the Reload button.';
		alert(tsktsk);
	}
}

// checks for 1 or 2 and no comment, sends reminder window to add comment
function lowScore() {
	// Reminder window code..				
	var f = document.feedback;
   

	if (((f.scale_711[3].checked == true) || (f.scale_711[4].checked == true)) && (f.text_713.value=='')) {
		windowUrl = 'http://' + location.host + '/public/support/feedback/reminder.html';
      
		windowPar = "scrollbars=yes,status=yes,width=350,height=170,left=200,top=200";
		window.open(windowUrl, "reminder", windowPar);
	}else {

      submitFeedback();
	}
}

// Validates the form, alerts if not minimun answers
function validate() {
	var f = document.feedback;
	var rate=false;
   		// Set reply for low sat
	if ( registered && underwhelmed(f) ) {
			// if a registered doc or tool
			f.redirect_url.value = hUrl
		}else{
			f.redirect_url.value = hUrlp
			}
	// checking for maxlength of comments - Added by vkambham
         if (f.text_713.value!=''){	
   		if(f.text_713.value.length>512) {
   		alert('Your comments must be 512 characters or less');
   		return false;
         }

      
	}
	// True if form minimum met. Validates only on IE
	if ((f.text_713.value != '') & (f.text_713.value != 'No provision for comments on Chapter survey'))  
       {
         rate=true;
       }
	for (i=4; i>=0; i--){
		if (f.scale_711[i].checked) rate=true;
	}
   
	for (i=2; i>=0; i--) {
		if (f.choice_965[i].checked) rate=true;
	}
	if (!rate) {
		alert('Please answer at least one question on the form before submitting.');
		return false;
	}else {
		lowScore(f);
	}
}

function stripQuotes (t) {
	//Replaces quot marks in doc page title to prevent clipping 
	var r1 = /"/g;
	t = t.replace(r1,'(quote)');
	return t;
}

divinate();


//Begin chapter object specific JS
formSrc[FSIndex_Chapter] =
'<link rel=\"Stylesheet\" href=' + strFBModuleCSSPath +' type=\"text/css\">'
+ '<div class=\"feedback-module\">'
+ '	<div class=\"title\">Feedback: Help us help you</div>'
+ '	<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">'
+ '	<form ACTION=\"' + fUrl + '\" NAME=\"feedback\" METHOD=\"POST\" target=\"thanks\" onSubmit=\"return submitForm()\">'
+ '  <tr>'
+ '    <td>'
+ '      <div class="text">Please rate this document.</div></td>'
+ '	<td>'
+ '      <div class=\"input\">'
+ '        <span class=\"radio-margin\">Excellent</span>'
+ '          <input type=\"radio\" name=\"scale_711\" value=\"5\" />'
+ '          <input type=\"radio\" name=\"scale_711\" value=\"4\" />'
+ '          <input type=\"radio\" name=\"scale_711\" value=\"3\" />'
+ '    	  <input type=\"radio\" name=\"scale_711\" value=\"2\" />'
+ '    	  <input type=\"radio\" name=\"scale_711\" value=\"1\" />Poor'
+ '    </td>'
+ '   </tr>'
+ '  <tr>'
+ '    <td>'
+ '        <div class=\"text\">This document solved my problem.</div>'
+ '    </td>'
+ '	<td>'
+ '        <div class=\"input\">'
+ '          <input type=\"radio\" name=\"choice_965\" value=\"2015\" />Yes'
+ '          <input type=\"radio\" name=\"choice_965\" value=\"2016\" />No'
+ '          <input type=\"radio\" name=\"choice_965\" value=\"2017\" />Just Browsing'
+ '        </div>'
+ '    </td>'
+ '   <tr>'
+ '    <td valign="top"><div class="text">Suggestions to improve this document.<br>(512 characters)</div>'
+ '	</td>'
+ '	<td><div class="textarea">'
+ '             <textarea rows="5" cols="30" class="\inputtext\" maxlength=\"512\" wrap=\"virtual\" name="text_713"></textarea>'
+ '            </div></td>'
+ '   </tr>'
+ '   <tr>'
+ '    <td valign="top"><div class="text">If you have provided a suggestion, please enter your full name and e-mail address. This information is optional and allows us to contact you if necessary.</div></td>'
+ '	<td>'
+ '	<table cellpadding="0" cellspacing="0" border="0">'
+ '	<tr>'
+ '	 <td><div class="textlabel">Name </div></td>'
+ '	 </tr>'
+ '	 <tr>'
+ '     <td>'
+ '   <div class="textbox"><input type="text" name=\"name\" size=\"40\"></div></td></tr>'
+ '	<tr>  '
+ '     <td><div class="texttitle">E-mail</div></td></tr>'
+ '	<tr>'
+ '     <td><div class=\"textbox\"><input type="text" name=\"email\" size="40" ></div></td></tr> </table></td>'
+ '	</tr>		  '
+ '<tr><td class="button" valign="bottom" align="right" colspan="5">'
+ '               <input type=\"button\" name=\"Submit\" value=\"Submit\"  onClick=\"validate();\" class=\"content\"></input>'
+ '</td></tr>'
+ '	</table>'
+ hn + '\"doc_title\" value=\" ' + dTtl + '\">'
//Fake comments box
//+ hn + '\"text_713\" value=\"No provision for comments on Chapter survey">'
//+ hn + '\"email\" value=\"\"'
//+ hn + '\"name\" value=\"\"'
+ hn + '\"doc_url\" value=\" ' + document.URL + '\">'
+ hn + '\"referrer_url\" value=\" ' + document.referrer + '\">'
+ hn + '\"feedback_type\" value=\"1\">'
+ hn + '\"survey_id\" value=\"293\">'
+ hn + '\"email_notification\" value=\"' + emailnote + '\">'
+ hn + '\"redirect_url\" value=\"\">'
+ hn + '\"format\" value=\"right\">'
+ hn + '\"submitswitch\" value=\"false\">'
+ hn + '\"doc_type\" value=\" ' + dTyp + '\">'
+ hn + '\"iapath\" value=\" ' + dIap + '\">'
+ hn + '\"docid\" value=\" ' + dDid + '\">'
+ hn + '\"iocontext\" value=\" ' + dIocs + '\">'//above added by Venkat(vkambham)
+ hn + '\"roadMap\" value=\" ' + droadMap + '\">' //added by Akhilesh(akmoghe)
+ hn + '\"PawsId\" value=\" ' + dPawsId + '\">' //added by Akhilesh(akmoghe)
+ '</form>'
+ '</div>';
//End Chapter Doctype specific JS


//Begin non-chapter object specific JS
formSrc[FSIndex_NonChapter] = '<div id=\"feedbackForm\">'
+ '<form ACTION=\"' + fUrl + '\" NAME=\"feedback\" METHOD=\"POST\" target=\"thanks\" onSubmit=\"return submitForm()\">'
+ '        <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\" ' + widthForm + ' \" bgcolor=\"#FFCC66\">'
+ '          <tr>'
+ '            <td width=\"5\"><img src=\"/swa/i/s.gif\" width=\"5\" height=\"17\" alt=\"\"></td>'
+ '            <td width=\"100%\" valign=\"middle\" class=\"moduletitle\">Feedback: Help us help you</td>'
+ '            <td><img src=\"/swa/i/s.gif\" width=\"3\" height=\"1\" alt=\"\"></td>'
+ '            <td valign=\"top\" align=\"right\"><img src=\"/swa/i/corner_ur_7.gif\" width=\"7\" height=\"7\" alt=\"\"></td>'
+ '          </tr>'
+ '        </table>'
+ '        <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\" ' + widthForm + ' \" bgcolor=\"#FFCC66\">'
+ '          <tr>'
+ '            <td>'
+ '              <table border=\"0\" cellspacing=\"1\" cellpadding=\"4\" width=\"100%\">'
+ '                <tr>'
+ '                  <td bgcolor=\"#FFFFCC\" ' +  mc + ' >Please rate this document.<br>'
+ scale711()
+ '                   <img src=\"/swa/i/s.gif\" width=\"1\" height=\"4\" alt=\"\"><br>'
+ '                   This document solved my problem.<br>'
+                       hn + '\"choice_965_desc\" value=\"This document solved my problem(2015=yes,2016=no,2017=browsing)\">'
+ choice965()
+ '                   <img src=\"/swa/i/s.gif\" width=\"1\" height=\"4\" alt=\"\"><br>'
+ '                   Suggestions to improve this document.<br>'
+ '                   <textarea name=\"text_713\" class=\"inputtext\" rows=\"4\" cols=\"' + wText + '\" wrap=\"virtual\" maxlength=\"512\"></textarea><br>'
+ '                   <span class=\"caption\">(512 character limit)</span><br>'
+                        hn + '\"syzygy\" value=\"108\">';

// display name and email fields if public ( there is no horiz display on public
//if ( !registered ) { By Venkat(vkambham) for FT 2.0
formSrc[FSIndex_NonChapter] += '<!-- Writing Public Stuff -->'
+ '                   <img src=\"/swa/i/s.gif\" width=\"1\" height=\"4\" alt=\"\"><br>'
+ '                   If you have provided a suggestion, please enter your full name and e-mail address. This information is optional and allows us to contact you if necessary.<br><br>'
+ '                     <table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" width=\"100%\">'
+ '                       <tr>'
+ '                         <td ' + mc + '>Name:</td>'
+ '                         <td ' + mc + '><input type=\"text\" name=\"name\" size=\"14\" class=\"inputtext\" maxlength=\"80\"></textarea></td>'
+ '             </tr>'
+ '             <tr>'
+ '               <td ' + mc + '>E-mail:</td>'
+ '               <td ' + mc + '><input type=\"text\" name=\"email\" size=\"14\" class=\"inputtext\" maxlength=\"80\"></textarea></td>'
+ '             </tr>'
+ '              </table>';
//}By Venkat(vkambham) for FT 2.0
formSrc[FSIndex_NonChapter] +=        hn + '\"doc_title\" value=\" ' + dTtl + '\">'
+                 hn + '\"doc_url\" value=\" ' + document.URL + '\">'
+                 hn + '\"referrer_url\" value=\" ' + document.referrer + '\">'
+                 hn + '\"feedback_type\" value=\"1\">'
+                 hn + '\"survey_id\" value=\"293\">'
+                 hn + '\"email_notification\" value=\" ' + emailnote + '\">'//added by Venkat(vkambham)
+                 hn + '\"redirect_url\" value=\"\">'
+                 hn + '\"format\" value=\"right\">'
+                 hn + '\"submitswitch\" value=\"false\">'
+                 hn + '\"doc_type\" value=\" ' + dTyp + '\">'// below added by Venkat(vkambham)
+                 hn + '\"iapath\" value=\" ' + dIap + '\">'
+                 hn + '\"docid\" value=\" ' + dDid + '\">'
+                 hn + '\"iocontext\" value=\" ' + dIocs + '\">'//above added by Venkat(vkambham)
+				  hn + '\"roadMap\" value=\" ' + droadMap + '\">' //added by Akhilesh(akmoghe)
+				  hn + '\"PawsId\" value=\" ' + dPawsId + '\">' //added by Akhilesh(akmoghe)
+ '               <div align=\"left\">'
+ '               <input type=\"button\" name=\"Submit\" value=\"Submit\"  onClick=\"validate();\" class=\"content\"></input>'
+ '               </div>'
+ '             </td>'
+ '            </tr>'
+ '           </table>'
+ '          </td>'
+ '        </tr>'
+ '      </table>'
+ '    <img src=\"/swa/i/s.gif\" border=\"0\" alt=\"\" height=\"7\" width=\"1\"><br>'
+ '</form>'
+ '</div>';
//End non-chapter object HTML


/*
If doctype meta tag value contains the string 'CHAPTER' AND the document is a TD doc evidenced by ioContentSource = 'CCIM-TD'
then use the chapter specific element of the formSrc array
*/

if ((dTyp.toUpperCase().indexOf("CHAPTER") > 0) && dIocs.toUpperCase() == "CCIM-TD")
   {
      FSIndex = FSIndex_Chapter;
   }
//If doctype meta tag does not value contains the string "CHAPTER", then use the non-chapter specific element of the formSrc array
else
   {
      FSIndex = FSIndex_NonChapter;
   };

//Write out the proper version, using the FSIndex index into the formSrc array
if ( !hide )
  { document.writeln(formSrc[FSIndex]) }

function scale711 () {
var fields;
var s711 = 'input name=\"scale_711\"  type=\"radio\" value=';
var td = '<td ' + mc + va + '>';
	fields = '<table><tr><td ' + mc + '>'
	+ '<' + s711 + '\"5\">' + ds + 'Excellent</input><br>'
	+ '<' + s711 + '\"4\">' + ds + 'Good</input><br>'
	+ '<' + s711 + '\"3\">' + ds + 'Average</input><br>'
	+ '<' + s711 + '\"2\">' + ds + 'Fair</input><br>'
	+ '<' + s711 + '\"1\">' + ds + 'Poor</input>'
	+ '   </td></tr></table>';
	return fields;
}

function choice965() {
var fields;
var ch965 = 'name=\"choice_965\" type=\"radio\" value=';
	fields = '<table><tr><td ' + mc + ' >'
	+ '       <input ' + ch965 + '\"2015\">' + ds + 'Yes</input><br>'
	+ '       <input ' + ch965 + '\"2016\">' + ds + 'No</input><br>'
	+ '       <input ' + ch965 + '\"2017\">' + ds + 'Just Browsing</input>'
	+ '       </td></tr></table>'; 
	return fields;
}

function noFormByUrl () {
	if ( ckMeta('ioContentSource','CCIM-EP') )	{ return true }
	return false
}
	
function ckMeta (k,v) {
	if (document.getElementsByName) {
	var metaArray = document.getElementsByName(k);
		for (var i=0; i<metaArray.length; i++) {
			if ( metaArray[i].content==v ) { return true }
		}
	return false	
	}	
}

// call noForm in main content cell to stop display.
function noForm(objectId, newVisibility) {
	var styleObject = getStyleObject(objectId);
	if (styleObject) {
	styleObject.visibility = newVisibility;
	return true;
	} else {
	return false;
	}
}

function getStyleObject(objectId) {
	// checkW3C DOM, then MSIE 4.
	if( document.getElementById && document.getElementById(objectId) ) {
	return document.getElementById(objectId).style;
	} else if ( document.all && document.all[objectId] ) {  
	return document.all[objectId].style;
	} else {
	return false;
	}
}

function getMeta (k) {
	try
   {
   var metaArray = document.getElementsByName(k);
	var v=metaArray[0].content;

// Following line commented out by kcolberg on 10/23/2007 to fix long doc load times
//   var dTyp= getMeta('docType');
   }
   catch(Exception)
   {
      return 'UNKNOWN';
   }
	return v;	
}
// This code is written by MY Tech Support team. The purpose is to
// render a link in all CDC documents where ever feedback form appears.
// Above link, when clicked, shall add the document to MYTS portal
// as bookmark.

// This code must be placed in cdcdoc.js right above the code that renders feedback form

// Author - Infosys Technologies Limited
// Date - June 27, 2004.

// This variable needs to be pointing to DEV, STG or PROD server as applicable
//var mytsServerName="http://tools-dev.cisco.com/Support/mytechsupport";

//var mytsImgUrl = mytsServerName+"/images/add_ts_bookmark2.gif";

// Placing the hyperlink and icon
//var strMytacForm="<form name='mytsBkmrkFrm' method='post' action='"+
//				mytsServerName+"/AddToBookmarkServlet'><input type=hidden name='myts_bmtitle' value=''><input type=hidden
//name='myts_bmurl' value=''><TABLE cellSpacing=0 cellPadding=2 align=center border=0><TBODY><TR><TD align=middle><IMG src='"
//				+mytsImgUrl +"' border=0></TD><TD align=middle><A class=contentLink href='Javascript:mytsAddDocToBkmrk();'>Bookmark
//this</A><BR>in <A class=contentBoldLink href='Javascript:mytsAddDocToBkmrk();'>My Tech Support</A></TD></TR></TBODY></TABLE></form>";
//document.writeln(strMytacForm);

// Method to add the document to the user's bookmarks
//function mytsAddDocToBkmrk() {
//    if (document.all){
//        for (var i=0;i < document.all.length; i++){
//            if (document.all(i).tagName == 'META'){
//				if (document.all(i).name =='title'){
//					document.mytsBkmrkFrm.myts_bmtitle.value=document.all(i).content;
//					break;
//
//				}
//			}
//		}
//	}
//	document.mytsBkmrkFrm.myts_bmurl.value=document.location;
//	document.mytsBkmrkFrm.submit();
//}


