var url=null;
var lefturl = null;
var contenturl = null;
var autotimeoutref = 0;
var caautotimeoutref = 0;
var caformid='';
var caobj='';
/*function loadmenu(url1)
{

url = url1;
new Effect.Fade('leftmenu',{afterFinish: loaditem1});
new Effect.Fade('content');
$('content').innerHTML = '';
}*/

var container=null;
function loaddelete(container1,url1)
{
url = url1; 
container=container1;
wipemessage();
if(confirm("Are you sure want to DELETE"))
new Effect.Fade(container,{afterFinish: function(request){new Ajax.Updater(container,url,{asynchronous:true, evalScripts:true,  onComplete: function(request){ new Effect.Appear(container);flashmessage();}, onFailure:function(request){alert('Failure occured due to timeout or server not responding'); return false;}})}});

}

var container=null;
function loadcheckbox(el,container1,url1)
{
if(!el.checked)
return;
url = url1; 
container=container1;
wipemessage();
if(confirm("Are you sure want to select this survey."))
new Effect.Fade(container,{afterFinish: function(request){new Ajax.Updater(container,url,{asynchronous:true, evalScripts:true,  onComplete: function(request){ new Effect.Appear(container);flashmessage();}, onFailure:function(request){alert('Failure occured due to timeout or server not responding'); return false;}})}});

}

var container=null;
function loadbutton(container1,url1){
//if(!el.checked)
//return;
url = url1; 
container=container1;
wipemessage();
if(confirm("Are you sure that you have completed the process of uploading the Employee data."))
new Effect.Fade(container,{afterFinish: function(request){new Ajax.Updater(container,url,{asynchronous:true, evalScripts:true,  onComplete: function(request){ new Effect.Appear(container);flashmessage();}, onFailure:function(request){alert('Failure occured due to timeout or server not responding'); return false;}})}});

}

function loadcontent(container1,url1)
{

url = url1; 
container=container1;
wipemessage();
new Effect.Fade(container,{afterFinish: function(request){new Ajax.Updater(container,url,{asynchronous:true, evalScripts:true,  onComplete: function(request){ new Effect.Appear(container);flashmessage();}, onFailure:function(request){alert('Failure occured due to timeout or server not responding'); return false;}})}});
}

function loadsubcontent(container1,url1)
{

url = url1; 
container=container1;
wipemessage();
new Effect.Fade(container,{afterFinish: function(request){new Ajax.Updater(container,url,{asynchronous:true, evalScripts:true,  onComplete: function(request){ new Effect.Appear(container);flashmessage();}, onFailure:function(request){alert('Failure occured due to timeout or server not responding'); return false;}})}});
}

function loadleftmenucontent(lefturl1,contenturl1)
{
lefturl = lefturl1;
url = contenturl1;
new Effect.Fade('leftmenu',{afterFinish: afterfinishload});
new Effect.Fade('content');
$('content').innerHTML = '';
wipemessage();
}

function loadtopmenucontent(container,lefturl1, tmenuid){
for(i=1;i<=5;i++)
if(i==tmenuid){
$('link'+i).className = 'tmb';
}
else
$('link'+i).className = 'topmenu';
loadcontent(container,lefturl1);
}
// form submission smooth effect
function ajaxformsub(form){
new Effect.Fade('content',{afterFinish: function(request){
new Ajax.Updater('content',$(form).action,{asynchronous:true, evalScripts:true, parameters:Form.serialize($(form).id), onComplete: function (request){new Effect.Appear('content');flashmessage(request); }});}});
}

//shows indicator while form submission
function indicatorformsub(form){
//clearInterval (autotimeoutref);
loading();
new Effect.Fade('content',{afterFinish: function(request){
new Ajax.Updater('content',$(form).action,{asynchronous:true, evalScripts:true, parameters:Form.serialize($(form).id), onComplete: function (request){loaded();new Effect.Appear('content');flashmessage(); }});}});
}
// form submission down to up effect
function searchformsub(form){
new Effect.BlindUp('content',{afterFinish: function(request){
new Ajax.Updater('content',$(form).action,{asynchronous:true, evalScripts:true, parameters:Form.serialize($(form).id), onComplete: function (request){new Effect.BlindDown('content');flashmessage(); }});}});
}


function partialajaxformsub(form,container){
new Effect.Fade(container,{afterFinish: function(request){
new Ajax.Updater(container,$(form).action,{asynchronous:true, evalScripts:true, parameters:Form.serialize($(form).id), onComplete: function (request){new Effect.Appear(container);flashmessage(); }});}});
}

function ajaxmainbodyformsub(form){
new Effect.Pulsate('mainbody',{afterFinish: function(request){
new Ajax.Updater('mainbody',$(form).action,{asynchronous:true, evalScripts:true, parameters:Form.serialize($(form).id), onComplete: function (request){new Effect.Grow('content');flashmessage(); }});}});
}

/*
function autoformsubmit(form){
alert("Time out");
ajaxformsub(form);
}
*/

function flashmessage(request)
{
new Ajax.Updater('message',"/pages/showmessage/",{asynchronous:true, evalScripts:true });
setTimeout("wipemessage()",10000);
}

function wipemessage(){
if($('message'))
$('message').innerHTML='';
}


var gui={
    updateContent:function(){
        $('content').visualEffect('Highlight');
    }
}

