﻿ahandaholder = false;
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 IsMailValid(value)
{
    var x = value;
    var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!filter.test(x))
        return false;
    else
        return true; 
}
function changeClass(objId,cssClass)
{
    document.getElementById(objId).className = cssClass;
}

function OpenPopup(pageLink,width,height,positionTop,positionLeft,parUseScrollBar) 
{
    popupWin=window.open(pageLink,'myNewWin','menubar=1,resizable=1,width='+width+',height='+height+',top='+positionTop+',left='+positionLeft+',scrollbars='+parUseScrollBar)
    return popupWin;
}
function OpenPopupWithOutReturn(pageLink,width,height,positionTop,positionLeft,parUseScrollBar) 
{
    popupWin=window.open(pageLink,'myNewWin','menubar=1,resizable=1,width='+width+',height='+height+',top='+positionTop+',left='+positionLeft+',scrollbars='+parUseScrollBar)
    }

function NewWindow(Sayfa,En,Boy) {
	window.open(Sayfa, 'Baslik', "height="+Boy+",width="+En+",top=200,left=200,status=yes,toolbar=no,menubar=no,location=no,scrollbars=no");
}
function NewWindowImage(Sayfa,En,Boy) {
	window.open(Sayfa, 'Baslik', "height="+Boy+",width="+En+",top=200,resizable=1,left=200,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes");
}
function GetbyAttr ( name, tag ) {
    var results = new Array();
    var elems = document.getElementsByTagName("*");
    var len = elems.length;

    if (name == "class") {
        for (var i = 0; i < len; i++) {
            if (elems[i].className) {                  
                results.push(elems[i]);
            }
        }
        return results;
    } else if (name == "for" && document.all) {
        name = "htmlFor";
    }

    for (var i = 0; i < len; i++) {
        if (elems[i].getAttribute(name)) {
            results.push(elems[i]);
        }
    }
    return results;
}

function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
function wordwrap(parString,parCharAmount)
{
    html = "";
	pointer = 0;
	index = -1;
	TotalCharAmount = parString.length;
	    while (pointer < TotalCharAmount )
	    {
		    index = (parString.substring(pointer,parCharAmount+pointer)).indexOf(' ');
		    if(index != -1 || parString.substring(pointer,parCharAmount+pointer).length != parCharAmount)// boşluk varsa
		    {
                if(parString.substring(pointer,parCharAmount+pointer).length != parCharAmount)
                {
                    html += parString.substring(pointer,parCharAmount+pointer);
                    pointer = TotalCharAmount;
                }
                else
                {
                    html += parString.substring(pointer,index+1+pointer);
		            pointer = pointer+index+1;
		        }
		        
	        }
	        else
	        {
		        html+= "<div>";
		        html+= parString.substring(pointer,parCharAmount+pointer);
		        html += "</div>";
		        pointer = pointer+parCharAmount;
	        }
	}
	    return html;
}

function ModalAc(Sayfa,En,Boy) {
	window.showModalDialog(Sayfa, "", "dialogHeight:"+Boy+"px; dialogWidth:"+En+"px;help:no;scroll:yes");
}

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }





//Global XMLHTTP Request object
var XmlHttp;
var slcSehirClientID = 'slcSehir';
var slcBelediyeClientID = 'slcBelediye';
var slcPartiClientID = 'slcParti';





function OnSlcPartiChanged()
{
    RedirectIfSehirAndPartiBothSelected();    
}

function RedirectIfSehirAndPartiBothSelected()
{
    var sehirList = document.getElementById(slcSehirClientID);
	//Getting the selected sehir
	var selectedSehirID = sehirList.options[sehirList.selectedIndex].value;	
	
	if(selectedSehirID != '')
	{	  
	    var partiList = document.getElementById(slcPartiClientID);
	    //Getting the selected parti
	    var selectedPartiID = partiList.options[partiList.selectedIndex].value;
	    
	    if(selectedPartiID != '')
	    {
	        document.location = "http://www.radikal.com.tr/secim2009/secimpartidetay.aspx?sehirid=" + selectedSehirID + "&" + "partiid=" + selectedPartiID;
	    }	    		
	}	
}

////////////////
/////////////// Sehir Belediye ajax
//////////////
//Creating and setting the instance of appropriate XMLHTTP Request object to 
//a "XmlHttp" variable  
function CreateXmlHttp()
{
    //Creating object of XMLHTTP in IE
    try
    {
        XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
        try
        {
            XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        } 
        catch(oc)
        {
            XmlHttp = null;
        }
    }
    //Creating object of XMLHTTP in Mozilla and Safari 
    if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
    {
        XmlHttp = new XMLHttpRequest();
    }
}


