// ccSurveyTools.js

function validateName(name) {
  return !(name.indexOf("\"") != -1 || name.indexOf("|") != -1);
}

//------------------------------------------------------------------------
// (new) Survey Tools

function ccSurveyListQN(pg,cx) {
  location.href = "/q?pg="+pg+"&tg=BuildSurveys-listQN&cx="+cx;
}

function ccSurveyEditQN(pg,cx,qnId) {
  u = "/q?pg="+pg+"&tg=BuildSurveys-editQN&cx="+cx;
  if ( qnId ) {
    u += "&questionnaireId="+qnId;
  }
  location.href = u;
}

function ccSurveyDetailQN(pg,cx,qnId) {
  var s="/q?pg="+pg+"&tg=BuildSurveys-detailQN&cx="+cx+"&questionnaireId="+qnId;
  if(typeof(projectId)!='undefined' && projectId!='' && projectId!='-1'){
  	s="/q?pg="+pg+"&tg=EEMM-listQuestionnaire&cx="+cx+"&pId="+projectId;
  }
  location.href = s;
}

function ccSurveyChangeCatQN(pg,cx,qnId) {
  location.href = "/q?pg="+pg+"&tg=BuildSurveys-changeCatQN&cx="+cx+"&questionnaireId="+qnId;
}

function ccSurveyEditPage(pg,cx,qnId,pageIdx,projectId,ftype) {
  var s="/q?pg="+pg+"&tg=BuildSurveys-editPage&cx="+cx+"&questionnaireId="+qnId+"&pageIdx="+pageIdx;
  if(typeof(projectId)!='undefined') s+="&projectId="+projectId;
  if(typeof(ftype)!='undefined') s+="&ftype="+ftype;
  location.href = s;
}

function ccSurveyListContents(pg,cx) {
  location.href = "/q?pg="+pg+"&tg=BuildSurveys-listContents&cx="+cx;
}

function ccSurveyEditContent(pg,cx,contentId) {
  location.href = "/q?pg="+pg+"&tg=BuildSurveys-editContent&cx="+cx+"&contentId="+contentId;
}

function ccEventEditPage(pg,cx,eventId,pageIdx) {
  location.href = "/q?pg="+pg+"&tg=SurveyPublisher-editPage&cx="+cx+"&eventId="+eventId+"&pageIdx="+pageIdx;
}

function surveyEventDetail(pg,cx,eventId) {
  location.href = "/q?pg="+pg+"&tg=SurveyPublisher-eventDetail&cx="+cx+"&eventId="+eventId;
}

//------------------------------------------------------------------------
// Publish survey

function ccPublishListing(pg,cx) {
  location.href = "/q?pg="+pg+"&tg=SurveyPublisher-publishedSurveys&cx="+cx;
}

function ccSurveyEventDetail(pg,cx,eventId) {
  location.href = "/q?pg="+pg+"&tg=SurveyPublisher-eventDetail&cx="+cx+"&eventId="+eventId;
}

function ccPreviewSurvey(cx,id,key) {
  var url = "/survey?pg=survey&loc=P&mode=pv&cx="+cx+"&id="+id+"&ak="+key;
  window.open(url,"previewSurvey","resizable=yes,width=800,height=600,toolbar=no,scrollbars=no");
}

function ccPreviewQuestionnaire(cx,id,key) {
  var url = "/survey?pg=survey&loc=Q&mode=pv&cx="+cx+"&id="+id+"&ak="+key;
  if (arguments[3] && arguments[3]!=""){
  	url+="&projectId="+arguments[3];
  }else{
   if(typeof(projectId)!='undefined'&& projectId!=''){
   	url+="&projectId="+projectId;
   }
  }
  if (arguments[4] && arguments[4]!=""){
    url+="&ftype="+arguments[4];
  }else if(typeof(ftype)!='undefined'){
    url+="&ftype="+ftype;
  }
  if (arguments[5]){
    url+="&themeName="+arguments[5];
  }else if(typeof(themeName)!='undefined'){
    url+="&themeName="+themeName;
  }
  window.open(url,"previewSurvey","resizable=yes,width=800,height=600,toolbar=no,scrollbars=no");
}