function afterfinishload(request)
{
new Ajax.Updater('leftmenu',lefturl,{asynchronous:true,  
 onComplete: new Effect.Appear('leftmenu',{afterFinish: new Ajax.Updater('content',url,{asynchronous:true, evalScripts:true, 
 onComplete:onMenuLoad , onFailure:function(request){alert('Failure occured due to timeout or server not responding'); return false;}})}),evalScripts:true, onFailure:function(request){alert('Failure occured due to timeout or server not responding'); return false;}});
}

function change(me, url)
{
var x = $(me).value;
new Ajax.Request(url,{asynchronous:true,  
 onComplete: function(request){alert("Request successfully completed"); return false;},evalScripts:true, parameters:'value='+x, onFailure:function(request){alert("Request not successfully completed"); return false;}});
}
function ajaxrequest(url){
loading();
new Ajax.Request(url,{asynchronous:true,onComplete: function(request){loaded();alert("Request successfully completed"); return false;},evalScripts:true, parameters:'value='+x, onFailure:function(request){loaded();alert("Request not successfully completed"); return false;}});
}

function change1(me,fname ,url)
{
var x = fname;
new Ajax.Request(url,{asynchronous:true,  
 onComplete: function(request){alert("Request successfully completed"); return false;},evalScripts:true, parameters:'value='+x, onFailure:function(request){alert("Request not successfully completed"); return false;}});
}
/*
function loaditem1(request)
{
wipemessage();
lefturl = url+'left_menu/';
new Ajax.Updater('leftmenu',url+'/left_menu/',{asynchronous:true,  
 onComplete: loaditem2,evalScripts:true, onFailure:function(request){alert('Failure occured due to timeout or server not responding'); return false;}});
}
function loaditem2(request)
{
new Effect.Appear('leftmenu',{afterFinish: loaditem3});
}

function loaditem3(request)
{
new Ajax.Updater('content',url,{asynchronous:true, evalScripts:true, 
 onComplete:onMenuLoad , onFailure:function(request){alert('Failure occured due to timeout or server not responding'); return false;}});
}
*/
function onchangeupdate(id, me, url,modelname)
{
var a = $(me).value;
new Ajax.Updater(id,url+a+'/'+modelname, {asynchronous:true, evalScripts:true, condition: $(me).value != 0, onComplete: new Effect.Appear(id, {duration: 16})});
}
function myupdator(id, me, url,modelname)
{
var a = $(me).value;
if(a == 0) return false;
a = a+'^';
new Ajax.Updater(id,url+a+'/'+modelname, {asynchronous:true, evalScripts:true, condition: $(me).value != 0, onComplete: new Effect.Appear(id, {duration: 16})});

}
function myupdator11(id, me, url,url2,modelname)
{id2 = "sub2";
var a = $(me).value;
if(a == 0) return false;
a = a+'^';
new Ajax.Updater(id,url+a+'/'+modelname, {asynchronous:true, evalScripts:true, condition: $(me).value != 0, onComplete: new Effect.Appear(id, {duration: 16})});
new Ajax.Updater(id2,url2+a+'/'+modelname, {asynchronous:true, evalScripts:true, condition: $(me).value != 0, onComplete: new Effect.Appear(id, {duration: 16})});
}

function reportpdator(el){
var srcElement = $(el).value;
switch (srcElement){
case (srcElement="1"):
case (srcElement="3"):
$('report').style.display= 'block';
$('notes').style.display= 'none';
$('bench').style.display= 'none';
break;

case (srcElement="4"):
$('notes').style.display= 'block';
$('report').style.display= 'none';
$('bench').style.display= 'none';
break;

case (srcElement="5"):
$('bench').style.display= 'block';
$('report').style.display= 'none';
$('notes').style.display= 'none';
break;

case (srcElement="0"):
$('bench').style.display= 'none';
$('report').style.display= 'none';
$('notes').style.display= 'none';
break;
}
}
function careportpdator(el){
var srcElement = $(el).value;
switch (srcElement){
case (srcElement="1"):
$('company').style.display= 'none';
break;

case (srcElement="2"):
$('company').style.display= 'block';
break;
case (srcElement="0"):
$('company').style.display= 'none';
break;
}
}
function onMenuLoad(){
new Effect.Appear('content');
var x=[];
x['data[menu][leftside]']=lefturl;
x['data[menu][rightside]']=url;
new Ajax.Request('/gsp-dev/pages/set_left_menu_session/',{asynchronous:true,  parameters: x, method: 'post'});
}
function call(obj, surveyId){
if(obj.selectedIndex == 0)
return false;
if(obj.selectedIndex == 1)
loadcontent("content","/surveys/consulting_survey_quection/" + surveyId);
}

// in companies view at create_user for drop down list of company_contacts by Avinash
function calling(obj, companyid, type_id){
if(obj.selectedIndex == 0)
return false; 
if(obj.selectedIndex != 0)
loadcontent("content","/master_emails/create_user/"+companyid+'/'+obj.value);
}
// above function is used for drop down list of company_contacts by Avinash

// to select the mail type for Survey Candidate List Mail 
function calling_candidate_mail(obj, survey_id, candidate_id){
if(obj.selectedIndex == 0)
return false; 
if(obj.selectedIndex != 0)
window.location.href="/master_emails/survey_candidate_send_mail/"+survey_id+'/'+candidate_id+'/'+obj.value;
}
// above function is used for select the mail type from Company mail

