﻿
function onImgError(source)
{
    source.src = 'http://i.biarada.com/imageNotfound.gif';
    source.onerror = '';
    return true;
}


function queryStringGetValue(param) 
{
   var URL = location.href
   if(param!=null) {
   var regEx = new RegExp("(\\?|&)("+param+"=)(.*?)(&|$|#)","i")
   var exec = regEx.exec(URL)
   var Sonuc = RegExp.$3
} 
else 
{
   var regEx = new RegExp("(\\?)(.*?)($)","i")
   var exec = regEx.exec(URL)
   var Sonuc = RegExp.$2
}
   return(Sonuc)
}
function ChangeSort(value)
{
var url = location.href;
if(url.indexOf('&pgNo')>0 || url.indexOf('?pgNo')>0)
{
url = url.replace('&pgNo='+queryStringGetValue("pgNo"),'&pgNo=0');
url = url.replace('?pgNo='+queryStringGetValue("pgNo"),'?pgNo=0');
}
else
{
if(url.indexOf('?')>0)
{
url = url+'&pgNo=0';
}
else
{
url = url+'?pgNo=0';
}

}
if(url.indexOf('&st=')>0)
{
url = url.replace('&st='+queryStringGetValue("st"),'&st='+value);
}
else
{
url = url+'&st='+value;
}
location.href=url;
}

function ChangeHits(value)
{
var url = location.href;
if(url.indexOf('&lh=')>0)
{
url = url.replace('&lh='+queryStringGetValue("lh"),'&lh='+value);
}
else
{
if(url.indexOf('?')>0)
{
url = url+'&lh='+value;
}
else
{
url = url+'?lh='+value;
}
}
location.href=url;
}

function checkStock()
{
    var obj = document.getElementById('imgStock')
    if(document.getElementById('hdnStock').value==1)
    {
        obj.src = 'http://i.biarada.com/chk.jpg';
        document.getElementById('hdnStock').value = 0; 
    }
    else
    {
        obj.src = 'http://i.biarada.com/chkChecked.jpg';
        document.getElementById('hdnStock').value = 1;
    }
}
function btnSearch_onclick() {
    
    if(document.getElementById("txtSearch").value.length>0)
    { 
    var searchText= ReplaceAll(document.getElementById("txtSearch").value,'"','');
    var t=setTimeout("SearchUrl(0);",400);
    
    if (window.XMLHttpRequest){xhttp=new XMLHttpRequest();}else{xhttp=new ActiveXObject("Microsoft.XMLHTTP");}
    xhttp.open("GET","http://www.birarada.info/log.aspx?Operation=SRC&Keyword="+Url.encode(searchText).replace(/\+/g,"%2B"),false);
    xhttp.send("LogData");
    }
    return false;
}
function btnSearchFilter_onclick() {
    
    if(document.getElementById("txtSearch").value.length>0)
    { 
    var searchText= ReplaceAll(document.getElementById("txtSearch").value,'"','');
    var t=setTimeout("SearchUrl(1);",400);
    
    if (window.XMLHttpRequest){xhttp=new XMLHttpRequest();}else{xhttp=new ActiveXObject("Microsoft.XMLHTTP");}
    filter='minP='+document.getElementById('txtStartPrice').value+';maxP='+document.getElementById('txtEndPrice').value;
   
    xhttp.open("GET","http://www.birarada.info/log.aspx?Operation=FILTER&Keyword="+Url.encode(searchText).replace(/\+/g,"%2B") +'&ExtraInfo='+filter,false);
    xhttp.send("LogData");
    }
    return false;
}
function SearchUrl(type){
    var filter='';
    if(type==1)
    {
        filter='&minP='+document.getElementById('txtStartPrice').value+'&maxP='+document.getElementById('txtEndPrice').value+'&st='+document.getElementById('cmbOrder').options[document.getElementById('cmbOrder').selectedIndex].value+'&pgNo=0';
    }
    document.location.href ='en-ucuz-'+Url.encode(ReplaceAll(ReplaceAll(ReplaceAll(ReplaceAll(document.getElementById("txtSearch").value,'"',''),'/',''),'%',''),'*',''))+'-fiyati,,,urun-ara.aspx?src='+Url.encode(document.getElementById("txtSearch").value).replace(/\+/g,"%2B")+'&stock='+document.getElementById('hdnStock').value+filter;
    return false;
}

