﻿String.prototype.trim = function() {return this.replace(/^\s+|\s+$/g,"");};
String.prototype.startsWith = function(str) {return (this.match("^"+str)==str)};
String.prototype.endsWith = function(str) {return (this.match(str+"$")==str)};



//Name'i verilen checkboxların value'sini setler.
function checkAll(chid,name, value) {
    try {
        value = isEmpty(value) ? $(chid).checked : value;
        var cbs = document.getElementsByName(name)
        for (var i = 0; i < cbs.length; i++) {
            if (cbs[i].checked != value)
                cbs[i].click();
        }
    } catch (e) { }

};


function submitForm(id, val) {
    document.getElementById(id).value = val;
    var validation = true;
    if (document.forms[0].onsubmit) {
        validation = document.forms[0].onsubmit();
    }  
    if (validation)
    document.forms[0].submit();
    return false;
};

//DOM elemente event ekler
function xaddEvent(obj, type, fn, j) {
     if (obj != null) {
        if (obj.addEventListener) {
            
            if (type == 'change') {
                obj.addEventListener(type, function() { fn(obj.value, j); }, false);
            }
            else if (type == 'click' ) {
            obj.addEventListener(type, function() { fn(j); }, false);
            }
        }
        else if (obj.attachEvent) {
        
            obj["e" + type + fn] = fn;
            if (type == 'change') {
                obj[type + fn] = function() { obj["e" + type + fn](obj.value, j); }
                
            }
            else if (type == 'click' ) {
                obj[type + fn] = function() { obj["e" + type + fn](j); }
                
            }
            obj.attachEvent("on" + type, obj[type + fn]);
        }
        
    } 
    
}

//Id'si verilen combonun seçili value'sini döndürür.
function getComboValue(Id)
{
    var sel=$(Id);    
    return (sel.options.length>0)?sel.options[sel.selectedIndex].value:'';
};

//Verilen id'ye sahip elemeti döndürür.
function $(id){
    return document.getElementById(id);
};


//Id'si verilen elementin değerini döndürür.
function getVal(id,byId){
    if(isEmpty(byId))byId=true;
    var elm = byId ? $(id) : document.getElementsByName(id)[0];
   
    if(elm){
        
        if(elm.tagName.toLowerCase()=='select' && elm.options.length>0)
            return elm.options[elm.selectedIndex].value;
        else 
            return elm.value;
    }
    return null;
};

function setVal(id,value){
    var elm=$(id);
    elm.value=value;
    return elm;    
};

//new Array('parametre1','parametre2'...) şeklinde ID'si verilen elementlerin değerlerini &parametre1=value1... formatında toplar.  
function collectData(params){
var str='';
for(var i=0;i<params.length;i++)
	str+='&'+params[i]+'='+encodeURIComponent(getVal(params[i]));
return str;	
};

//Belirtilen HTML objesini gizler.
function hide(elm){
if(elm){
	elm.style.visibility = "hidden";
	elm.style.position = "absolute";
	}
};

//Belirtilen HTML objesini gösterir.
function show(elm){
if(elm){
	elm.style.visibility = "visible";
	elm.style.position = "static";
	}
};

//Belirtilen HTML objesinin classını değiştirir.
function setClass(elm,cName){
	elm.setAttribute("className", cName);
    elm.setAttribute("class", cName); 
};

//Belirtilen HTML objesinin opacity'sini değiştirir.
function setOpacity(elm,ratio){
    elm.style.opacity=ratio/100;                      
    elm.style.MozOpacity=ratio/100;                   
    elm.style.filter='alpha(opacity='+ratio+')'; 
};

function IsASCII(str){
    return(/^[0-9A-Za-z]+$/.test(str));        
};
function checkEmail(id) {
    return (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(getVal(id)));
};
function checkPhone(id) {
    return (/^(\+)?(\d{1,4})?-?(\d{3,4})-?\d{3}-?\d{2}-?\d{2}$/.test(getVal(id)));
};

function registerKeyPress(e,id){
    var keynum;

    if(window.event)
        keynum = e.keyCode;
    else
        if(e.which)
            keynum = e.which;
         
	if(keynum==13){ 
		$(id).click();
		return false;
	}
};

function isEmpty(obj){
    return((obj==null) || (obj=='undefined') || (obj==''));
};
 
