function checkApprovalDate(source, arguments)
{
	if (CorrectDate(ValidatorGetValue("ddlApprovalDay"), ValidatorGetValue("ddlApprovalMonth"), ValidatorGetValue("ddlApprovalYear") ))
	{
		return true;
	}
	else
	{
		return false;
	}

	return true;
}

function checkEndIntervalDate(source, arguments)
{
	if (CorrectDate(ValidatorGetValue("ddlEndIntervalDay"), ValidatorGetValue("ddlEndIntervalMonth"), ValidatorGetValue("ddlEndIntervalYear") ))
	{
		return true;
	}
	else
	{
		return false;
	}

	return true;
}

function checkBeginIntervalDate(source, arguments)
{
	if (CorrectDate(ValidatorGetValue("ddlBeginIntervalDay"), ValidatorGetValue("ddlBeginIntervalMonth"), ValidatorGetValue("ddlBeginIntervalYear") ))
	{
		return true;
	}
	else
	{
		return false;
	}

	return true;
}

function openPopup(sURL)
{
		var sProperties;
		var sWindowName;
		sProperties = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrolling=auto,scrollbars=yes,resizable=no,width=700,height=500";
		sWindowName = "ViewDAE";
		window.open(sURL, sWindowName, sProperties);
}

function checkContribution(source, arguments)
{
	var sCtrlName = source.id.split("_")[0];
	return true; // fara avans
}

function checkRevenues(source, arguments)
{
	var sCtrlName = source.id.split("_")[0];
	 
	 
	 ///////////// 
	 checkIsNumeric(ValidatorGetValue(sCtrlName + "_txtSalary"), "Campul \"Salariu NET\" trebuie sa contina doar cifre");
	 checkIsNumeric(ValidatorGetValue(sCtrlName + "_txtRentRevenues"), "Campul \"Venituri din chirii\" trebuie sa contina doar cifre");
	 checkIsNumeric(ValidatorGetValue(sCtrlName + "_txtStockRevenues"), "Campul \"Venituri din dividende\" trebuie sa contina doar cifre");
	 
	 
	 checkIsNumeric(ValidatorGetValue(sCtrlName + "_txtHouseCreditPayments"), "Campul \"Rate la credite pentru locuinta\" trebuie sa contina doar cifre");
	 checkIsNumeric(ValidatorGetValue(sCtrlName + "_txtAlimony"), "Campul \"Popriri\" trebuie sa contina doar cifre");
	 checkIsNumeric(ValidatorGetValue(sCtrlName + "_txtConsoCreditPayments"), "Campul \"Rate la credite de consum\" trebuie sa contina doar cifre");
	 checkIsNumeric(ValidatorGetValue(sCtrlName + "_txtOverdraft"), "Campul \"Overdraft la cardul de salariu\" trebuie sa contina doar cifre");
	 checkIsNumeric(ValidatorGetValue(sCtrlName + "_txtCreditCardLimit"), "Campul \"Limita Card de credit\" trebuie sa contina doar cifre");
	 
	 //////////////
	 
 	var iSalary = new Number(ValidatorGetValue(sCtrlName + "_txtSalary"));
 	var iRentRevenuess = new Number(ValidatorGetValue(sCtrlName + "_txtRentRevenues"));
 	var iStockRevenues = new Number(ValidatorGetValue(sCtrlName + "_txtStockRevenues"));
 	var iTotalR = new Number(0);
	iTotalR = iSalary + iRentRevenuess + iStockRevenues;
	
 	var iHouseCreditPayments = new Number(ValidatorGetValue(sCtrlName + "_txtHouseCreditPayments"));
 	var iAlimony = new Number(ValidatorGetValue(sCtrlName + "_txtAlimony"));
 	var iConsoCreditPayments = new Number(ValidatorGetValue(sCtrlName + "_txtConsoCreditPayments"));
 	var iOverdraft = new Number(ValidatorGetValue(sCtrlName + "_txtOverdraft"));
 	var iCreditCardLimit = new Number(ValidatorGetValue(sCtrlName + "_txtCreditCardLimit"));

	var iTotalE = new Number(0);

	iTotalE = iHouseCreditPayments + iAlimony + iConsoCreditPayments + iOverdraft * 0.02 + iCreditCardLimit * 0.02 ;

	if ( iTotalR > iTotalE)
	{
		return true;
	}
	else
	{
		return false;
	}

	return true;
}



function checkCarPriceNumeric(source, arguments)
{
	var sCtrlName = source.id.split("_")[0];

    return checkIsNumeric(ValidatorGetValue(sCtrlName + "_txtCarPrice"), "Campul \"Pretul autoturismului\" trebuie sa contina doar cifre");
}

function checkContributionNumeric(source, arguments)
{
	var sCtrlName = source.id.split("_")[0];

    return checkIsNumeric(ValidatorGetValue(sCtrlName + "_txtContribution"), "Campul \"Aport\" trebuie sa contina doar cifre");
}


function checkAmountNumeric(source, arguments)
{
	var sCtrlName = source.id.split("_")[0];

    return checkIsNumeric(ValidatorGetValue(sCtrlName + "_txtAmount"), "Campul \"Suma\" trebuie sa contina doar cifre");
}

function checkIsNumeric(sField, sErrorMessage)
{
	for (var i = 0; i < sField.length ; i++) 
	{ 
		var sChar = sField.substring(i, i + 1); 
		if (sChar < "0" || "9" < sChar) 
			{
				alert(sErrorMessage);
				return false;
			} 
	} 

	return true; // correct
}

function checkEmailwww(source, arguments)
{
	var sCtrlName = source.id.split("_")[0];
	 
 	var sEmail = ValidatorGetValue(sCtrlName + "_txtEmail");

	if (sEmail.indexOf('www') > -1)
	{
		return false;
	}

	return true;
}

