function initialize () {
  initLightbox();
}

// contact.asp
function sendContact() {
  if ( controlContact() == false ) return;
  postto ('contact.asp?p=send', 'frm_contact');
}

function ayarla_konu() {
  if ($('fld_subject').value=='other') Element.show('d_digerkonu');
  else Element.hide('d_digerkonu');
  resizePage();
}

function controlContact() {
  var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  if ($('fld_name').value == "") { alert ("Please fill in the name field."); $('fld_name').focus(); return false; }
  if (!filter.test($('fld_mail').value)) {  alert ("Please check your e-mail."); $('fld_mail').focus(); return false;  }
  if ($('fld_message').value == "") { alert ("Please fill in the message field."); $('fld_message').focus(); return false; }
  return true;
}
// end-contact.asp

function goto(url) {
  slideshowenabled = false;
  $('d_page').innerHTML = "";
  Element.show('d_loading');
  new Ajax.Request( url, { method: "get", evalScripts: true, onSuccess: renderPage, onFailure: reportError } );
}

function postto (url, formId) {
  var tmp=getPostParameters(formId);
  $('d_page').innerHTML = "";
  Element.show('d_loading');
  new Ajax.Request( url, { method: "post", evalScripts: true, postBody: tmp, onSuccess: renderPage, onFailure: reportError } );
}

function getPostParameters(p_formId) {
  var poststr;
  if (p_formId == 'frm_contact') {   // contact
    poststr = "fld_name=" + encodeURI($('fld_name').value) + "&fld_mail=" + encodeURI($('fld_mail').value) + "&fld_subject=" + encodeURI($('fld_subject').value) + "&fld_othersubject=" + encodeURI($('fld_othersubject').value) + "&fld_message=" + encodeURI($('fld_message').value);
  } else if (p_formId == 'frm_gb') {  // guestbook
    poststr = "fld_name=" + encodeURI($('fld_name').value) + "&fld_mail=" + encodeURI($('fld_mail').value) + "&fld_message=" + encodeURI($('fld_message').value);
  } else return null;   // error

  return poststr
}

function renderPage(transport) {
  Element.hide('d_loading');
  $('d_page').innerHTML=transport.responseText;

  var myScripts = transport.responseText.extractScripts();
  var myReturnedValues = myScripts.map(function(script) { return eval(script); });
}

function reportError(transport) {
  Element.hide('d_loading');
  $('d_page').innerHTML='';
  
  poststr = "fld_error=" + encodeURI(transport.responseText);
  new Ajax.Request( "senderror.asp", { method: "post", postBody: poststr, onSuccess: renderPage } );
}

function popUpImage(name, url, width, height) { window.open(url, name, 'left=0,top=0,width='+width+',height='+height+',toolbar=no,menubar=no,status=yes,scrollbars=yes,resizable=no'); }

function limitText(obj, maxLength) {
  if (obj.value.length >= maxLength)
    obj.value = obj.value.substring(0, maxLength);
    temp = $('charCount').innerHTML.split(':');
    $('charCount').innerHTML = temp[0] + ': ' + (maxLength - obj.value.length).toString();
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