// to select the mail type from Company mail
function calling_mail(obj, companyid, page){
if(obj.selectedIndex == 0)
return false; 
if(obj.selectedIndex != 0)
window.location.href="/master_emails/contact_select_mail/"+companyid+'/'+obj.value+page;
}
// above function is used for select the mail type from Company mail
// to select the services data
function calling_service(obj){
if(obj.selectedIndex == 0)
return false; 
if(obj.selectedIndex != 0)
loadcontent("content","/invoices/populate_service/"+obj.value);
}

// to select the mail type from Study Company mail
function calling_study_company_mail(obj, companyid, page){
if(obj.selectedIndex == 0)
return false; 
if(obj.selectedIndex != 0)
window.location.href="/master_emails/study_company_send_mail/"+companyid+'/'+obj.value+page;
}
// above function is used for select the mail type from Study Company mail


// to select the mail type from survey mail
function mail_type(obj, survey_id, check){
if(obj.selectedIndex == 0)
return false; 
if(obj.selectedIndex != 0)
window.location.href="/survey_emails/send/"+survey_id+'/'+obj.value+'/'+check;
}

function calling_mail_type(obj, study_survey_id, companyid, contact_id, sample_id, page){
if(obj.selectedIndex == 0)
return false; 
if(obj.selectedIndex != 0)
window.location.href="/master_emails/contact_edit_mail/"+study_survey_id+'/'+companyid+'/'+contact_id+'/'+obj.value+'/'+sample_id+page;
}
// above function is used for select the mail type from Contact mail

function contact_mail_type(obj, companyid, contact_id, sample_id){
if(obj.selectedIndex == 0)
return false; 
if(obj.selectedIndex != 0)
window.location.href="/master_emails/contact_mail/"+companyid+'/'+contact_id+'/'+obj.value+'/'+sample_id;
}
// above function is used for select the mail type from Contact mail

// below function is used for select the mail type from Study Survey 2009 at Company detail
function study_contact_mail_type(obj, companyid, contact_id, sample_id){
if(obj.selectedIndex == 0)
return false; 
if(obj.selectedIndex != 0)
window.location.href="/master_emails/study_contact_mail/"+companyid+'/'+contact_id+'/'+obj.value+'/'+sample_id;
}
// above function is used for select the mail type from Study Survey 2009 at Company detail


/*this function use for the live date and time by nilesh*/
function goforit(){
if (document.all||document.getElementById)
setInterval("getthedate()",1000)
}
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
function getthedate(){
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var hours=mydate.getHours()
var minutes=mydate.getMinutes()
var seconds=mydate.getSeconds()
var dn="AM"
if (hours>=12)
dn="PM"
if (hours>12){
hours=hours-12
}
if (hours==0)
hours=12
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
//change font size here
var cdate="<small><font color='FFFFFF' face='Arial' size='1px' weight='800'><span class='copyright'>"+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+" "+hours+":"+minutes+" "+dn+" </span></font></small>"
if (document.all)
document.all.clock.innerHTML=cdate
else if (document.getElementById)
$("clock").innerHTML=cdate
else
document.write(cdate)
}
// this is used for doing readonly the text box 
function changestate(x,id){
if(x.checked ){
($(id)).removeAttribute('disabled');
    }else{
($(id)).setAttribute('disabled',true);
} 
}

// this is used for select all check boxes on particular one
function checkall(id1,id2,id3,id4){
//alert('sara');
if(document.getElementById(id1).checked){
document.getElementById(id2).checked=1;
document.getElementById(id3).checked=1;
document.getElementById(id4).checked=1;
}else{
document.getElementById(id2).checked=0;
document.getElementById(id3).checked=0;
document.getElementById(id4).checked=0;
}
}

// to add the Demographic Survey Options
function addoptiontoquestion()
{
m=$('max').value*1;
x= $('opt');
tr = document.createElement("tr");
t1=document.createElement("td");
t1.setAttribute('class', 'textbox');
t1.innerHTML = 'Option '+(m+1)+' :';
t2=document.createElement("td");
d=document.createElement("div");
l=document.createElement("label");
t=document.createElement("textarea");
l.setAttribute( 'for', 'DemographicSurveyOptionOption'+(m+1));
t.cols = 40;
t.rows = 1;
t.id = 'DemographicSurveyOptionOption'+(m+1);
t.name = 'data[DemographicSurveyOption][option_'+(m+1)+']';
d.appendChild(l);
d.appendChild(t);
t2.appendChild(d);
tr.appendChild(t1);
tr.appendChild(t2);
x.appendChild(tr);
$('max').value=m+1;
}
function addoption() {
m=$('max').value*1;
x= $('opt');
tr = document.createElement("tr");
t1=document.createElement("td");
t1.setAttribute('class', 'textbox');
t1.innerHTML = 'Option '+(m+1)+' :';
t2=document.createElement("td");
d=document.createElement("div");
l=document.createElement("label");
t=document.createElement("textarea");
l.setAttribute( 'for', 'DemographicOptionOption'+(m+1));
t.cols = 40;
t.rows = 1;
t.id = 'DemographicOptionOption'+(m+1);
t.name = 'data[DemographicOption][option_'+(m+1)+']';
d.appendChild(l);
d.appendChild(t);
t2.appendChild(d);
tr.appendChild(t1);
tr.appendChild(t2);
x.appendChild(tr);
$('max').value=m+1;
}

