// JavaScript Document
// it is used to validate a numrical data

function ValidateNo(NumStr, String)
{
    for(var Idx=0; Idx<NumStr.length; Idx++)
    {
        var Char = NumStr.charAt(Idx);
        var Match = false;

        for(var Idx1=0; Idx1<String.length; Idx1++)
        {
            if(Char == String.charAt (Idx1))
                Match = true;
        }

        if (!Match)
            return false;
    }
    return true;
}

function changereadonly_leaves_paid_time_off(){
var x = document.getElementById("CaLeavePaidTimeOff");//alert(x.value);

if(x.checked )
{
document.getElementById("leaves_question11").style.display = "block";

}
else
{
document.getElementById("leaves_question11").style.display = "none";
}	

}
function changereadonly_leaves_compressed_workweek(){
var x = document.getElementById("CaLeaveCompressedWorkweek");//alert(x.value);

if(x.checked )
{
document.getElementById("leaves_question10").style.display = "block";

}
else
{
document.getElementById("leaves_question10").style.display = "none";
}	

}
function changereadonly_leaves_Job_sharing(){
var x = document.getElementById("CaLeaveJobSharing");//alert(x.value);

if(x.checked )
{
document.getElementById("leaves_question9").style.display = "block";

}
else
{
document.getElementById("leaves_question9").style.display = "none";
}	

}
function changereadonly_leaves_telecommuting(){
var x = document.getElementById("CaLeaveTelecommuting");//alert(x.value);

if(x.checked )
{
document.getElementById("leaves_question8").style.display = "block";

}
else
{
document.getElementById("leaves_question8").style.display = "none";
}	

}


function changereadonly_leaves_housing_loan(){
var x = document.getElementById("CaLeaveHousingLoan");//alert(x.value);

if(x.checked )
{
document.getElementById("leaves_question3").style.display = "block";

}
else
{
document.getElementById("leaves_question3").style.display = "none";
}	

}
function changereadonly_leaves_holiday_home_scheme(){
var x = document.getElementById("CaLeaveHolidayHomeScheme");//alert(x.value);

if(x.checked )
{
document.getElementById("leaves_question7").style.display = "block";

}
else
{
document.getElementById("leaves_question7").style.display = "none";
}	

}

function validat_generalinformation()
{
if(document.add_generalinfo.CaGeneralInformationName.value == "")
{
alert("Please Enter Your company Name.");
document.add_generalinfo.CaGeneralInformationName.focus();
return false;
}

if(document.add_generalinfo.CaGeneralInformationWebAddress.value == "")
{
alert("Please Enter Your web address.");
document.add_generalinfo.CaGeneralInformationWebAddress.focus();
return false;
}


if(document.add_generalinfo.CaGeneralInformationPostelAddress.value == "")
{
alert("Please Enter Your postal address.");
document.add_generalinfo.CaGeneralInformationPostelAddress.focus();
return false;
}

if(document.add_generalinfo.CaGeneralInformationYearFounded.value == "")
{
alert("Please Enter Your year founded.");
document.add_generalinfo.CaGeneralInformationYearFounded.focus();
return false;
}

if(document.add_generalinfo.CaGeneralInformationFounderInvolvedCompany.value == "")
{
alert("Please Enter Your founder involved company.");
document.add_generalinfo.CaGeneralInformationFounderInvolvedCompany.focus();
return false;
}

if(document.add_generalinfo.CaGeneralInformationRole.value == "")
{
alert("Please Enter Each of their roles?.");
document.add_generalinfo.CaGeneralInformationRole.focus();
return false;
}

if(document.add_generalinfo.CaGeneralInformationHeadOrganisation.value == "")
{
alert("Please Enter Name of Head of Organization.");
document.add_generalinfo.CaGeneralInformationHeadOrganisation.focus();
return false;
}

return true;
}


function changereadonly_compansation_com_benefit_scheme(){
var x = document.getElementById("CaCompensationComBenefitScheme");//alert(x.value);

if(x.checked )
{
document.getElementById("compansation_question3").style.display = "block";

}
else
{
document.getElementById("compansation_question3").style.display = "none";
}	

}
function changereadonly_compansation_com_com_contribution_pension_plan(){
var x = document.getElementById("CaCompensationComContributionPensionPlan");//alert(x.value);

if(x.checked )
{
document.getElementById("compansation_question4").style.display = "block";

}
else
{
document.getElementById("compansation_question4").style.display = "none";
}	

}
	

