// functie de deschidere fereastra noua fara scroll :
function openwind(pict_link,width,height) {
	var parameters;
	var winx = (screen.width - width) / 2;
    var winy = (screen.height - height) / 2;
	
	parameters = "width="+width+", height="+height+", top="+winy+", left="+winx+", status=no, scrollbars=no";
	
	win = window.open(pict_link,'view',parameters);
	win.window.focus();
}

// functie de deschidere fereastra noua cu scroll :
function openwindscroll(pict_link,width,height) {
	var parameters;
	var winx = (screen.width - width) / 2;
    var winy = (screen.height - height) / 2;
	
	parameters = "width="+width+", height="+height+", top="+winy+", left="+winx+", status=no, scrollbars=yes";
	
	win = window.open(pict_link,'view',parameters);
	win.window.focus();
}

// functie ce verifica sa se introduca doar numere :
function isnumeric(text, text_alert) {
	valid = true;
	
	var sw_text;

	for(var j=0; j<text.length; j++) {
		if(isNaN(text.charAt(j))) {
			sw_text = 1;
			break;
		}
	}
	
	if((sw_text==1)) {
		valid = false;
		alert(text_alert);
		return valid;
	}
	
	return valid;
}

// functie utila ptr introducerea preturilor :
function verify_price_field(price, price_alert, points_error) {
	valid = true;
	
	var sw_price, puncte;
	puncte = 0;

	for(var j=0; j<price.length; j++) {
		if(isNaN(price.charAt(j)) && price.indexOf(".")==-1) {
			sw_price = 1;
			break;
		}
		
		if(price.charAt(j)==".")
			puncte++;
	}
	
	if((sw_price==1)) {
		valid = false;
		alert(price_alert);
		return valid;
	} else {
		// se verifica ca pretul sa nu aiba mai multe puncte asociate :
		if(puncte>1) {
			valid = false;
			alert(points_error);
			return valid;
		}
	}
	
	return valid;
}

// functie de verificare a extensiei imaginilor :
function check_ext(path) {
	var array_ext = Array("jpg","jpeg","jpe");
	var img_array = path.split(".");
	var ext, sw_ext=0;
	
	for(i=0;i<img_array.length;i++) {
		if(i==(img_array.length-1)) {
			ext = img_array[i];
		}
	}
	
	for(i=0;i<array_ext.length;i++) {
		if(ext.toUpperCase()==array_ext[i] || ext.toLowerCase()==array_ext[i]) {
			sw_ext = 1;
			break;
		}
	}
	
	return sw_ext;
}

// functie de verificare a extensiei unui fisier :
function check_ext_file(path) {
	var array_ext = Array("pdf");
	var img_array = path.split(".");
	var ext, sw_ext=0;
	
	for(i=0;i<img_array.length;i++) {
		if(i==(img_array.length-1)) {
			ext = img_array[i];
		}
	}
	
	for(i=0;i<array_ext.length;i++) {
		if(ext.toUpperCase()==array_ext[i] || ext.toLowerCase()==array_ext[i]) {
			sw_ext = 1;
			break;
		}
	}
	
	return sw_ext;
}

// functie de verificare a adresei de e-mail :
function check_mail(str,text) {
	valid = true;
	if(str=="") {
		alert(text);
		valid = false;
	} else {
		tmp = str;
		if(tmp.indexOf("@")==-1 || tmp.indexOf("@")==0) {
			alert(text);
			valid = false;
		} else {
			arr1 = new Array();
			arr1 = tmp.split("@");
			if(arr1[1].indexOf(".")==-1 || arr1[1].indexOf(".")==0) {
				alert(text);
				valid = false;
			} else {
				arr2 = new Array();
				arr2 = arr1[1].split(".");
				if(arr2[1].length<2 || arr2[1].length>20) {
					alert(text);
					valid = false;
				}
			}
		}
	}
	return valid;
}