// to add the Demographic Survey Options
function addoptiontoselect()
{
m=$('max').value*1;
x= $('opt');
tr = document.createElement("tr");
t1=document.createElement("td");
t1.setAttribute('class', 'textbox');
t1.innerHTML = 'Option '+(m+1)+' :';
t2=document.createElement("td");
d=document.createElement("div");
l=document.createElement("label");
t=document.createElement("textarea");
l.setAttribute( 'for', 'SelectSurveyOptionOption'+(m+1));
t.cols = 40;
t.rows = 2;
t.id = 'SelectSurveyOptionOption'+(m+1);
t.name = 'data[SelectSurveyOption][option_'+(m+1)+']';
d.appendChild(l);
d.appendChild(t);
t2.appendChild(d);
tr.appendChild(t1);
tr.appendChild(t2);
x.appendChild(tr);
$('max').value=m+1;

}
// Function use for candidate select to survey
function CandidateCheckAll(form)
{
var f = $('ajaxform_add');
count =f.elements.length;
    for (i=0; i < count; i++) 
  {
    if(f.elements[i].checked == 0)
      f.elements[i].checked = 1;
   
  }
}

function CandidateUncheckAll(form){

var f = $('ajaxform_add');
count = f.elements.length;
    for (i=0; i < count; i++) 
  {
    if(f.elements[i].checked == 1)
      f.elements[i].checked = 0; 
   
  }
}

var container=null;
function closesuvey(container1,url1,name1)
{
url = url1; 
container=container1;
name=name1;
wipemessage();
if(confirm("Are you sure want to CLOSE '" + name+"'"))
new Effect.Fade(container,{afterFinish: function(request){new Ajax.Updater(container,url,{asynchronous:true, evalScripts:true,  onComplete: function(request){ new Effect.Appear(container);flashmessage();}, onFailure:function(request){alert('Failure occured due to timeout or server not responding'); return false;}})}});
}

function GoPreviousIndicator(aForm)
{
  iSkipValidation=1;
 $('previouspagebtn').value="clicked";
   indicatorformsub(aForm);
}

function waGoPreviousIndicator(aForm)
{
  iSkipValidation=1;
 $('previouspagebtn').value="clicked";
   $(aForm).submit();
}

function GoPreviousPage(aForm)
{
  iSkipValidation=1;
 $('previouspagebtn').value="clicked";
   ajaxformsub(aForm);
}

function setHidden(aForm, hid){
  iSkipValidation=1;
 $(hid).value="clicked";
   ajaxformsub(aForm);
}

function finishlater(aForm)
{
  iSkipValidation=1;
  $('finlater').value="clicked";
$(aForm).submit();
}
// this is used to finish later culture I
function ca_finishlater(aForm, obj){
//alert(aForm);
 if(!confirm('Finish later will save the responses but need to submit again in future to include the responses the survey.')){
 return false;
  }
  var frmvalidator  = new Validator(obj);
  frmvalidator.clearAllValidations();
  $('finlater').value="clicked";
  $(aForm).submit();
}
// to erase the answer in Paper Survey Operator
function erase_answer(answer1,answer2){
for(b=1; b<=5; b++){
$(answer1+'_'+b).checked=false;
$(answer2+'_'+b).checked=false;

}
}
function list_erase_answer(answer2){
for(b=1; b<=5; b++){
$(answer2+'_'+b).checked=false;
}
}

//to erase answers in other survey type
function other_erase_answer(qid, ratingcount, responses){
for(i=1; i<= responses; i++)
for(j=1; j<=ratingcount;j++)
$('answer'+i+'_'+qid+'_'+j).checked = false;

}
/*
function chkForm1()
{
if(document.add_emailist['candidate_email'].value == "")
{

alert("Please Upload Email list in Excel Formate e.g. email.xml OR download.xml");
document.add_emailist['candidate_email'].focus();
return false;
}
else 
{
var str = document.add_emailist['candidate_email'].value 
if(str !='')
{
var x = str.lastIndexOf ('.');
str = str.substr(x+1);
if (str != 'xml')
{
alert("This is not the Excel file Please Upload Emails in Excel Formate e.g. email.xml OR download.xml");
document.add_emailist['candidate_email'].select();
return false;
}
}
}
return true;
}
*/
function goto(page){ 
window.location.href=''+page;
}

