
str_empty = "\s*";

str_host = "[0-9a-zA-Z]+(\.[-0-9a-zA-Z]+)+";

str_path = "\/?[-/.0-9a-zA-Z&?%=_#]*";

str_email = "[-_.0-9a-zA-Z]+([+][-_.0-9a-zA-Z]+)*@"+str_host;

str_url = "((http:\/\/)|(ftp:\/\/)|(www[.])|(ftp[.]))"+str_host+"(\/"+str_path+")?";

str_tel = "(([(][+]?[0-9]{2,3}[)])|([+]?[0-9]{2,3}))?[-. 0-9]{2,30}";           
//str_tel = "0[0-9]{9}";

str_int = "[+-]?[0-9]+";

str_pc = "[0-9]{4,5}";

str_float = "[-+]?[0-9]*(\.[0-9]*)?";

str_pass = ".{4,}";

str_year = "((19)|(20))[0-9]{2}";

pcre_empty = new RegExp("^"+str_empty+"$");

pcre_host = new RegExp("^"+str_host+"$");

pcre_path = new RegExp("^"+str_path+"$");

pcre_email = new RegExp("^"+str_email+"$");

pcre_url = new RegExp("^"+str_url+"$");

pcre_tel = new RegExp("^"+str_tel+"$");

pcre_int = new RegExp("^"+str_int+"$");

pcre_pc = new RegExp("^"+str_pc+"$");

pcre_float = new RegExp("^"+str_float+"$");

pcre_pass = new RegExp("^"+str_pass+"$");

pcre_year = new RegExp("^"+str_year+"$");

function check_date(form,datename) {
	d=parseInt(form.elements[datename+'[day]'].options[form.elements[datename+'[day]'].selectedIndex].value,10);
	m=parseInt(form.elements[datename+'[mon]'].options[form.elements[datename+'[mon]'].selectedIndex].value,10)-1;
	y=parseInt(form.elements[datename+'[year]'].options[form.elements[datename+'[year]'].selectedIndex].value,10);
	datanoua = new Date(y,m,d,12,0,0);  // 12h dupa 12:00 pentru ca in IE
					    // sunt probleme cu aproximarile
	if (datanoua) ret=true;
		else ret=false;

//  pentru debugging
//	alert ("Data input: " + d + " " + m + " " + y + ".");
//	alert ("Data output: " + datanoua.getDate() + " " +
//						   datanoua.getMonth() + " " +
//						   datanoua.getFullYear() + "."); 
	if (ret) {
		if ( (d==datanoua.getDate()) &&
			(m==datanoua.getMonth()) &&
			(y==datanoua.getFullYear()) ) 
					ret=true; else ret=false;
		timestamp=datanoua.getTime()/1000;
//		alert (timestamp);
		if ( (arguments.length>2) && (timestamp<arguments[2]) ) ret=false;
		if ( (arguments.length>3) && (timestamp>arguments[3]) ) ret=false;
	}


	return(ret);
}

function parsedate(form,datename) {
	d=parseInt(form.elements[datename+'[day]'].options[form.elements[datename+'[day]'].selectedIndex].value,10);
	m=parseInt(form.elements[datename+'[mon]'].options[form.elements[datename+'[mon]'].selectedIndex].value,10)-1;
	y=parseInt(form.elements[datename+'[year]'].options[form.elements[datename+'[year]'].selectedIndex].value,10);
	data = new Date(y,m,d,0,0,1);
	return(data.getTime()/1000);
}

function array2str(arr) {
	var msg="";
	for(i=0;i<arr.length;i++)
		msg+=(i+1)+". "+arr[i]+"\n";
	return(msg);
}

function syncDates(frm,from_el,to_el,changed) {
    var from_day=frm.elements[from_el+'[day]'];
    var from_mon=frm.elements[from_el+'[mon]'];
    var from_year=frm.elements[from_el+'[year]'];
    var to_day=frm.elements[to_el+'[day]'];
    var to_mon=frm.elements[to_el+'[mon]'];
    var to_year=frm.elements[to_el+'[year]'];

    var from=new Date(from_year.options[from_year.selectedIndex].value,from_mon.options[from_mon.selectedIndex].value-1,from_day.options[from_day.selectedIndex].value);
    var to=new Date(to_year.options[to_year.selectedIndex].value,to_mon.options[to_mon.selectedIndex].value-1,to_day.options[to_day.selectedIndex].value);
    
    if (changed==from_el)
	if (to.getTime()<from.getTime()) {
	    if (from_day.selectedIndex==from_day.options.length-1) {
		to_day.selectedIndex=0;
		if (from_mon.selectedIndex==from_mon.options.length-1) {
		    to_mon.selectedIndex=0;
		    to_year.selectedIndex=from_year.selectedIndex+1;
		} else {
		    to_mon.selectedIndex=from_mon.selectedIndex+1;
		    to_year.selectedIndex=from_year.selectedIndex;
		}
	    } else {
		to_day.selectedIndex=from_day.selectedIndex+1;
		to_mon.selectedIndex=from_mon.selectedIndex;
		to_year.selectedIndex=from_year.selectedIndex;
	    }
	}
    
    if (changed==to_el)
	if (to.getTime()<from.getTime()) {
	    from_day.selectedIndex=to_day.selectedIndex;
	    from_mon.selectedIndex=to_mon.selectedIndex;
	    from_year.selectedIndex=to_year.selectedIndex;
	}
 
}

