
var invalidaddress=new Array();
invalidaddress[0]="afsfa";
invalidaddress[1]="fsadfa";
invalidaddress[2]="daef";
invalidaddress[3]="sfasef";
var testresults;
//////////
function Trim(s) 
{

	while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
		{
			s = s.substring(1,s.length);
		}

	while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
		{
			s = s.substring(0,s.length-1);
		}
	return s;
}
////////////////*
function checkbae(mailadres){
	//if (document.layers||document.getElementById||document.all)
		return checkemail(mailadres);
	//else
	//	return true;
}
function checkemail(mailadres){
	var invalidcheck=0;
	//var str=document.getElementById('txtEmail').value;
	var str = mailadres;
	var filter=/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(str)){
		var tempstring=str.split("@");
		tempstring=tempstring[1].split(".");
		for (i=0;i<invalidaddress.length;i++){
			if (tempstring[0]==invalidaddress[i])
				invalidcheck=1;
		}
		if (invalidcheck!=1)
			testresults=true;
		else{
			//alert("Please input a more official email address!")
			testresults=false;
		}
	}
	else{
		//alert("Please input a valid email address!")
		testresults=false;
	}
	return (testresults)
}
//////////////////////////////////
function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
 
   for (var i = 0; i < sText.length && IsNumber == true; i++) 
   { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
      {
         IsNumber = false;
      }
   }
   return IsNumber;
}
//////////////////////////////////
function isCurrency(ch,key) 
{
	if (!(ch >= '0' && ch <= '9') && key != 8 && key!=44) // && key!=46
	{
		return false;
	}
	return true;
}

function getkey(e)
{
	if (window.event)
	   return window.event.keyCode;
	else if (e)
		return e.which;
	else
		return null;
}


function keyCheck(e, obj)
{
	var key, ch;
	key = getkey(e);
//alert(key);
	if (key == null) return true;
	ch = String.fromCharCode(key);

	if (!isCurrency(ch,key)) 
	{
		if (window.event)
			window.event.returnValue = false;
		else
			e.preventDefault();
	}
	return true;
}
////////////////////////////////////////////////////////
function PageQuery(q) {
	if(q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	this.keyValuePairs = new Array();
	if(q) {
		for(var i=0; i < this.q.split("&").length; i++) {
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function(s) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0] == s)
				return this.keyValuePairs[j].split("=")[1];
		}
		return false;
	}
	this.getParameters = function() {
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++) {
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}
	this.getLength = function() { return this.keyValuePairs.length; }	
}
function queryString(key){
	var page = new PageQuery(window.location.search); 
	return unescape(page.getValue(key)); 
}
function displayItem(key){
	if(queryString(key)=='false') 
	{
		//result.innerHTML="you didn't enter a ?name=value querystring item.";
		return "";
	}else{
		//result.innerHTML+=queryString(key)+"<BR>";
		return queryString(key);
	}
}
////////////////////////////////////////////////////////

function bigac(imgname)
{
	window.open('http://www.esenshop.com/productPhoto.aspx?p='+imgname,'','top=10,left=10,width=100,height=100');
}
function bigresimac(id)
{
	window.open('http://www.esenshop.com/photo.aspx?id=' + id,'','width=450,height=580,scrollbars=2');
}
////////////////////////////////////////////////////////

String.prototype.replaceAll=function(s1, s2) {return this.split(s1).join(s2)}

////////////////////////////////////////////////////////