function addoptiontomaster()
{
m=$('max').value*1;
x= $('opt');
tr = document.createElement("tr");
t1=document.createElement("td");
t1.setAttribute('class', 'textbox');
t1.innerHTML = 'Option '+(m+1)+' :';
t2=document.createElement("td");
d=document.createElement("div");
l=document.createElement("label");
t=document.createElement("textarea");
l.setAttribute( 'for', 'SelectMasterOptionOption'+(m+1));
t.cols = 40;
t.rows = 1;
t.id = 'SelectMasterOptionOption'+(m+1);
t.name = 'data[SelectMasterOption][option_'+(m+1)+']';
d.appendChild(l);
d.appendChild(t);
t2.appendChild(d);
tr.appendChild(t1);
tr.appendChild(t2);
x.appendChild(tr);
$('max').value=m+1;
}
//function used to add rule in 360 survey set
function addrule()
{
x= $('opt');
m=Number($('max').value);
//ty =  document.getElementById('opttype');
y=document.createElement("tr");
z=document.createElement("td");
z.setAttribute('class','normaltext');
z.innerHTML = 'Rule '+(m+1);
z1=document.createElement("td");
option1 =  $("SurveyRuleDesignationId1");
select1 = document.createElement("select");
select1.setAttribute('class','textbox');
select1.setAttribute('name','data[SurveyRule][designation_id_'+(m+1)+']');
for(var i=0;i<option1.options.length;i++)
select1.options[i] = new Option(option1.options[i].text,option1.options[i].value);
z1.appendChild(select1);

z2=document.createElement("td");
option2 = $("SurveyRuleRelationId1");
select2 = document.createElement("select");
select2.setAttribute('class','textbox');
select2.setAttribute('name','data[SurveyRule][relation_id_'+(m+1)+']');
for(var i=0;i<option2.options.length;i++)
select2.options[i] = new Option(option2.options[i].text,option2.options[i].value);
z2.appendChild(select2);

z3=document.createElement("td");
option3 =  $("SurveyRuleSurveySetId1");
select3 = document.createElement("select");
select3.setAttribute('class','textbox');
select3.setAttribute('name','data[SurveyRule][survey_set_id_'+(m+1)+']');
for(var i=0;i<option3.options.length;i++)
select3.options[i] = new Option(option3.options[i].text,option3.options[i].value);
z3.appendChild(select3)

z4=document.createElement("td");
d=document.createElement("div");
l=document.createElement("label");
t=document.createElement("textarea");
l.setAttribute( 'for', 'SurveyRuleMessage1'+(m+1));
t.cols = 35;
t.rows = 2;
t.id = 'SurveyRuleMessage1'+(m+1);
t.setAttribute('class','text');
t.name = 'data[SurveyRule][message_'+(m+1)+']';
d.appendChild(l);
d.appendChild(t);
z4.appendChild(d);
/*z2=document.createElement("td");
z2.innerHTML ='<input name="no_'+(m+1)+'" type="text" value="">';*/
y.appendChild(z);
y.appendChild(z1);
y.appendChild(z2);
y.appendChild(z3);
y.appendChild(z4);
//y.appendChild(z2);
x.appendChild(y);//alert(select1.options[1].value);
$('max').value=m+1;
}

// in Culture Survey at Dimension for user
function loadlinkcontent(container1,url1)
{
  url = url1; 
  container=container1;
  wipemessage();
  new Effect.Fade(container,{afterFinish: function(request){new Ajax.Updater(container,url,{asynchronous:true, evalScripts:true,  onComplete: function(request){ new Effect.Appear(container);flashmessage();}, onFailure:function(request){alert('Failure occured due to timeout or server not responding'); return false;}})}});
}
// in Culture Survey at Dimension for user

// survey Relationship
function addsurveyrelation()
{
x= document.getElementById('opt');
m=Number(document.getElementById('max').value);
//ty =  document.getElementById('opttype');
y=document.createElement("tr");
z=document.createElement("td");
z.setAttribute('class','boldtext');
z.innerHTML = 'Relation '+(m+1);
z2=document.createElement("td");
option2 =  document.getElementById("RelationshipRelationId1");
select2 = document.createElement("select");
select2.setAttribute('class','normaltext');
select2.setAttribute('name','data[Relationship][relation_id_'+(m+1)+']');
for(var i=0;i<option2.options.length;i++)
select2.options[i] = new Option(option2.options[i].text,option2.options[i].value);
z2.appendChild(select2);

z3=document.createElement("td");
option3 =  document.getElementById("RelationshipCandidateId1");
select3 = document.createElement("select");
select3.setAttribute('class','normaltext');
select3.setAttribute('name','data[Relationship][candidate_id_'+(m+1)+']');
for(var i=0;i<option3.options.length;i++)
select3.options[i] = new Option(option3.options[i].text,option3.options[i].value);
z3.appendChild(select3)
y.appendChild(z);
y.appendChild(z2);
y.appendChild(z3);
x.appendChild(y);
document.getElementById('max').value=m+1;
}
/*
function from_list(){
var x = document.getElementById("to_4");
if(x.checked ) {
document.getElementById("form_to").style.display = "block";
}
else {
document.getElementById("form_to").style.display = "none";
}
var y = document.getElementById("to_3");
if(y.checked ) {
document.getElementById("form_to").style.display = "none";
}
var y = document.getElementById("to_2");
if(y.checked ) {
document.getElementById("form_to").style.display = "none";
}
var y = document.getElementById("to_1");
if(y.checked ) {
document.getElementById("form_to").style.display = "none";
}
}
*/
// to make the total of Employees working in India
function make_total(){
var value1=($('CompanyPartTimeEmp').value)*1;
var value2=($('CompanyFullTimeEmp').value)*1;
if(value1!='' || value1==0 && value2!='' || value2==0){
$('CompanyTotalEmp').value = (value1+value2);

} 
}



// to make the total of Employees working in India
function study_make_totals(){
var value1=($('NomineeOrganizationPartTime').value)*1;
var value2=($('NomineeOrganizationFullTime').value)*1;
if(value1!='' || value1==0 && value2!='' || value2==0){
$('NomineeOrganizationTotal').value = (value1+value2);

} 
}


