﻿//Update: 2011-01

function IsValidEmail(str) {
    var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,8})$/;
    return (filter.test(str));
}

/* Description : Locate Popup page to center. */
	function PopupWindow(pURL, pH, pW) {
    //if (typeof pH == "undefined") pH = "default value";
    if (!pW) {
        pW = 320;
    }
    if (!pH) {
        pH = 250;
    }
    
	//window.status = '';
	var winleft = (screen.width - pW) / 2;
	var wintop = (screen.height - pH) / 2; 
	
	var args = "top=" + wintop + ", left=" + winleft + ", width=" + pW + ", height=" + pH + ", toolbar=0, menubar=0, scrollbars=0, status=-1, resizable=-1";

	var wForm = window.open(pURL,"wndPopup",args);

	return wForm;
}



/* Description : İlgili elemanın görünüp, gizlenmesini sağlar. */
function ToggleDisplay(pID_or_Obj) {
    var obj = pID_or_Obj; //Nesne olarak kabul edilsin.

    if (obj.length) { //Nesne uzunluğu tanımlı ise, ID olarak ele alınsın
        //alert("obj length: " + obj.length);
        obj = document.getElementById(pID_or_Obj);
    }
    
    if (obj==null) return;
    
    if (obj.style.display==''){
        obj.style.display='none';
    }else{
        obj.style.display=''; 
    }
}


/*İlgili nesnenin işlem yaptığını gösteren bir simge ekler */
function InProgress(pIDSource) {
    var objSource = document.getElementById(pIDSource);
    if (objSource != null) {
        objSource.className = "cssInProgress";
        objSource.disabled = true;
    }
}


/*Enter tuşuna basıldığında bir butona basar.*/
function CheckEnterKey(e, btnId) {
    var evt = e ? e : window.event;
    var btn = document.getElementById(btnId);
    if (btn) {
        if (evt.keyCode == 13) {
            btn.click();
            return false;
        }
    }
}


//QueryString parametresini verir.
function querystring(pURL, pKey) {
	 if (pURL.indexOf("?")<0) return ""; //no query
	 
    var query = pURL.split("?")[1]; //window.location.search.substring(1); //Hata: pURL.search.substring(1)   
    var parms = query.split('&');
    //var hash = window.location.hash;
    //var parms = hash.split('&');
    var gkey, gval;
    for (var i = 0; i < parms.length; i++) {
        var pos = parms[i].indexOf('=');
        if (pos > 0) {
            gkey = parms[i].substring(0, pos);
            gval = parms[i].substring(pos + 1);

            if (pKey == gkey) {
                return gval;
            }
        }
    }
    
    return ""; //not found
}


//script dosyası ekler. 2012
function AddScriptByURL(pURL) {
    var gScript = document.createElement('script');
    gScript.type = 'text/javascript';
    gScript.src = pURL;
    document.getElementsByTagName('head')[0].appendChild(gScript);
}