function chkForm(tip,obj,val,msj,setfcs)
{
    var sonuc = true;
    switch(tip)
    {
        case "t"://textbox & dropdown
            if(Trim(document.getElementById(obj).value) == val)
                sonuc = false;
            break;
        case "r"://radio
            if(document.getElementById(obj).checked == val)
                sonuc = false;
            break;
        case "c"://checkbox
            if(document.getElementById(obj).checked == val)
                sonuc = false;
            break;
    }
    if(!sonuc && msj != '')alert(msj);
    if(!sonuc && setfcs)document.getElementById(obj).focus();

    return sonuc;
}
////////////////////////////////////////////////////////
function printdiv(obj)
{
    var a = window.open('','','');
    a.document.open("text/html");
    a.document.write('<link rel="stylesheet" href="/MagnificTour/css/magnifictour.css" />');
    a.document.write(document.getElementById(obj).innerHTML);
    a.document.getElementById('ReservationBtn').style.display='none';
    a.document.getElementById('CRight').style.display='none';
    a.document.close();
    a.print();
}
////////////////////////////////////////////////////////
function popCariExt(b,t,e)
{
    window.open('current_detail.aspx?b='+b+'&t='+t+'&e='+e,'','top=50,left=50,width=750,height=570,scrollbars=2');
}
/////////////////////////////////////////////////////////
function ilet(t)
{
	window.open('http://www.esenshop.com/popmail.aspx?t='+t,'','width=380,height=300');
}
////////////////////////////////////////////////////////
function setHidValExt(obj,hidobj,val)
{hidobj.value = val=='-bos-'?'':obj.options[obj.selectedIndex].value;}
function setHidValExt2(hidobj,val)
{hidobj.value = val;}
////////////////////////////////////////////////////////
function hsOrder(){
document.getElementById('ddSirala').value == '' ? document.getElementById('ddSiralaArt').style.display = 'none' : document.getElementById('ddSiralaArt').style.display = '';
//document.getElementById('ddSirala').value == '' ? document.getElementById('lnkRefresh').style.display = 'none' : document.getElementById('lnkRefresh').style.display = '';
}
////////////////////////////////////////////////////////
function hsNakit()
{document.getElementById('ddIslemTip').value != '' ? document.getElementById('ddNakit').style.display = '' : document.getElementById('ddNakit').style.display = 'none';
}
////////////////////////////////////////////////////////
function hsEkTarih()
{document.getElementById('ddBilgi').value != '1' ? document.getElementById('trEkTarih').style.display = 'none' : document.getElementById('trEkTarih').style.display = '';
if(document.getElementById('ddBilgi').value != '1'){sp('spZ','none','');document.getElementById('txtBaslaTarih').value = '';document.getElementById('txtBitisTarih').value = ''}
clrAll();
}
////////////////////////////////////////////////////////
function frmButGiz(bid,sid)
{
	document.getElementById(bid).style.display = 'none';
	document.getElementById(sid).style.display = '';
}
////////////////////////////////////////////////////////
function sayfaAdres()
{
	var a = document.URL.split("//"); // split at protocol
	a = (a[1] ? a[1] : a[0]).split("/");
	// use last element of a; split at /
	// host is a[0]; path is a[1..(n-1)]; a[n] is page
	return a[a.length-1];
}
////////////////////////////////////////////////////////

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_validateFormTR() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateFormTR.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; ad=args[i+1]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=Trim(val.value))!="") {//val.value
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+ad+' geçerli değil.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+ad+' gereklidir.\n'; }
  } if (errors) alert('Doldurulması Gereken Alanlar:\n'+errors);
  document.MM_returnValue = (errors == '');
}
function MM_validateFormENG() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateFormENG.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; ad=args[i+1]; val=MM_findObj(args[i]);
if (val) { nm=val.name; if (Trim(val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+ad+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+ad+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+ad+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+ad+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
///////////////////////////////////////////////////////
function cargoTakip(sno)
{
	var bgun = new Date();
	tar = bgun.getFullYear() + '/' + (parseInt(bgun.getMonth())+1).toString() + '/' + bgun.getDate();
	window.open('http://www.yurticikargo.com.tr/02.hizmet/gonderi_takip_pr_ozel.asp?ilktarih='+tar+'&ozel_alan='+sno,'','toolbar=false,statusbar=false,scrollbars=2,width=620,height=400');
	//frmButGiz('imgCargoAra','spKargoBekle');
}
////////////////////////////////////////////////////////
function validDate(bastar,bittar,x)
{//x=2592000000->30gun msec
	//bastar = document.getElementById('BaslaTarih').value;
	//bittar = document.getElementById('BitisTarih').value;
	
	var firstDate1 = new Date(bastar.split('/')[2],bastar.split('/')[1]-1,bastar.split('/')[0]);
	//var firstDate = Date.UTC( firstDate1.getFullYear(), firstDate1.getMonth()+1, firstDate1.getDate());
	var firstDate = Date.parse( (firstDate1.getMonth()+1)+"-"+firstDate1.getDate()+"-"+ firstDate1.getFullYear());
	//alert(firstDate);
	var secondDate1 = new Date(bittar.split('/')[2],bittar.split('/')[1]-1,bittar.split('/')[0]);
	//var secondDate = Date.UTC( secondDate1.getFullYear(), secondDate1.getMonth()+1, secondDate1.getDate());
	var secondDate = Date.parse( (secondDate1.getMonth()+1)+"-"+secondDate1.getDate()+"-"+ secondDate1.getFullYear());
	if(secondDate-firstDate>x*24*3600*1000){return false;}
	else return true;
}