// too check date format
function calcJulian(isDate){
gregDate = new Date(isDate);
year = gregDate.getFullYear();
month = gregDate.getMonth()+1;
day = gregDate.getDate();
A = Math.floor((7*(year+Math.floor((month+9)/12)))/4);
B = day+Math.floor((275*month)/9)
isJulian = (367*year)-A+B+1721014;
return isJulian;
}
function chk_notable_pract1(){
partialajaxformsub('ajaxform_add_12','content');
}

//validate notable_practice
function chk_notable_pract(){
if($('NotablePracticeDescriptionId').value==0){
alert('Plese Select Description');
return false;
}
partialajaxformsub('ajaxform_add_1','content');
}

//validate notable_practice for survey
function chk_survey_notable_pract(){
if($('SurveyNotablePracticeQbyqMastersId').value==0){
alert('Plese Select Description');
return false;
}
partialajaxformsub('ajaxform_add_1','content');
}

//function to check status of mode
function chk_mode_status(status){
currentstat = $('CaCompaniesStatusMode').value;
if(status != currentstat && status != 0){
if(status !=3 && status!=2){
if(currentstat !=1 && currentstat !=0){
answer = confirm("If you select this mode of survey, Invoice will be raised");
if(answer ==0){

return false;
}
}
}
if(status !=1 && status !=0 && currentstat ==1){
result = confirm("If you select this mode of survey, Invoice will be deleted");
if(result ==0){
return false;
}
}
}
return true;
}


function chk_add_employee_comments(cand_id,survey_id){

partialajaxformsub('ajaxform_add_'+cand_id+'_'+survey_id+'','content');
}
//validate create survey
function chk_createsurvey(companyId) {
if(companyId == null){
if($('SurveyCompanyId').value==0){
alert("Please Select Company name");
$('SurveyCompanyId').focus();
return false;
}
}
if($('SurveySurveyType').value==0){
alert("Please Select type");
$('SurveySurveyType').focus();
return false;
}
if($('SurveySurveyCategory').value==0){
alert("Please Select Category");
$('SurveySurveyCategory').focus();
return false;
}
 if($('from').value==''){
alert("Please click on calender to select start date");
$('from').focus();
return false;
}
if($('to').value==''){
alert("Please click on calender to select end date");
$('to').focus();
return false;
}
tmps = $('from').value.split("-");
sDate = tmps[1]+"/"+tmps[0]+"/"+tmps[2];
startDate = calcJulian(sDate);
tmpe = $('to').value.split("-")
eDate = tmpe[1]+"/"+tmpe[0]+"/"+tmpe[2];
endDate = calcJulian(eDate);
if (endDate-startDate < 0){
alert("End Date Must be greater than start date");
$('to').value = "";
$('to').focus();
return false;
}
partialajaxformsub('ajaxform_add','wholecontent');
return false;
}


//validate conert survey from pilot to main
function chk_convertsurvey() {
 if($('from').value==''){
alert("Please click on calender to select start date");
$('from').focus();
return false;
}
if($('to').value==''){
alert("Please click on calender to select end date");
$('to').focus();
return false;
}
tmps = $('from').value.split("-");
sDate = tmps[1]+"/"+tmps[0]+"/"+tmps[2];
startDate = calcJulian(sDate);
tmpe = $('to').value.split("-")
eDate = tmpe[1]+"/"+tmpe[0]+"/"+tmpe[2];
endDate = calcJulian(eDate);
if (endDate-startDate < 0){
alert("End Date Must be greater than start date");
$('to').value = "";
$('to').focus();
return false;
}
partialajaxformsub('ajaxform_add','content');
return false;
}

//validate conert survey from pilot to main
function chk_extendsurvey_date() {
 if($('to').value==''){
alert("Please click on calender to select end date");
$('to').focus();
return false;
}
if($('from').value==''){
alert("Please click on calender to select start date");
$('from').focus();
return false;
}
tmps = $('SurveyOldEnddate').value.split("-");
sDate = tmps[0]+"/"+tmps[1]+"/"+tmps[2];
olddate = calcJulian(sDate);
tmpe = $('to').value.split("-")
eDate = tmpe[2]+"/"+tmpe[1]+"/"+tmpe[0];
newdate = calcJulian(eDate);

tmps1 = $('SurveyOldStartdate').value.split("-");
sDate1 = tmps1[0]+"/"+tmps1[1]+"/"+tmps1[2];
olddate1 = calcJulian(sDate1);
tmpe1 = $('from').value.split("-")
eDate1 = tmpe1[2]+"/"+tmpe1[1]+"/"+tmpe1[0];
newdate1 = calcJulian(eDate1);

/*if (newdate-olddate < 0){
alert("End Date Must be greater than Previous End Date");
$('to').value = "";
$('to').focus();
return false;
}*/
if (newdate-newdate1 < 0){
alert("End Date Must be greater than Start Date");
$('to').value = "";
$('to').focus();
return false;
}
if (newdate1-newdate > 0){
alert("Start Date must be less than End Date");
$('from').value = "";
$('from').focus();
return false;
}
partialajaxformsub('ajaxform','content');
return false;
}