function checkYahooRO(source, arguments)
{
	var sCtrlName = source.id.split("_")[0];
	 
 	var sEmail = ValidatorGetValue(sCtrlName + "_txtEmail");

	if (sEmail.indexOf('yahoo.ro') > -1)
	{
		return false;
	}

	return true;
}

function checkYahooIncorrect(source, arguments)
{
	var sCtrlName = source.id.split("_")[0];
	 
 	var sEmail = ValidatorGetValue(sCtrlName + "_txtEmail");

	// 1. yahoo nu accepta semnul - in adrese
	if ( (sEmail.indexOf('yahoo') > -1) && (sEmail.indexOf('-') > -1) )
	{
		return false;
	}

	// 2. yahoo nu accepta semnul . in adrese
	if ( (sEmail.indexOf('yahoo') > -1) && (sEmail.split('@')[0].indexOf('.') > -1) )
	{
		return false;
	}
	
	var arrBannedStrings = new Array(7);
    var iIndex = 0;

	arrBannedStrings[iIndex++] = "yahooo.com";
	arrBannedStrings[iIndex++] = ".comm";
	arrBannedStrings[iIndex++] = "yah00.com";
	arrBannedStrings[iIndex++] = "iahoo.com";
	arrBannedStrings[iIndex++] = "@com.ro";
	arrBannedStrings[iIndex++] = "yaho.coom";
	arrBannedStrings[iIndex++] = "yaho.coom";
	arrBannedStrings[iIndex++] = "xxxxxx";

	for (var i = 0; i < arrBannedStrings.length ;i++ )
	{
		if (sEmail.indexOf(arrBannedStrings[i]) > -1)
		{
			return false;
		}
	}

	return true;
}

function CorrectDate(sDay, sMonth, sYear)
{
	var iDay = new Number(sDay);
	var iMonth = new Number(sMonth);
	var iYear = new Number(sYear);

	if (iDay>30 && (iMonth==2||iMonth==4||iMonth==6||iMonth==9||iMonth==11)) return false;
	
	if (iMonth==2)
	{
		if (iDay > 29)  return false;
		if ((iDay > 28) && !(((iYear % 4)==0) && ((iYear % 100)!=0) || ((iYear % 400)==0))) return false;
	}
	return true;
}

function CorrectDate(sDay, sMonth, sYear)
{
	var iDay = new Number(sDay);
	var iMonth = new Number(sMonth);
	var iYear = new Number(sYear);

	if (iDay>30 && (iMonth==2||iMonth==4||iMonth==6||iMonth==9||iMonth==11)) return false;
	
	if (iMonth==2)
	{
		if (iDay > 29)  return false;
		if ((iDay > 28) && !(((iYear % 4)==0) && ((iYear % 100)!=0) || ((iYear % 400)==0))) return false;
	}
	return true;
}

function checkBirthDate(source, arguments)
{
	var sCtrlName = source.id.split("_")[0];
	if (CorrectDate(ValidatorGetValue(sCtrlName + "_ddlDay"), ValidatorGetValue(sCtrlName + "_ddlMonth"), ValidatorGetValue(sCtrlName + "_txtBirthYear") ))
	{
		return true;
	}
	else
	{
		return false;
	}

	return true;
}

function checkCorrectDate(source, arguments)
{
	if (CorrectDate(ValidatorGetValue("ddlDay"), ValidatorGetValue("ddlMonth"), ValidatorGetValue("txtLastUpdateYear") ))
	{
		return true;
	}
	else
	{
		return false;
	}

	return true;
}
function checkFirstHireDate(source, arguments)
{
	var sCtrlName = source.id.split("_")[0];
	if (CorrectDate(ValidatorGetValue(sCtrlName + "_ddlFirstHireDay"), ValidatorGetValue(sCtrlName + "_ddlFirstHireMonth"), ValidatorGetValue(sCtrlName + "_txtFirstHireYear") ))
	{
		return true;
	}
	else
	{
		return false;
	}

	return true;
}

function checkNextStepDate(source, arguments)
{
	var sCtrlName = source.id.split("_")[0];
	if (CorrectDate(ValidatorGetValue(sCtrlName + "_ddlNextStepDay"), ValidatorGetValue(sCtrlName + "_ddlNextStepMonth"), ValidatorGetValue(sCtrlName + "_txtNextStepYear") ))
	{
		return true;
	}
	else
	{
		return false;
	}

	return true;
}


function checkEndContractDate(source, arguments)
{
	var sCtrlName = source.id.split("_")[0];
	if (CorrectDate(ValidatorGetValue(sCtrlName + "_ddlEndContractDay"), ValidatorGetValue(sCtrlName + "_ddlEndContractMonth"), ValidatorGetValue(sCtrlName + "_txtEndContractYear") ))
	{
		return true;
	}
	else
	{
		return false;
	}

	return true;
}


function checkLastHireDate(source, arguments)
{
	var sCtrlName = source.id.split("_")[0];
	if (CorrectDate(ValidatorGetValue(sCtrlName + "_ddlLastHireDay"), ValidatorGetValue(sCtrlName + "_ddlLastHireMonth"), ValidatorGetValue(sCtrlName + "_txtLastHireYear") ))
	{
		return true;
	}
	else
	{
		return false;
	}

	return true;
}

function checkExpDate(source, arguments)
{

	var sCtrlName = source.id.split("_")[0];
	if (CorrectDate(ValidatorGetValue(sCtrlName + "_ddlDay"), ValidatorGetValue(sCtrlName + "_ddlMonth"), ValidatorGetValue(sCtrlName + "_txtExpYear") ) )
	{
		return true;
	}
	else
	{
		return false;
	}

	return true;
}
