// JavaScript Document
function checkValid(id, msg, regula) {
	var prefix = "* ";
	var suffix = "\n";
	
	
	switch(regula) {
		case 'required':
						if (document.getElementById(id).value=="")
							return prefix+msg+suffix;
						break;
		case 'select':
						if (document.getElementById(id).options[document.getElementById(id).selectedIndex].value=="")
							return prefix+msg+suffix;
						break;
		case 'numeric':
						var validch = "0123456789.";
						var isNumber=true;
						var ch;
						var val = document.getElementById(id).value;
						
						for (i=0; i<val.length && isNumber == true; i++) { 
							ch = val.charAt(i); 
							if (validch.indexOf(ch) == -1) 								
								return prefix+msg+suffix;
						}
						break;
		case 'email':
						var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
						if (!filter.test(document.getElementById(id).value))
							return prefix+msg+suffix;
						break;
		case 'integer':
						var filter=/^\d{0,9}$/;
						if (!filter.test(document.getElementById(id).value))
							return prefix+msg+suffix;
						break;
		case 'limitpercent':
						if (document.getElementById(id).value<0 || document.getElementById(id).value>100)
							return prefix+msg+suffix;
						break;
	}
	return "";
}

function checkIdentical(id1, id2, msg) {

	var prefix = "* ";
	var suffix = "\n";

	if (document.getElementById(id1).value != document.getElementById(id2).value)
	return prefix+msg+suffix
	else
	return ''

}

function checkLength(id, min, max, msg) {

	var prefix = "* ";
	var suffix = "\n";

	if (document.getElementById(id).value.length < min || document.getElementById(id).value.length > max )
	return prefix+msg+suffix
	else
	return ''

}

function checkRadio(form_name,radio_name,msg)
{
	
	var radio_choice = false;	
	var prefix = "* ";
	var suffix = "\n";
	radio_obj = eval('document.'+form_name+'.'+radio_name);
	
	if (radio_obj.checked) {
		radio_choice = true; 	
	} else {	
		for (counter = 0; counter < radio_obj.length; counter++)
		{
			
			if (radio_obj[counter].checked) {
				radio_choice = true; 
				break;
			}
		}
	}
	
	if (!radio_choice) {
		return prefix+msg+suffix;
	}
	    return '';
}

function verificaFormular(which) {
	msg_alert = "______________________________________________________\n\n"
	msg_alert += "Va rugam corectati erorile si incercati din nou:\n";
	msg_alert += "______________________________________________________\n";
	msg_alert += "\n";
	switch(which) {
		case "form":
			msg = "";
			msg += checkValid("nume", "Trebuie sa specificati numele dvs.", "required");
			break;
		case "curs":
			msg = "";
			msg += checkValid("nume", "Trebuie sa specificati numele dvs.", "required");
			msg += checkValid("email", "Trebuie sa specificati email-ul dvs.", "email");
			break;
		case "revista":
			msg = "";
			msg += checkValid("nume", "Trebuie sa specificati numele dvs.", "required");
			msg += checkValid("prenume", "Trebuie sa specificati prenumele dvs.", "required");
			msg += checkValid("oras", "Trebuie sa specificati orasul dvs.", "required");
			msg += checkValid("email", "Trebuie sa specificati email-ul dvs.", "email");
			break;
	}
	if (msg!="") {
		alert(msg_alert+msg);
		return false;
	}else{
		return true;
	}
}

var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789+/=";

function encode64(inp) {
	var out = "";
	var chr1, chr2, chr3 = "";
	var enc1, enc2, enc3, enc4 = "";
	var i = 0;
	do {
		chr1 = inp.charCodeAt(i++);
		chr2 = inp.charCodeAt(i++);
		chr3 = inp.charCodeAt(i++);
		
		enc1 = chr1 >> 2;
		enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
		enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
		enc4 = chr3 & 63;
		
		if (isNaN(chr2)) {
			enc3 = enc4 = 64;
		}
		else if (isNaN(chr3)) {
			enc4 = 64;
		}

		out = out + keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4);

		chr1 = chr2 = chr3 = "";
		enc1 = enc2 = enc3 = enc4 = "";

	}
	while (i < inp.length);
	return out;
}

function decode64(inp) {
	var out = "";
	var chr1, chr2, chr3 = "";
	var enc1, enc2, enc3, enc4 = "";
	var i = 0;

	var base64test = /[^A-Za-z0-9\+\/\=]/g;

	if (base64test.exec(inp)) {
		alert("There were invalid base64 characters in the input text.\n" + "Valid base64 characters are A-Z, a-z, 0-9, ?+?, ?/?, and ?=?\n" + "Expect errors in decoding.");
	}
	inp = inp.replace(/[^A-Za-z0-9\+\/\=]/g, "");

	do {

		enc1 = keyStr.indexOf(inp.charAt(i++));
		enc2 = keyStr.indexOf(inp.charAt(i++));
		enc3 = keyStr.indexOf(inp.charAt(i++));
		enc4 = keyStr.indexOf(inp.charAt(i++));
	
		chr1 = (enc1 << 2) | (enc2 >> 4);
		chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
		chr3 = ((enc3 & 3) << 6) | enc4;
	
		out = out + String.fromCharCode(chr1);
	
		if (enc3 != 64) {
			out = out + String.fromCharCode(chr2);
		}
		if (enc4 != 64) {
			out = out + String.fromCharCode(chr3);
		}
	
		chr1 = chr2 = chr3 = "";
		enc1 = enc2 = enc3 = enc4 = "";
	
	}
	while (i < inp.length);

	return out;
}

/* galerie poze */
function gal_open_centered(url) {
	w = 700;
	h = 650;
	sw = screen.width;
	sh = screen.height;
	l = (sw - w) / 2;
	t = (sh - h) / 2;
	window.open(url, 'Galerie', 'width='+w+',height='+h+',top='+t+',left='+l+',scrollbars=no,resizable=no');	
}

function showPic (whichpic) { 
	if (document.getElementById) { 
		document.getElementById('placeholder').src = whichpic.href.replace('thumbs', 'big'); 
		if (whichpic.title) { 
			document.getElementById('desc').childNodes[0].nodeValue = whichpic.title; 
		} else { 
			document.getElementById('desc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue; 
		} 
		return false; 
	} else { 
		return true; 
	} 
}
/* galerie poze ends*/

function go(url)
	{
		var box = document.forms['order'].order;
		destination = url + "&order=" + box.options[box.selectedIndex].value;
		if (destination) location.href = destination;	
	}