function openUp(x, y, adress, name) 
{	
	var newOpenUp = window.open(adress, name, 'width=' + x + ', height=' + y + 'resizable=no, scrollbars=yes, menubar=no, location=no, status=no, screenX=1, screenY=1');
	newOpenUp.focus();
}

function doFormFocus(obj) {
	if (obj.value == obj.defaultValue) obj.value = '';
}

function doFormBlur(obj) {
	if (obj.value == '') obj.value = obj.defaultValue;
}

function openMailPopup(page)
{
	mailWindow = window.open('mail.php?page=' + page,'Mail','width=400,height=300,toolbar=No,location=No,scrollbars=Yes,status=No,resizable=No,fullscreen=No');
}


function openPostPopup(category)
{
	mailWindow = window.open('question.php?category=' + category,'intrebari','width=350,height=350,toolbar=No,location=No,scrollbars=Yes,status=No,resizable=No,fullscreen=No');
}


function checkSearch(form, message, defaultValue)
{
	if (form.search.value.length < 3) {
		alert(message);
		return false;
	}
	
	if (form.search.value == defaultValue) {
		return false;
	}
	
	return true;
}


function validateSearchFieldsPage(form)
{
	if (form.search.value.length < 3) {
		alert('Va rugam sa introduceti o expresie mai lunga de 3 carcactere!');
		return false;
	}
	
	if (form.search.value == 'cauta in site') {
		alert('Va rugam sa introduceti termenii de cautati!');
		return false;
	}
	
	return true;
}

	
function checkEmail(e) {
	ok = '1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM';

	for(i = 0; i < e.length; i++){
		if(ok.indexOf(e.charAt(i)) < 0)
			return (false);
	} 

	if (document.images) {
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two))
			return (-1);
	}
}


function verifyEmail(form, message)
{
	if (!checkEmail(form.email.value)) {
		alert(message);
		return false;
	}
}

function verifyEmailN(form, message)
{
	if (!checkEmail(form.email.value)) {
		alert(message);
		return false;
	}
}



function getURL(mode, page, params)
{
	if (page == "")
		return host + (!mode ? 'index.php' : '') + (params && params != '' ? (params.substr(0, 1) != '#' ? '&' : '') + params : '');
	
	return host + (!mode ? 'index.php?page=' : '') + (mode ? '' : '') + page + (mode ? '.html' : '') + (params && params != '' ? (params.substr(0, 1) != '#' ? '&' : '') + params : '');
}

function checkIBAN()
{
	var msg = IBANChk('IBAN',document.register_form.iban.value);
	
	if (msg != '')
		return msg;
	
}


function IBANChke(fieldName,b)
{
	var msg="";
	// Check the length
	if (b.length < 5) {
		msg = "IBAN: " + fieldName + " length is less than 5 characters";
		return msg;
	}
	
	// Swap the first four characters with the rest
	s = b.substring(4) + b.substring(0, 4);
	
	// Loop by characters of the string
	for (i = 0, r = 0; i < s.length; i++ ) {
		// Extract the following character c
		c = s.charCodeAt(i);
		
		// Calculate the code k from 0 to 35
		if (48 <= c && c <= 57) // for a digit 0-9
		{
			if (i == s.length-4 || i == s.length-3) {
				msg = "IBAN: Positions 1 and 2 of " + fieldName + " cannot contain digits";
				return msg;
			}
			
			k = c - 48;
		}
		else if (65 <= c && c <= 90) // for a letter A-Z
		{
			if (i == s.length-2 || i == s.length-1) {
				msg = "IBAN: Positions 3 and 4 of " + fieldName + " cannot contain letters";
				return msg;
			}
			
			k = c - 55;
		}
		else {
			msg="IBAN: Only digits and uppercase letters are allowed in " + fieldName;
			return msg;
		}
		
		// Cumulate the remainder of the division by 97
		if (k > 9)
			r = (100 * r + k) % 97;
		else
			r = (10 * r + k) % 97;
	}
	
	// Check the check digits
	if (b.substring(2, 4) > "98") {
		msg = "IBAN: The check digits cannot be superior to 98 in " + fieldName;
		return msg;
	}
	
	// The remainder of division should be 1
	if (r != 1) {
		msg = "IBAN: The check digits are invalid";
		return msg;
	}
	
	// Return OK
	return msg;
}