// this for limit a input field.
function limitText(limitField, limitCount, limitNum) {
if (limitField.value.length > limitNum) {
alert('Answer should not more than '+limitNum+' charector');
limitField.value = limitField.value.substring(0, limitNum);
} else {
limitCount.value = limitNum - limitField.value.length;
}
}

//validate create survey
function chk_createlistsurvey() {
if($('from').value==''){
alert("Please click on calender to select start date");
$('from').focus();
return false;
}
if($('to').value==''){
alert("Please click on calender to select end date");
$('to').focus();
return false;
}
tmps = $('from').value.split("-");
sDate = tmps[1]+"/"+tmps[0]+"/"+tmps[2];
startDate = calcJulian(sDate);
tmpe = $('to').value.split("-")
eDate = tmpe[1]+"/"+tmpe[0]+"/"+tmpe[2];
endDate = calcJulian(eDate);
if (endDate-startDate < 0){
alert("End Date Must be greater than start date");
$('to').value = "";
$('to').focus();
return false;
}
partialajaxformsub('ajaxform_add','wholecontent');
return false;
}

// validate Search date From To
function search_date() {
if($('from').value != '' && $('to').value == ''){
alert("Please click on calender to select End Date");
$('to').focus();
return false;
}
tmps = $('from').value.split("-");
sDate = tmps[1]+"/"+tmps[0]+"/"+tmps[2];
startDate = calcJulian(sDate);
tmpe = $('to').value.split("-")
eDate = tmpe[1]+"/"+tmpe[0]+"/"+tmpe[2];
endDate = calcJulian(eDate);
if (endDate-startDate < 0){
alert("End Date Must be greater than start date");
$('to').value = "";
$('to').focus();
return false;
}
ajaxformsub('ajaxform');
return false;
}


function loading(){
$('loading').className = 'loading';
}
function loaded(){
$('loading').className = 'loaded';
flashmessage();
}

// used to convert the integer data into decimals
function res(t,v){
var w = "";
var m = "";
for (i=0; i < t.value.length; i++) {
x = t.value.charAt(i);
if (v.indexOf(x,0) != -1){
if(i==3 && w.indexOf('.',0)==-1)
w += '.';
if(x == '.' &&  w.indexOf('.',0)!=-1)
continue;
w += x;
if(w >100){
w = m;
break;}
m =w;
}
}
t.value = w;
}

// function to check date within 3 months
function chk_nextstepdate(){
if($('from').value == ''){
alert("Please Click on Calendor to Enter Date");
$('from').focus();
return false;
}
//today = new Date();
tmps = $('from').value.split("-");
sDate = tmps[1]+"/"+tmps[0]+"/"+tmps[2];
tmpl = $('CaSurveyCompanyLdate').value.split("-");
lDate = tmpl[1]+"/"+tmpl[0]+"/"+tmpl[2];
tmpt = $('CaSurveyCompanyCreatedate').value.split("-");
tDate = tmpt[1]+"/"+tmpt[0]+"/"+tmpt[2];

if (Date.parse(sDate) > Date.parse(lDate) || Date.parse(sDate) < Date.parse(tDate)) {
alert('Please enter date between '+$('CaSurveyCompanyCreatedate').value+' and '+$('CaSurveyCompanyLdate').value);
return false;
}
partialajaxformsub('ajaxform','content');
return false;
}

// this is used to submit basic information
function add_basicinfo(){
partialajaxformsub('addform','content');
return false;
}
// this is used to submit basic information
function add_basicinfo_keypoints(){
if($('BasicInformationOption').value==0){
alert("Please Select Option");
$('BasicInformationOption').focus();
return false;
}
partialajaxformsub('basic_information','content');
return false;
}


// this is used to submit basic information
function add_master_basicinfo(){

if($('MasterBasicInformationName').value == ""){
alert("Please enter Option name");
$('MasterBasicInformationName').focus();
return false;
}
partialajaxformsub('add_master_option','content');
return false;
}

// this is used to submit detail notes
function add_detail_notes(){
partialajaxformsub('addform','content');
return false;
}
// this is used to submit gr process


function addprocess(){
partialajaxformsub('addhr_process','content');
return false;
}


// this is used to submit master hr process
function add_master_hrp(){
if($('HrProcessName').value == ""){
alert("Please enter HR Process name");
$('HrProcessName').focus();
return false;
}
partialajaxformsub('add_master_hr','content');
return false;

}

function add_child_hrp(){
if($('HrProcessChild').value == ""){
alert("Please enter HR Process name");
$('HrProcessChild').focus();
return false;
}
partialajaxformsub('add_child_hr','content');
return false;

}
////****************for select for multiple options*****************************//
function addOption(selectbox,text,value )
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}

function removeOption(listbox,i)
{
listbox.remove(i);

}
//******** move single value left to right *************//
function addOption_list(){
if(!$('hiddenvalues')){
alert('Hidden field to store values is not available');
return false;
}
for(i=document.drop_list.Category.options.length-1;i>=0;i--){
var Category=document.drop_list.Category;
if(document.drop_list.Category[i].selected){
optionvalue=document.drop_list.Category[i].value;
addOption(document.drop_list.SubCat, document.drop_list.Category[i].text, document.drop_list.Category[i].value);
removeOption(Category,i);
str = $('hiddenvalues').value;
if(str == ''){
$('hiddenvalues').value = ',';
str = ',';
}
$('hiddenvalues').value = str+optionvalue+',';
//alert($('hiddenvalues').value);
}
}
}