function oferteDiv() {
	var divs = document.getElementsByTagName("div");
	for(i = 0; i < divs.length; i++){
		if(divs[i].className =='hotofferhome' ){
			divs[i].onmouseover = overdiv;
			divs[i].onmouseout = outdiv;
			if(divs[i].getElementsByTagName("a")[0].offsetHeight > 17){
				//console.log(divs[i].getElementsByTagName("a")[0].offsetHeight);
				divs[i].getElementsByTagName("a")[0].style.top = "6px";
			}
		}
		if(divs[i].className =='hotofferhome0' ){
			divs[i].onmouseover = overdiv0;
			divs[i].onmouseout = outdiv0;
		}
	};
	
}

function overdiv(){
		this.style.backgroundImage = "url(../images/offer_bg_on.gif)";
	}
	
function outdiv(){
		this.style.backgroundImage = "url(../images/offer_bg_off.gif)";
	}
	
function overdiv0(){
		this.style.backgroundImage = "url(../images/offer0_bg_on.gif)";
		this.getElementsByTagName("a")[0].style.backgroundImage = "url(../images/offer0_bg_on_right.gif)";
	}
	
function outdiv0(){
		this.style.backgroundImage = "url(../images/offer0_bg_off.gif)";
		this.getElementsByTagName("a")[0].style.backgroundImage = "url(../images/offer0_bg_off_right.gif)";
	}	

var setupTables = {
	init:function(){
	 if(document.getElementsByTagName){  
	   var tables = document.getElementsByTagName("table");
	   for(k = 0;k < tables.length; k++){
	   	   if(tables[k].className.indexOf('hotdeals') != -1){
		   var tabelCurent = tables[k];
		   var rows = tables[k].getElementsByTagName("tr");
		   for(i = 0; i < rows.length; i++){
				//console.log(i);
				if(i==0) {rows[0].classname = "colorat";continue;}
				
				if(rows[i].cells[0].className == "tblLegend" && rows[i].cells[0].colSpan == "8") {continue;}
				for(j = 0; j < rows[i].cells.length; j++) {
					if(j == rows[i].cells.length - 1 && i < rows.length) {
						if(tables[k].className.indexOf("noblue") == -1) {
							rows[i].cells[j].style.color = "#002254";
							rows[i].cells[j].style.fontWeight = "bold";
						}
					}
					if(j == rows[i].cells.length - 2 && i < rows.length -1) {				
						rows[i].cells[j].style.padding = "2px 2px";
					}					
				}
				if(i < rows.length - (rows[rows.length-1].cells[0].className == 'tblLegend')?'1':0){
					try {
						rows[i].addEventListener('mouseover',overTr,false);
						rows[i].addEventListener('mouseout',outTr,false);
						}catch(err){
							try{
								rows[i].onmouseover = overTr;
								rows[i].onmouseout = outTr;
							}catch(err){}
						}
				}
					if(i % 2 == 0){rows[i].className = "colorat";}else{rows[i].className = "alb";}			
			}
			}
		}
	}
	
	function overTr() {
		this.style.color = '#297CBE';
		this.style.cursor = 'default';
		this.cells[this.cells.length - 1].style.color = '#297CBE';
	}
	
	function outTr() {
		var tab = this.parentNode.tagName == 'TABLE'?this.parentNode:this.parentNode.parentNode;
		this.style.color = '';
		this.cells[this.cells.length - 1].style.color = (tab.className.indexOf('noblue') == -1)?'#002254':'';
		//console.log(this.parentNode.tagName);
	}
}
}


function initializare() {
	setupTables.init();
	oferteDiv();
	initForm();
}

window.onload = initializare;

function printContent(){
	var node = document.getElementById("center_padded");
	var content=node.innerHTML;
	var pwin=window.open('','print_content','width=534');

	pwin.document.open();
	pwin.document.write('<html><head><link rel="stylesheet" type="text/css" href="css/print.css" media="all"></head><body onload="window.print();">'+content+'</body></html>');
	pwin.document.close();
 
	setTimeout(function(){pwin.close();},1000);
}