var SITE_URL='http://www.artukraine.com.ua/';
var IE=document.all?true:false;
if(!IE) document.captureEvents(Event.KEYPRESS);
if(!IE) document.captureEvents(Event.MOUSEMOVE);
var err_style='1px solid #f00';

function isValidEmail(strEmail){
  validRegExp=/^[^@]+@[^@]+.[a-z]{2,}$/i;
  if (strEmail.search(validRegExp) == -1) return false;
  return true;
}

function post_comment(obj){
  var error=0;
  var event_id=obj['event_id'].value;
  var c_name=obj['c_name'].value;
  var c_mail=obj['c_mail'].value;
  var c_message=obj['c_message'].value;

  if(c_name=='' || c_name.length<2){
    document.getElementById('c_name').style.border=err_style; error=1;
  }else document.getElementById('c_name').style.border='1px solid #ffa63d';
  if(!isValidEmail(c_mail)){
    document.getElementById('c_mail').style.border=err_style; error=1;
  }else document.getElementById('c_mail').style.border='1px solid #ffa63d';
  if(c_message=='' || c_message.length<3){
    document.getElementById('c_message').style.border=err_style; error=1;
  }else document.getElementById('c_message').style.border='1px solid #ffa63d';

  if(error==0){
    var poststr="c_name=" + encodeURI(c_name)+"&c_mail=" + encodeURI(c_mail)+"&c_message=" + encodeURI(c_message)+"&event_id=" + encodeURI(event_id);
    makePOSTRequest(SITE_URL+'events/', poststr);
  }
}
function makePOSTRequest(url,parameters){
  http_request=false;
  if(window.XMLHttpRequest){ // Mozilla, Safari,...
    http_request=new XMLHttpRequest();
    if(http_request.overrideMimeType){
      http_request.overrideMimeType('text/html');
    }
  }else if(window.ActiveXObject){ // IE
    try{
      http_request=new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
      try{
        http_request=new ActiveXObject("Microsoft.XMLHTTP");
      }catch(e){}
    }
  }
  if(!http_request){
    alert('Cannot create XMLHTTP instance');
    return false;
  }

  http_request.onreadystatechange=alertContents;
  http_request.open('POST', url, true);
  http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=windows-1251");
  http_request.setRequestHeader("Content-length", parameters.length);
  http_request.setRequestHeader("Connection", "close");
  http_request.send(parameters);
}

var http_request=false;
function blockError(){return true;}
function alertContents(){
  try{
    if(http_request.readyState == 4){
      result=http_request.responseText;
      document.getElementById('container').innerHTML='<div>'+result+'</div>';
    }
  }catch(e){
     alert(e);
  }
}

var todaydate=new Date();
var curmonth=todaydate.getMonth()+1; //get current month (1-12)
var curyear=todaydate.getFullYear(); //get current year

cal=buildCal(curmonth, curyear, "main", "month", "daysofweek", "days", 0);

function calendar(curmonth,curyear){  document.getElementById("cal").innerHTML=buildCal(curmonth, curyear, "main", "month", "daysofweek", "days", 0);}
// CALENDAR
function buildCal(m, y, cM, cH, cDW, cD, brdr){
  //var mn=['January','February','March','April','May','June','July','August','September','October','November','December'];
  var mn=['Січень','Лютий','Березень','Квітень','Травень','Червень','Липень','Серпень','Вересень','Жовтень','Листопад','Грудень'];
  var dim=[31,0,31,30,31,30,31,31,30,31,30,31];
  var dow=['п','в','с','ч','п','с','н'];

  var oD=new Date(y, m-1, 1); //DD replaced line to fix date bug when current day is 31st
  oD.od=oD.getDay()+1; //DD replaced line to fix date bug when current day is 31st

  var todaydate=new Date() //DD added
  var scanfortoday=(y==todaydate.getFullYear() && m==todaydate.getMonth()+1)? todaydate.getDate() : 0 //DD added

  dim[1]=(((oD.getFullYear()%100!=0)&&(oD.getFullYear()%4==0))||(oD.getFullYear()%400==0))?29:28;
  var t='<table class="'+cM+'" cellpadding="0" border="0" cellspacing="0"><tr>';
  t+='<td colspan="7" align="center" class="'+cH+'">'+
     '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr>'+
       '<td align="right" width="15">'+
         '<a class="hand nav_dig" onclick="javascript:calendar('+((m-1)==0 ? 12 : (m-1))+','+((m-1)==0 ? (y-1) : y)+');"><</a>'+
       '</td><td align="center">'+
         '<a class="nav_dig" href="'+SITE_URL+'calendar/'+y+'/'+m+'/" >'+mn[m-1]+' '+y+'</a>'+
       '</td><td align="left" width="15">'+
         '<a class="hand nav_dig" onclick="javascript:calendar('+((m+1)==13 ? 1 : (m+1))+','+((m+1)==13 ? (y+1) : y)+');">></a>'+
       '</td>'+ //'<td align="right" width="15">'+
//         '<a class="hand" onclick="javascript:calendar('+m+','+(y-1)+');"><</a>'+
//       '</td><td align="center" width="45" style="color:#0a62a9;">'+
//         '<a href="'+SITE_URL+'calendar/'+y+'/" >'+

//         '</a>'+
//       '</td><td align="left" width="15">'+
//         '<a class="hand" onclick="javascript:calendar('+m+','+(y+1)+');">></a>'+
       '</tr></table>'+
     '</td></tr>'+
     '<tr>';
  for(s=0;s<7;s++) t+='<td class="'+cDW+'" align="center">'+dow[s]+'</td>';
  t+='</tr><tr>';
  for(i=0;i<=41;i++){
    var x=((i-oD.od+1>=0)&&(i-oD.od+1<dim[m-1])) ? i-oD.od+2 : '';
    if (x && x==scanfortoday && i>0) //DD added
      t+='<td class="'+cD+', nav_active_dig" align="center"><a class="nav_active_dig" href="'+SITE_URL+'calendar/'+y+'/'+m+'/'+x+'/">'+x+'</a></td>';
    else{      if(i>0)
        t+='<td class="'+cD+'" align="center"><a class="nav_dig" href="'+SITE_URL+'calendar/'+y+'/'+m+'/'+x+'/" >'+x+'</a></td>';
    }
    if((i>0)&&((i)%7==0)&&(i<36)) t+='</tr><tr>';
  }
  return t+='</tr></table>';
}

function dsp(i){
 document.getElementById(i).style.visibility="visible";
}
function undsp(i){
 document.getElementById(i).style.visibility="hidden";
}
function rowPointer(row,action,classNormal,classOver,classMark){
  if(action=='over'){
    if(row.className!=classMark) row.className=classOver;
  }else if(action=='out'){
    if(row.className!=classMark) row.className=classNormal;
  }else if(action=='down'){
    row.className=(row.className!=classMark) ? classMark : classNormal;
  }
}
function replace_element(elemID1,elemID2,elemID3){
  elem1=document.getElementById(elemID1);
  elem2=document.getElementById(elemID2);
  elem3=document.getElementById(elemID3);
  if(elem1.style.display=='none'){    elem3.style.visibility='hidden';
    elem3.style.display='none';
    elem2.style.visibility='hidden';
    elem2.style.display='none';
    elem1.style.visibility='visible';
    elem1.style.display='block';
  }
}
function downloadImage(file){
  location.href='/pic/download/'+file;
}

