﻿var UTF8 = {
	encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},

	decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}


function chrChange(char, findChar, repChar){
	var re = new RegExp (findChar, 'gi');
	var newstr = char.replace(re, repChar);	
return(newstr);
}



ieHover = function () {
  try {
    var sfEls = document.getElementById("sub_menu").getElementsByTagName("LI");
    for (var i = 0; i < sfEls.length; i++) {
      sfEls[i].onmouseover = function () {
        this.className += " iehover";
      }
      sfEls[i].onmouseout = function () {
        try {
          this.className = this.className.replace(new RegExp("iehover\\b"), "");
        } catch (e) {
          //alert(e);
        }
      }
    }
  } catch (ex) {

  }
}


function isEmpty(str){
  return (str == null) || (str.length == 0);
}

// returns true if the string is a valid email
function isEmail(str){
  if(isEmpty(str)) return false;
  var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i
  return re.test(str);
}



function epostaListKayit(){
  eposta = document.getElementById('eBultenEposta');
  if(!isEmail(eposta.value)){
    alert('Lütfen geçerli bir eposta giriniz');
    return(false);
  }else{
    var d = new Date();
    var sonuc = $.ajax({
      url: "/xml/EpostaListe.ashx?d=" + d.getTime(),
      type: 'POST',
      data: { Eposta : eposta.value },
      async: false
    }).responseText;
    
    try{ parseInt(sonuc); }
    catch(ex){ 
      // birsey yapma
    }
    
    if(sonuc != 100){
      alert(sonuc);
    }else{
      $('#eBultenBut').hide();
      eposta.disabled = true;
      eposta.value = 'Teşekkürler.';
    }
    return(false);
  }
}


function getKeyCharCode(event) {
	var key = null;
	if(window.event){key = window.event.keyCode;}else if (event.which) {key = event.which;}
	return key;
}



function epostaListEnter(event) {
	var isMozilla = false;
	if (!window.event && event.which) { isMozilla = true; }
	var key = getKeyCharCode(event);
	var isNumeric = false;	
	if (key != null) {
	  if (key == 13) {
	    return(epostaListKayit());
		} 
	} 
}