// to demographic function for company pay bonus
function changereadonly_company_pay_bonus(){
var x = document.getElementById("company_pay_bonus_1");//alert(x.value);

if(x.checked )
{
	
document.getElementById("demo_question1").style.display = "block";

}
else
{
document.getElementById("demo_question1").style.display = "none";
}	

var y = document.getElementById("company_pay_bonus_0");

if(y.checked )
{
document.getElementById("demo_question1").style.display = "none";

}

}
// to demographic function for Absence rates
function changereadonly_measure_absence_rates(){
var x = document.getElementById("measure_absence_rates_1");//alert(x.value);

if(x.checked )
{
	
document.getElementById("demo_question22").style.display = "block";

}
else
{
document.getElementById("demo_question22").style.display = "none";
}	

var y = document.getElementById("measure_absence_rates_0");

if(y.checked )
{
document.getElementById("demo_question22").style.display = "none";

}

}

function calpercentage(id1,id2,el){
	//alert('hi pankaj');
	el = $(el);
	var num=(document.getElementById(id1).value)*1;
	var den=(document.getElementById(id2).value)*1;//alert(num); alert(den);
	if(den !=0 || num != 0){
		if(num!='' && den!=''){
			el.value = Math.round((num/den)*100);	
		}else{
			el.value = 0;
			}//alert(el.value );
	}else{
		el.value = 0;
	}
}

function calmanagerial(){
	var num=(document.getElementById('CaDemographicManagerialWomen').value)*1;
	var den1=(document.getElementById('CaDemographicJobLevelSupervisory').value)*1;
	var den2=(document.getElementById('CaDemographicJobLevelManagerial').value)*1;
	if(num!='' && den1!='' && den2!=''){
			document.getElementById('CaDemographicPercWomenManagSuperStaff').value = Math.round((num/(den1+den2))*100);	
	}
		
}
function checkall(id1,id2,id3,id4){
	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;
	}
	
}



function validat_benefit(){
	
	if(document.benefit_addform.CaBenefitHourTraining.value == "")
	{
	alert("Please Enter how many hours of training/year do employees receive.");
	document.benefit_addform.CaBenefitHourTraining.focus();
	return false;
	}
	
	if(!ValidateNo(document.benefit_addform.CaBenefitHourTraining.value,"1234567890."))
    {
        alert("Please Enter valid data for how many hours of training/year do employees receive");
        document.benefit_addform.CaBenefitHourTraining.focus();
        return false;
    }
	
	
	return true;
}


function getSelectedTexts (select) {
var r = new Array();
for (var i = 0; i < select.options.length; i++)
if (select.options[i].selected)
r[r.length] = select.options[i].text;
return r;
}

// this function used to shows the selected industry types 
function show_industry () {
  var text= new Array();
	$('CaGeneralInformationShowIndustry').value = getSelectedTexts($('IndustryTypeParentId'));
	//alert(text);
}
// this function used to shows the year 
	function chk_year() {
		if($('CaGeneralInformationOrganisationYearYear').value < $('CaGeneralInformationYearFounded').value){
			alert('This year should not less than year founded');
			return false;
		}
		return true;
	}
	
// this function used to check minmum value
	function chk_min(x, id) {
		//alert(Math.round(9.5));
		if(Math.round(x.value) > Math.round(id.value)){
			alert('This should not be greater than previous question');
			//document.add.CaWorkLifeBalanceLeavePaid.focus();
			return false;
		}
		return true;
	}

// this is used to hide & show on checkbox click
function show_hide(x,obj){
	
	if(x.checked ){
		document.getElementById(obj).style.display = "block";	
	}
	else{
		document.getElementById(obj).style.display = "none";
	}	

}

// this is used to show content
	function show_content(sid){
		if(document.getElementById(sid).style.display == "none"){
			document.getElementById(sid).style.display = "block";
		}else{
			document.getElementById(sid).style.display = "none";
		}
	}
	
	
function show_content1(sid){
		if(document.getElementById(sid).style.display == "none"){
			document.getElementById(sid).style.display = "block";
		}else{
			document.getElementById(sid).style.display = "none";
		}
	}
	
// this is used to hide & show on radio button click
	function radio_showhide(x, obj){
		if(x.checked  && x.value == 1){
			document.getElementById(obj).style.display = "block";	
		}
		else{
			document.getElementById(obj).style.display = "none";
		}
		if(x.checked  && x.value == 0){
			document.getElementById(obj).style.display = "none";
		}
	}

