/* 
 *	PointSystem. JavaScript.
 *
*/

// проверка введённого email
function validateEmail(email) {
  var reg = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
  if (!email.match(reg)) {
    return (false);
  }
  return(true);
}
//----------------------------------
//Отсчет обратного времени, с днями.
//----------------------------------
function StartCountDown(myDiv,myTargetDate){
	var dthen	= new Date(myTargetDate);
	var dnow	= new Date();
	//alert(dthen);
	ddiff		= new Date(dthen-dnow);
	gsecs		= Math.floor(ddiff.valueOf()/1000);
	CountBack(myDiv,gsecs);
}

function Calcage(secs, num1, num2){
	s = ((Math.floor(secs/num1))%num2).toString();
	//alert(secs/num1);
	if (s.length < 2){	
	  s = "0" + s;
	}
	return (s);
}

function CountBack(myDiv, secs){
	var DisplayStr;
	var DisplayFormat = "%%D%% дн. %%H%%:%%M%%:%%S%%";
	DisplayStr = DisplayFormat.replace(/%%D%%/g,	Calcage(secs,86400,100000));
	DisplayStr = DisplayStr.replace(/%%H%%/g,		Calcage(secs,3600,24));
	DisplayStr = DisplayStr.replace(/%%M%%/g,		Calcage(secs,60,60));
	DisplayStr = DisplayStr.replace(/%%S%%/g,		Calcage(secs,1,60));
	
	if(secs > 0){	
	  document.getElementById(myDiv).innerHTML = DisplayStr;
	  setTimeout("CountBack('" + myDiv + "'," + (secs-1) + ");", 990);
	}
	else{
	  document.getElementById(myDiv).innerHTML = '<span style="font-size:16pt;">Конкурс завершен</span>';
	}
}