function IBANChk(fieldName,b)
{
	var msg="";
	// Check the length
	if (b.length < 5) {
		msg = "IBAN: " + fieldName + " lungimea e mai mica de 5 caractere";
		return msg;
	}
	
	// Swap the first four characters with the rest
	s = b.substring(4) + b.substring(0, 4);
	
	// Loop by characters of the string
	for (i = 0, r = 0; i < s.length; i++ ) {
		// Extract the following character c
		c = s.charCodeAt(i);
		
		// Calculate the code k from 0 to 35
		if (48 <= c && c <= 57) // for a digit 0-9
		{
			if (i == s.length-4 || i == s.length-3) {
				msg = "IBAN: Pozitiile 1 si  2 din " + fieldName + " nu pot contine cifre";
				return msg;
			}
			
			k = c - 48;
		}
		else if (65 <= c && c <= 90) // for a letter A-Z
		{
			if (i == s.length-2 || i == s.length-1) {
				msg = "IBAN: Pozitiile 3 si 4 din " + fieldName + " nu pot contine litere";
				return msg;
			}
			
			k = c - 55;
		}
		else {
			msg = "IBAN: Doar cifre si majuscule sunt permise in  " + fieldName;
			return msg;
		}
		
		// Cumulate the remainder of the division by 97
		if (k > 9)
			r = (100 * r + k) % 97;
		else
			r = (10 * r + k) % 97;
	}
	
	// Check the check digits
	if (b.substring(2, 4) > "98") {
		msg = "Cifra de control IBAN nu poate fi mai mare decat 98 in " + fieldName;
		return msg;
	}
	
	// The remainder of division should be 1
	if (r != 1) {
		msg = "Cifrele de control IBAN sunt invalide";
		return msg;
	}
	
	// Return OK
	return msg;
}

function validareCNP(s)
{
	var suma=0;
	var mesaj="";
	if(s.length==13)
	{
		suma=parseInt(s.charAt(0))*2+parseInt(s.charAt(1))*7+parseInt(s.charAt(2))*9+parseInt(s.charAt(3))*1+parseInt(s.charAt(4))*4+parseInt(s.charAt(5))*6+parseInt(s.charAt(6))*3+parseInt(s.charAt(7))*5+parseInt(s.charAt(8))*8+parseInt(s.charAt(9))*2+parseInt(s.charAt(10))*7+parseInt(s.charAt(11))*9;
		suma=suma%11;
		if(suma==10)
			suma=1;
		if(suma==parseInt(s.charAt(12)))
			{}
		else{
			return "CNP invalid !!!";
		}
	}
	else{
		
		return "CNP de lungime necorespunzatoare (<>13) !!!" ;
	}
}


function validareCUI(cui)
{
	var z,y;

	//cui=cui.value;
	pondere_n="";
	total=0;
	
	if (cui.substr(0, 2).toUpperCase() == "RO")
		cui = cui.substr(2);
	
	// Valoarea numerica de caractere trebuie sa fie intre 2 si 10
	if (cui.length < 7 || cui.length > 10 ) { return "CUI de lungime necorespunzatoare (<>7 - 10) !!!"; }
	//  cheia de calcul
	
	pondere="7532175321";
	z=cui.length;
	y=10-z;
	pondere_n = pondere.substr(y,z);
	// Calcul propruzis ..
	for (x=0;x < cui.length -1 ;++x) {
		total+=cui.charAt(x) * pondere_n.charAt(x);
	}
	//Totalul se inmulteste cu 10 si se aplica modulo de 11
	total = (total * 10)%11%10;
	// Rezultatul final trebuie sa fie egal cu ultima cifra din cui intial, cifra reprezinta o cheie de control
	if ( cui.substr(z-1,1) != total )  return "CUI invalid !!!";
	
	
}

function checkval(val){
	//var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
	//strip out acceptable non-numeric characters
	if (isNaN(val)) {
		return " trebuie sa contina numai cifre.";
	}
}