// this is used to hide & show on radio button click
function radio(x, obj){
	
	if(x.checked  && x.value == "subsidiary_division_majority"){
		document.getElementById(obj).style.display = "block";	
	}
	else{
		document.getElementById(obj).style.display = "none";
	}
	if(x.checked  && x.value != "subsidiary_division_majority"){
		document.getElementById(obj).style.display = "none";
	}

}

// to validate the uploaded file must be .doc extension
	function culture2() {
		var extension = new Array();
		extension[0] = ".doc";
		//extension[1] = ".wmv";
		if($('CaSurveyCompanyFileupload').value == ""){
			alert("Please select a file to upload");
			return false;
		}
		else{
			charpos = $('CaSurveyCompanyFileupload').value.search(/'/);
			if(charpos >=0){
			alert("Single quote not allowed in file name");
			return false;
			}
		}
		if($('CaSurveyCompanyFileupload').value != ""){
			var fieldvalue = $('CaSurveyCompanyFileupload').value;
			var thisext = fieldvalue.substr(fieldvalue.lastIndexOf('.'));
			for(var i = 0; i < extension.length; i++) {
	 			if(thisext == extension[i]) { return true; }
	 		}
			alert("Please Upload .doc extension file Only.");
			return false;
		}
		else{
			alert("Please select a file to upload");
			return false;
		}
	}
	
	function culture_audit2() {
		var extension = new Array();
		extension[0] = ".doc";
		extension[1] = ".docx";
		if($('CaSurveyCompanyFileupload').value == ""){
			alert("Please select a file to upload");
			return false;
		}
		else{
			charpos = $('CaSurveyCompanyFileupload').value.search(/'/);
			if(charpos >=0){
			alert("Single quote not allowed in file name");
			return false;
			}
		}
		if($('CaSurveyCompanyFileupload').value != ""){
			var fieldvalue = $('CaSurveyCompanyFileupload').value;
			var thisext = fieldvalue.substr(fieldvalue.lastIndexOf('.'));
			for(var i = 0; i < extension.length; i++) {
	 			if(thisext == extension[i]) { return true; }
	 		}
			alert("Please Upload .doc or .docx extension file Only.");
			return false;
		}
		else{
			alert("Please select a file to upload");
			return false;
		}
	}
	
	function additional_file(id,constant) {
		
		//for culture audit 2 and survey add doc 
		if(constant==1)
			var extension = new Array('.png','.doc','.txt','.gif','.pdf','.jpg','.jpeg','.xls','.ppt','.pps','.zip');
			//for upload file in compopany in admin
		else
			var extension = new Array('.jpg','.jpeg','.doc','.pdf','.txt','.xls','.ppt','.pps','.zip');
		if($(id).value == ""){
			alert("Please select a file to upload additional documents");
			return false;
		}else{
			charpos = $(id).value.search(/'/);
			if(charpos >=0){
			alert("Single quote not allowed in file name");
			return false;
			}
		}
		if($(id).value != ""){
			var fieldvalue = $(id).value;
			var thisext = fieldvalue.substr(fieldvalue.lastIndexOf('.'));
			//alert(thisext);
			if(extension.inArray(thisext)){
				return true;
			}
			else{
			alert("Invalid extension.");
			return false;
			}
		}
		return true;
	}
	// Returns true if the passed value is found in the
	// array. Returns false if it is not.
	Array.prototype.inArray = function (value)
	{
		var i;
		for (i=0; i < this.length; i++) 
		{
			if (this[i] == value) 
			{
			return true;
			}
		}
		return false;
	}
	
// to validate the uploaded file must be .xls extension
	function upload_email_list() {
		//alert('hi pankaj');
		var extension = new Array();
		extension[0] = ".xls";
		extension[1] = ".xlsx";
		if($('image').value == ""){
			alert("Please select a file to upload");
			return false;
		}
		if($('image').value != ""){
			var fieldvalue = $('image').value;
			var thisext = fieldvalue.substr(fieldvalue.lastIndexOf('.'));
			for(var i = 0; i < extension.length; i++) {
	 			if(thisext == extension[i]) { return true; }
	 		}
			alert("Please Upload .xls or .xlsx extension file Only.");
			return false;
		}
		else{
			alert("Please select a file to upload");
			return false;
		}
	}
	