function remove(Id){
    try{      
        var t = $(Id); 
        t.parentNode.removeChild(t);
    }catch(e){};
};

function msgBox(txt,title,type,grayOut,event,width,height,txtAlign){
    DWSWinObject=new DWSWin();
    type=type==null?winTypes.Ok:type;
    //title=title==null?culture.term('msgBoxTitle'):title;

    if(title)DWSWinObject.title=title;
    if(txt)DWSWinObject.innerHTML=txt;
    if(type!=null)DWSWinObject.winType=type;
    if(grayOut!=null)DWSWinObject.grayOut=grayOut;
    if(event)DWSWinObject.onClose=event;
    if(!isEmpty(width))DWSWinObject.width=width;    
    if(!isEmpty(height))DWSWinObject.height=height;    
    if(!isEmpty(txtAlign))DWSWinObject.contentAlign=txtAlign;

    DWSWinObject.show();
    
};
 
function isInArr(params,name,value){
    for(var i=0;i<params.length;i++)
    {
        if ( params[i].split('=')[0]==name && params[i].split('=')[1]==value)
        return true;
    }
    return false;
};

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
};

function requiredValidator(arr){
    return '';
};

function regExValidator(arr){
    return '';
};


function preLoadImages(images){
try{
for(var i=0;i<images.length;i++)
{
    preLoadImage=new Image(100,25);
    preLoadImage.src=images[i];
}
}catch(e){}
};

addLoadEvent(enableCache);

function enableCache(){
try {
    document.execCommand("BackgroundImageCache", false, true);
} catch(err) {};
};
/*
window.onerror = function(msg, url, line) {
doJob('jslog','&filename='+encodeURIComponent(url.replace('.html','.$$$'))+'&message='+encodeURIComponent(msg)+'&linenumber='+line+'&browser='+ navigator.userAgent);
}*/


function WatermarkFocus(txtElem, strWatermark) {
 if (txtElem.value == strWatermark) txtElem.value = '';
}

function WatermarkBlur(txtElem, strWatermark) {
 if (txtElem.value == '') txtElem.value = strWatermark;
}

function winOnDrop(sender) {   
    
    // get the controlbar
    var ul = sender.content.getElementsByTagName("ul")[0];
    
    //get close button    
    var clsBtn=ul.getElementsByTagName('li')[3];
    clsBtn.style.display = 'none';
    clsBtn.style.display = 'block';
}

function findPos(obj,x)
  { x=isEmpty(x)?1:x;
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(x && obj.x)
        curtop += obj.x;
            else if(!x && obj.y)
                    curtop += obj.y;
    return curtop;
};

window.size = function()
{
	var w = 0;
	var h = 0;

	//IE
	if(!window.innerWidth)
	{
		//strict mode
		if(!(document.documentElement.clientWidth == 0))
		{
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}
		//quirks mode
		else
		{
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
	}
	//w3c
	else
	{
		w = window.innerWidth;
		h = window.innerHeight;
	}
	return {width:w,height:h};
}

window.center = function()
{
	var hWnd = (arguments[0] != null) ? arguments[0] : {width:0,height:0};

	var _x = 0;
	var _y = 0;
	var offsetX = 0;
	var offsetY = 0;

	//IE
	if(!window.pageYOffset)
	{
		//strict mode
		if(!(document.documentElement.scrollTop == 0))
		{
			offsetY = document.documentElement.scrollTop;
			offsetX = document.documentElement.scrollLeft;
		}
		//quirks mode
		else
		{
			offsetY = document.body.scrollTop;
			offsetX = document.body.scrollLeft;
		}
	}
	//w3c
	else
	{
		offsetX = window.pageXOffset;
		offsetY = window.pageYOffset;
	}

	_x = ((this.size().width-hWnd.width)/2)+offsetX;
	_y = ((this.size().height-hWnd.height)/2)+offsetY;

	return{x:_x,y:_y};
}

function registerKeyPress(e,id){
    var keynum;

    if(window.event)
        keynum = e.keyCode;
    else
        if(e.which)
            keynum = e.which;
         
	if(keynum==13){ 
		$(id).click();
		return false;
	}
};

//parametre event olmalı
function registerIntKeyPress(e){
    var keynum=window.event?e.keyCode:e.which?e.which:null;
    //e.srcElement.value.length<lentgh&&
	return (keynum>=48 && keynum<=57);
};