function ClickButton(e, buttonid)
{ 
    var bt = document.getElementById(buttonid); 
	if (typeof bt == 'object'){ 
	    if (e.keyCode == 13){ 
	        bt.click(); 
			return false; 
		} 
    } 
}
function loadSearchPage()
{
    document.getElementById('txtSearch').focus();
    document.getElementById('txtSearch').value=document.getElementById('hdnSearchText').value;
}


function ChangeDatail(id)
{
   if(document.getElementById('detay'+id).style.display=="block")
    {
        document.getElementById('detay'+id).style.display = "none";
        document.getElementById('prdHrefDetail'+id).innerHTML = "Detayı Aç";
        
    }
    else
    {
        document.getElementById('detay'+id).style.display = "block";
        document.getElementById('prdHrefDetail'+id).innerHTML = "Detayı Kapat";
    }
}
    
function loadPageDefault()
{
 document.getElementById('txtSearch').focus();
}
function btnSort_onclick()
{
    document.location.href =document.getElementById('cmbOrder').value;
    return false;
}
function noSrcSearch(src) {
    document.getElementById("txtSearch").value = src;
    btnSearch_onclick();
}


function ReplaceAll(Source,stringToFind,stringToReplace){
var temp = Source;
var index = temp.indexOf(stringToFind);
while(index != -1){
    temp = temp.replace(stringToFind,stringToReplace);
    index = temp.indexOf(stringToFind);
}
return temp;
}
    
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}
function ChangeShare()
    {
        if(document.getElementById('shareAll').style.display=="none")
            document.getElementById('shareAll').style.display="block";
        else
            document.getElementById('shareAll').style.display="none";
    }
    
    function makeURL(nod)
      {
      var title = document.title;
      var url = document.location.href;
      var options = "height=700,width=800,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1";
      var mURL='';
      if(nod==1)
      mURL="http://www.facebook.com/sharer.php?u=" + url + "&title=" + title;
      if(nod==2)
      mURL="http://www.google.com/bookmarks/mark?op=edit&bkmk=" + url + "&title=" + title;
      if(nod==3)
      mURL="http://myweb2.search.yahoo.com/myresults/bookmarklet?&u=" +url+ "&t=" + title;
      if(nod==4)
      mURL="http://www.mixx.com/submit/story?title="+title+"&page_url="+url+"&partner=Biarada&description=";
      if(nod==5)
      mURL="http://digg.com/submit?url="+url+"&title=" + title; 
      if(nod==6)
      mURL="http://www.stumbleupon.com/submit?url="+url+"&title=" + title;
      if(nod==7)
      mURL="http://del.icio.us/post?url="+url+"&title=" + title;
      if(nod==8)
      mURL="http://reddit.com/submit?url="+url+"&title=" + title;
      if(nod==9)
      {mURL="http://twshot.com/share.aspx?url="+url+"&title=" + title;}
      if(nod==10)
      mURL="http://www.myspace.com/Modules/PostTo/Pages/?l=2&u=" +url+ "&t="+title+"&c="+title;
      if(nod==11)
      mURL="http://friendfeed.com/share/bookmarklet/frame#title=" + title + "&url="+url;
      if(nod==12)
      {
        options = "height=235,width=675,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1";
        mURL="http://www.azbuz.com/shareObject.jsp?t=" + title + "&u="+url;
      }
       mURL=encodeURI(mURL);
      window.open(mURL.replace(/amp;/gi,''),'_blank',options);

      }
      function shareTwitter(articleID){
          var title = encodeURI(document.getElementById('hiddenTitle').value);
          //var url = escape(document.getElementById('hiddenURL').value);
          var options = "height=700,width=800,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1";
          window.open('http://twitter.com/home?status='+title+' '+'http://milliyet.com.tr/d/t.aspx?ID='+articleID,'_blank',options);
      }
function numbersonly(B)
{
var A=B.charCode?B.charCode:B.keyCode;
if(A!=8&&A!=9&&A!=13)
{
    if((A<48||A>57)&&A!=13)
        return false
}
if(A==13)
    return btnSearchFilter_onclick();
else
    return true;
}