function ccStartSurvey(cx,key,loc,eventId,title) {
  var url = "/survey?pg=survey&cx="+cx+"&eventId="+eventId+"&ak="+key+"&loc="+loc;
  if (arguments[5] && arguments[5]!=""){
  	url+="&projectId="+arguments[5];
  }
  if (arguments[6] && arguments[6]!=""){
    url+="&ftype="+arguments[6];
  }else if(typeof(ftype)!='undefined'){
    url+="&ftype="+ftype;
  }  
  
  var ww = window.screen.width - 50;
  var hh = window.screen.height - 100;
  window.open(url,"StartSurvey"+eventId,"top=0,left=0,width="+ww+",height="+hh+",resizable=yes,toolbar=no,scrollbars=yes");
//  window.open(url,"StartSurvey"+eventId,"width=800,height=600,toolbar=no,scrollbars=yes");
  var obj = document.getElementById("" + cx + loc+"_ssurvey_area_"+eventId);
  if ( obj ) {
    obj.innerHTML = title+" <SMALL>" + ccStartSurveyI18n + "</SMALL>"; //i18n "launched";
  }
}

function goToSurvey(i){
  var url = "/survey?pg=survey&cx="+cx+"&eventId="+id+"&ak="+ak+"&loc=" +loc+ "&projectId="+projectId+"&ftype=2" + "&fId=" + fId;
  if(pageNum!="") url = url + "&pageNum=" + pageNum;
  if(bk!="") url = url + "&bk=" + bk;
  if(addr!="") url = url + "&addr=" + addr;
  if(mode!="") url = url + "&mode=" + mode;
  if(i=='0' || i=='1'){
    url = url + "&rpm="+i;
  }
  location.href = url;
}

function startCruiserEval(obj,cx,key,loc,eventId,title,projectId,ftype,facultyId) {
  var url = "/survey?pg=EEMM-preCruiserEval&cx="+cx+"&eventId="+eventId+"&ak="+key+"&loc="+loc+"&projectId="+projectId+"&ftype="+ftype;
  if(facultyId != ''){
    url += "&fId=" + facultyId;
  }
  var ww = window.screen.width - 50;
  var hh = window.screen.height - 100;
  window.open(url,"StartSurvey"+eventId,"top=0,left=0,width="+ww+",height="+hh+",resizable=yes,toolbar=no,scrollbars=yes");
  if ( obj && title!='') {
    obj.innerHTML = title+" <SMALL>" + ccStartSurveyI18n + "</SMALL>"; //i18n "launched";
    obj.onclick = "";
  }
}

function ccShowQuickResults(cx,id,ak) {
  var url = "/q?pg=qsurvey_result&cx="+cx+"&id="+id+"&ak="+ak;
  window.open(url,"SurveyResult"+id,"width=600,height=400,toolbar=no,scrollbars=yes,resizable=yes");
}

function ccQSurveyCleanup(doc,prefix,id) {
  var area = doc.getElementById(prefix+"_qsurvey_area_"+id);
  if ( area ) {
    area.innerHTML = "<DIV CLASS=\"ccBold\" ALIGN=\"CENTER\"><BR/>" + ccQSurveyCleanupI18n + "<BR/><BR/></DIV>"; //i18n, "Your response has been submitted.<BR/>Thank you for your participation.";
  }
}
function ccViewReport(cx,id,rk) {
  var url = "/q?pg=survey_summary_report&cx="+cx+"&id="+id+"&rk="+rk;
  window.open(url,"SummaryReport"+eventId,"width=700,height=500,toolbar=no,scrollbars=yes");
}

ccLoadScript("js/" + ccLang + "/ccSurveyTools-i18n.js");