//******** move single value right to left *************//
function addOption_list_back(){
if(!$('hiddenvalues')){
alert('Hidden field to store values is not available');
return false;
}
for(i=document.drop_list.SubCat.options.length-1;i>=0;i--){
var SubCat=document.drop_list.SubCat;
if(document.drop_list.SubCat[i].selected){
value = document.drop_list.SubCat[i].value;
addOption(document.drop_list.Category, document.drop_list.SubCat[i].text, document.drop_list.SubCat[i].value);
removeOption(SubCat,i);
str = $('hiddenvalues').value;
myregexp = new RegExp(","+value+",");
$('hiddenvalues').value = str.replace(myregexp,",");
}
}
}

//******** move all value left to right *************//
function move_all_Option(selectbox){
if(!$('hiddenvalues')){
alert('Hidden field to store values is not available');
return false;
}
for(i=document.drop_list.Category.options.length-1;i>=0;i--){
var Category=document.drop_list.Category;
optionvalue=document.drop_list.Category[i].value;
addOption(document.drop_list.SubCat, document.drop_list.Category[i].text, document.drop_list.Category[i].value);
str = $('hiddenvalues').value;
if(str == ''){
$('hiddenvalues').value = ',';
str = ',';
}
$('hiddenvalues').value = str+optionvalue+',';
}
removeAllOptions(document.drop_list.Category);

}

//******** move all value right to left *************//
function move_all_Option_back(selectbox){
if(!$('hiddenvalues')){
alert('Hidden field to store values is not available');
return false;
}
for(i=document.drop_list.SubCat.options.length-1;i>=0;i--){
var SubCat=document.drop_list.SubCat;
value = document.drop_list.SubCat[i].value;
addOption(document.drop_list.Category, document.drop_list.SubCat[i].text, document.drop_list.SubCat[i].value);
str = $('hiddenvalues').value;
myregexp = new RegExp(","+value+",");
$('hiddenvalues').value = str.replace(myregexp,",");
}
if($('hiddenvalues').value == ',')
$('hiddenvalues').value == '';
removeAllOptions(document.drop_list.SubCat);
}

function removeAllOptions(selectbox)
{
var i;
for(i=selectbox.options.length-1;i>=0;i--)
{
selectbox.remove(i);
}
}

function target1(){
if($('ReportType').value =='4'){
if($('ReportNote').value.length >= '650'){
alert('Plese Type Note not more than 650 charector');
alert('Your Current length is '+$('ReportNote').value.length);
return false;
}
}return true;
}

function showRadio(id){
m=$(id); $('showrad').innerHTML = '';//setTimeout("wipemessage()",10000);
var t1 = '<table><tr><td class="text" align ="left"><b>Benchmark</b></td><td class="text" align ="left"><b>Order</b></td></tr>';
x= $('showrad');
var check = '';
var k =1;
var r = new Array();
var first = true;
  for (var i = 0; i < m.options.length; i++){
  if(i == 0)
  continue;
    if (m.options[i].selected){
if(first)
check = 'checked';
else
check = '';
      r[r.length] = i;
t1 += '<tr><td  class = "text" align="right">'+m.options[i].text+' - </td><td align = "left"><input type="text" class="small_textbox" name="data[Report][bm_report_'+m.options[i].value+']" value='+ k +'></td></tr>';
first = false;
k++;}

  }
t1 += '</table>';
$('showrad').innerHTML = t1;
}
//function used to show confirmation msg after submit form
function msg_confirm(formid,container,msg){
var fRet;
fRet = confirm(msg);
if(fRet ==false)
return false;
if(fRet ==true)
partialajaxformsub(formid,container);
}

function msg_confirm_load(container,url,msg){
var fRet;
fRet = confirm(msg);
if(fRet ==false)
return false;
if(fRet ==true)
new Effect.Fade(container,{afterFinish: function(request){new Ajax.Updater(container,url,{asynchronous:true, evalScripts:true,  onComplete: function(request){ new Effect.Appear(container);flashmessage();}, onFailure:function(request){alert('Failure occured due to timeout or server not responding'); return false;}})}});

}

function autorequest(){
clearInterval (autotimeoutref);
autotimeoutref = setInterval("autoajaxcall()",1200000);
}
function autoajaxcall(){
if(!$('autorequesttime')){
clearInterval (autotimeoutref); return false;
}
new Ajax.Request('/pages/autorequest/',{asynchronous:true,  
 onComplete: function(request){/*alert("Request successfully completed");*/ return false;},onFailure:function(request){/*alert("Request not successfully completed");*/ return false;}});
}
function caautosub(formid,obj){
clearTimeout(caautotimeoutref);
caformid=formid;
caobj=obj;
caautotimeoutref = setTimeout("caautoajaxformsub()",1200000);
}
function caautoajaxformsub(){

clearTimeout(caautotimeoutref);
if(!$(caobj)) return false;
alert("Please wait for few moments, we are saving your filled in information Form.");
var frmvalidator  = new Validator(caobj);
  frmvalidator.clearAllValidations();
  $('finlater').value="clicked";
  $('cafinlater').value="clicked";
  $(caformid).submit();

}
function refreshImg() {
var randomNumber = Math.floor(Math.random()*123456);
$("captcha").src = "/pages/captcha/"+randomNumber;
return false;
}
