nav = navigator.appName.indexOf("Microsoft")!= -1 ? 1 : 2;

function popup(url, name, width, height, scroll, modal, resizable) {
	width=Math.min(screen.availWidth,width);
	height=Math.min(screen.availHeight-40,height);
	var poz_x=(screen.availWidth-width)/2;
	var poz_y=(screen.availHeight-height-30)/2;
	newwin=window.open(url, name, 'scrollbars='+scroll+', menubar=no, width='+width+', height='+height+', resizable=no,toolbar=no, left='+poz_x+', top='+poz_y+', location=no, status=no');
	if(modal){
		popInt=setInterval(function(n){
			if(typeof(newwin.name)=="string"){
				if(newwin.document.body){
					openerfocus=function(){
						if(typeof(newwin.name)=="string"){
							newwin.focus();
						}else{
							document.body.onfocus=null;
						}
					}
					document.body.onfocus=openerfocus;
					newwin.window.document.body.onunload=function(){}
					newwin.focus();
					/*with(newwin){
						self.focus()
						opener.document.body.onfocus=function(){self.focus();opener.alert(4);}
						self.document.body.onunload=function(){opener.document.body.onfocus=null}
					}*/
					clearInterval(popInt);
				}
			}else{
				clearInterval(popInt)
			}
		},1)
	}
}

function checkIBAN()
{
	var msg = IBANChk('IBAN',document.formular_furnizori.new_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;

	// 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.";
	}
}