// Variables
var months_ro = new Array("Ianuarie","Februarie","Martie","Aprilie","Mai","Iunie","Iulie","August","Septembrie","Octombrie","Noiembrie","Decembrie");
var days_ro = new Array("Duminic&#259;","Luni","Mar&#355;i","Miercuri","Joi","Vineri","S&#226;mb&#259;t&#259;");
var months_en = new Array("January","February","March","Aprili","May","June","July","August","September","October","November","December");
var days_en = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");

// cross-browser for getElementById
function xGetElementById(e)
{
  if(typeof(e)=='string') {
    if(document.getElementById) e=document.getElementById(e);
    else if(document.all) e=document.all[e];
    else e=null;
  }
  return e;
}

// Function which validates an email address
function isEmailAddr(email)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

//function which blocks input to a restricted list of characters
function restrictInput(myfield, e, dec, char, special)
{
	var key;
	var keychar;
	var digits = String("0123456789");
	var letters = String("abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ");
	
	if (window.event)
		 key = window.event.keyCode;
	else if (e)
		 key = e.which;
	else
		 return true;
	keychar = String.fromCharCode(key);
	
	chars = digits;
	
	if(char)
		chars += letters;
	
	if(special)
		chars += special;
	
	// return
	if(key==13)
		return true;
	// control keys
	if((key==null) || (key==0) || (key==8) || (key==9) || (key==27))
		return true;
	// numbers & special chars
	else if((chars.indexOf(keychar) > -1))
		return true;
	// decimal point jump
	else if(dec && (keychar == ".") && myfield.value.indexOf(".") == -1)
		return true;
	else
		return false;
}

function stripslashes (str){
	return (str+'').replace('/\0/g', '0').replace('/\(.)/g', '$1');
}

function reinitialiseScrollPane()
{
	$('.scroll-pane').jScrollPane({showArrows: false, scrollbarWidth: 15, animateTo: true, dragMinHeight: 15, dragMaxHeight: 15});
}

function getNewProductTxt(id){
	if(newProducts[id] != undefined){
		xGetElementById("new-product-txt").innerHTML = stripslashes(newProducts[id]);
	} else {
		xGetElementById("new-product-txt").innerHTML = "Produsul cautat nu exista !";
	}
	reinitialiseScrollPane();
}

function checkContactForm(o){
	if(o.nume.value == ""){
		alert("Campul 'nume' este obligatoriu !");
		o.nume.focus();
		return false;
	}
	if(o.email.value == ""){
		alert("Campul 'email' este obligatoriu !");
		o.email.focus();
		return false;
	}
	if(!isEmailAddr(o.email.value)){
		alert("Campul 'email' nu este valid !");
		o.email.focus();
		return false;
	}
	if(o.subiect.value == ""){
		alert("Campul 'subiect' este obligatoriu !");
		o.subiect.focus();
		return false;
	}
	if(o.mesaj.value == ""){
		alert("Campul 'mesaj' este obligatoriu !");
		o.mesaj.focus();
		return false;
	}
	if(o.cod.value == ""){
		alert("Campul 'cod' este obligatoriu !");
		o.cod.focus();
		return false;
	}
	return true;
}

function checkResetContactForm(){
	var d = xGetElementById("contact-form");
	if(confirm("Sigur doriti sa resetati formularul ?"))
		d.reset();
	return false;
}