function OnSlcSehirChanged()
{    
    RedirectIfSehirAndPartiBothSelected();   
    var sehirList = document.getElementById(slcSehirClientID);
	//Getting the selected sehir
	var selectedSehirID = sehirList.options[sehirList.selectedIndex].value;
	ClearBelediyeListItems();
	
	if(selectedSehirID == '')
	{	  
	    return;	
	}
	
    var belediyeList = document.getElementById(slcBelediyeClientID);
           
    var requestUrl = "/secim2009/api/belediyelist.ashx" + "?sehirid=" + selectedSehirID;
    CreateXmlHttp();
     
    // If browser supports XMLHTTPRequest object
    if(XmlHttp)
    {
        //Setting the event handler for the response
        XmlHttp.onreadystatechange = HandleSlcSehirChangedResponse;

        //Initializes the request object with GET (METHOD of posting), 
        //Request URL and sets the request as asynchronous.
        XmlHttp.open("GET", requestUrl,  true);

        //Sends the request to server
        XmlHttp.send(null);  
    }
 }
   
 function HandleSlcSehirChangedResponse()
 {
    if(XmlHttp.readyState == 4)
     {
        // To make sure valid response is received from the server, 
        // 200 means response received is OK
        if(XmlHttp.status == 200)
        {  
            ClearAndSetBelediyeListItems(XmlHttp.responseText);
        }
        else
        {
            alert("There was a problem retrieving data from the server." );
        }
     }
 }
 
 
 function ClearBelediyeListItems()
 {
    var belediyeList = document.getElementById(slcBelediyeClientID);
    
    //Clears the belediye combo box contents.
    for (var count = belediyeList.options.length-1; count >0; count--)
    {
        belediyeList.options[count] = null;
    }
 }
 
 function ClearAndSetBelediyeListItems(responseText)
 {
    var belediyeList = document.getElementById(slcBelediyeClientID);        
    var belediyeNodes = responseText.split(";");       
    var ValueAndText;
    var selectValue;
    var selectText;
    var optionItem;
    
    //Add new belediye list to the state combo box.
    for (var count = 0; count < belediyeNodes.length; count++)
    {
        ValueAndText = (belediyeNodes[count]).split("#");
        selectValue = ValueAndText[0];
        selectText = ValueAndText[1];
                
        optionItem = new Option(selectText, selectValue ,  false, false);        
        belediyeList.options[belediyeList.length] = optionItem;
    }
 }
 
//////////////
////////////// End - Sehir Belediye ajax
/////////////
 
 
function OnSlcBelediyeChanged()
{
    var belediyeList = document.getElementById(slcBelediyeClientID);
	//Getting the selected sehir
	var selectedBelediyeID = belediyeList.options[belediyeList.selectedIndex].value;
			
	
	if(selectedBelediyeID != '')
	{
	    var sehirList = document.getElementById(slcSehirClientID);
	    var selectedSehirID = sehirList.options[sehirList.selectedIndex].value;	      
	    document.location = "http://www.radikal.com.tr/secim2009/secimildetay.aspx?belediyeid=" + selectedBelediyeID + "&sehirid=" + selectedSehirID;
	}	
}

function OnBtnSubmitClicked()
{
    //Secilen sehir
    var sehirList = document.getElementById(slcSehirClientID);
	var selectedSehirID = sehirList.options[sehirList.selectedIndex].value;
	
	var partiList = document.getElementById(slcPartiClientID);
	//Getting the selected sehir
	var selectedPartiID = partiList.options[partiList.selectedIndex].value;
    
    
        if(selectedSehirID != "")
        {
            document.location = "http://www.radikal.com.tr/secim2009/secimildetay.aspx?sehirid=" + selectedSehirID;
            return;
        }
        
        if(selectedPartiID != "")
        {        
            document.location = "http://www.radikal.com.tr/secim2009/secimpartidetay.aspx?partiid=" + selectedPartiID;
            return;                    
        }
        window.alert("Lütfen arama kriteri seçin.")               
    
}

function ChangeCityDetail(obj)
{
    document.location = "http://www.radikal.com.tr/secim2009/secimildetay.aspx?sehirid="+obj.options[obj.selectedIndex].value;
}

