﻿bosluk=String.fromCharCode(32)
backSpace=String.fromCharCode(8)
enters=String.fromCharCode(10) + String.fromCharCode(13)
tab=String.fromCharCode(9)
backSlash=String.fromCharCode(92)
Slash=String.fromCharCode(47)
tekTirnak=String.fromCharCode(8217)
ciftTirnak=String.fromCharCode(8221)
tekTirnakErr=String.fromCharCode(39)
ciftTirnakErr=String.fromCharCode(34)

noktalama=".,?-()!:_*$" + backSlash + tekTirnak + ciftTirnak
rakamlar="0123456789" + backSpace
buyukHarfler="ABCÇDEFGĞHIİJKLMNOÖPQRSŞTUÜVWXYZ" + backSpace
kucukHarfler="abcçdefgğhıijklmnoöpqrsştuüvwxyz" + backSpace
browserName=navigator.userAgent.toLowerCase();
alertDiv=null;

documentURL=document.location.href

function trim(p_obj)
{
	p_obj.value=p_obj.value.replace(/^\s+|\s+$/g,"");
}

function showObj(p_obj)
{
	p_obj.style.display=""
}

function hideObj(p_obj)
{
	p_obj.style.display="none"
}

function textBoxLengthValidation(p_obj)
{
	if (p_obj.value.length<=parseInt(p_obj.getAttribute("maxlength")))
	{
		return true
	}
	return false
}

function keypressValidation(p_AllowedChars, p_keyCode)
{
	// ------------------- Örnek kullanım -----------------------
	// onkeypress="return keypressValidation(rakamlar+noktalama, getKey(event))"
	//-----------------------------------------------------------
	
	sonuc="";
	key = p_keyCode;
	
	for (k=0; k<p_AllowedChars.length; k++)
	{
		if (p_AllowedChars.charAt(k)==String.fromCharCode(key))
		{
			sonuc=p_AllowedChars.charAt(k)
			return true
		}
	}
	
	if (sonuc=="")
	{
		return false
	}
}

function keypressCheck(p_obj, p_AllowedChars, p_event)
{
	sonuc=-1;
	p_keyCode=getKey(p_event);

////////////////////////////////////////////////
//  bu 2 satırı sonradan ekledim (14.12.2009) //
	var harfSecimi1="";
	var harfSecimi2="";
////////////////////////////////////////////////

	if(!textBoxLengthValidation(p_obj))
	{
		return false
	}
	
	if (p_AllowedChars.charAt(0)=="A")
	{
		harfSecimi1=kucukHarfler;
		harfSecimi2=buyukHarfler;
	}
	else if (p_AllowedChars.charAt(0)=="a")
	{
		harfSecimi1=buyukHarfler;
		harfSecimi2=kucukHarfler;
	}

	if(!keypressValidation(p_AllowedChars, p_keyCode))
	{
		//alert("olmady 1")
		if(!keypressValidation(harfSecimi1, p_keyCode))
		{
			// Tek tirnagi convert ediyor
			if (p_keyCode==39)
			{
				wp_keyCode=8217
				return p_keyCode
			}
			
			// Cift tirnagi convert ediyor
			if (p_keyCode==34)
			{
				p_keyCode=8221
				return p_keyCode
			}
			
			return false
		}
		else
		{
			
			for (k=0; k<harfSecimi1.length; k++)
			{
				if (harfSecimi1.charAt(k)==String.fromCharCode(p_keyCode))
				{
					setKey(p_event, harfSecimi2.charAt(k).charCodeAt(0))
					return p_keyCode
				}
			}
			
			return false
		}
	}
}


function onblurValidation(p_gelenChar, p_AllowedChars)
{
	
	// Tek tirnagi convert ediyor
	if (p_gelenChar==tekTirnakErr)
	{
		p_gelenChar=tekTirnak
	}
	
	// Cift tirnagi convert ediyor
	if (p_gelenChar==ciftTirnakErr)
	{
		p_gelenChar=ciftTirnak
	}
	
	for (j=0; j<p_AllowedChars.length; j++)
	{
		if (p_AllowedChars.charAt(j)==p_gelenChar)
		{
			return p_AllowedChars.charAt(j)
		}
	}
	
	return ""	
}


function onblurBuyukHarf(p_gelenChar)
{
	for (m=0; m<kucukHarfler.length; m++)
	{
		if (kucukHarfler.charAt(m)==p_gelenChar)
		{
			return buyukHarfler.charAt(m)
		}
	}
	return p_gelenChar
}


function onblurKucukHarf(p_gelenChar)
{
	for (n=0; n<buyukHarfler.length; n++)
	{
		if (buyukHarfler.charAt(n)==p_gelenChar)
		{
			return kucukHarfler.charAt(n)
		}
	}
	return p_gelenChar
}


function onblurCheck(p_obj, p_AllowedChars)
{
	//p_AllowedChars oluşturulurken mutlaka önce harf dizisi,
	//sonra rakam vs. gelmeli
	//fonksiyon ilk harf "A" ise büyük harfe, "a" ise küçük harfe çeviriyor
	sonuc=""
	trim(p_obj)
	
	for (k=0; k<p_obj.value.length; k++)
	{	
		if (p_AllowedChars.charAt(0)=="A")
		{
			sonuc+=onblurValidation(onblurBuyukHarf(p_obj.value.charAt(k)), p_AllowedChars)
		}
		else if (p_AllowedChars.charAt(0)=="a")
		{
			sonuc+=onblurValidation(onblurKucukHarf(p_obj.value.charAt(k)), p_AllowedChars)
		}
		else
		{
			sonuc+=onblurValidation(p_obj.value.charAt(k), p_AllowedChars)
		}
	}

	p_obj.value=onblurMaximumLength(p_obj, sonuc)
}


function noEmpty(p_obj, p_Etiket)
{
	if (p_obj.value.length==0)
	{
		alert("[" + p_Etiket + "] alanını boş bırakamazsınız.")
		p_obj.focus()
		return false
	}
	
	return true
}


function isExact(p_obj, p_Etiket, p_Value)
{
	if (p_obj.value.length!=parseInt(p_Value))
	{
		alert("[" + p_Etiket + "] alanı tam olarak " + p_Value + " karakter uzunluğunda olmalıdır.")
		p_obj.focus()
		return false
	}
	
	return true
}

function isEmpty(p_obj)
{
	if (p_obj.value.length==0)
	{
		return true
	}
	
	return false
}

function checkMinimum(p_obj, p_Etiket, p_Min)
{
	if ( p_obj.value.length<parseInt(p_Min) )
	{
		alert("[" + p_Etiket + "] alanı minimum " + p_Min + " karakter uzunluğunda olmalıdır.")
		p_obj.focus()
		return false
	}
		
	return true
}

function onblurMaximumLength(p_obj, p_txtGelenSonuc)
{
	if ( p_txtGelenSonuc.length>parseInt(p_obj.getAttribute("maxlength")) )
	{
		return p_txtGelenSonuc.substr(0, parseInt(p_obj.getAttribute("maxlength")))
	}
	
	return p_txtGelenSonuc
}

function floatParser(p_string)
{
	return (parseFloat(p_string)*100)
}

function catchBackSpace()
{
	if(window.event.keyCode==8)
	{
		return true
	}
	else
	{
		return false
	}
}


function clearCombo(objCombo)
{
	if (objCombo)
	{
		itemAdet=objCombo.options.length
		while (itemAdet>0)
		{
			itemAdet=objCombo.options.length
			objCombo.options.remove(0)
		}
	}
}


function populateCombo(objCombo, p_ValueList)
{
	
	clearCombo(objCombo)
	valueArray=p_ValueList.split("|||")
	result=""
	
	for (say=0; say<valueArray.length; say++)
	{
		optionArray=valueArray[say].split("@@@")
		result=""
		for (say2=0; say2<optionArray.length; say2++)
		{
			result+="@" + optionArray[say2]
		}

		opt = document.createElement("OPTION")
		opt.value=(say+1).toString() + result
		opt.text=result.substr(1,result.length-1).replace(/@/g," - ")
		
		if (valueArray.length==1)
		{
			opt.selected=true
		}
		
		objCombo.add(opt, say)
	}
}

function getKey(e)
{
	if (!e) var e = window.event
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	return code;
}

function setKey(e, keyCode)
{
	if (!e) var e = window.event
	if (e.keyCode) e.keyCode = keyCode;
	else if (e.which) e.which = keyCode;
}



function returnDateNow()
{
	now=new Date()
	
	hour=now.getHours().toString()
	minute=now.getMinutes().toString()
	second=now.getSeconds().toString()
	monthnumber=(now.getMonth() + 1).toString()
	monthday=now.getDate().toString()
	year=now.getYear().toString()
	
	if (hour.length==1)
		hour="0" + hour
		
	if (minute.length==1)
		minute="0" + minute
	
	if (second.length==1)
		second="0" + second
		
	if (monthnumber.length==1)
		monthnumber="0" + monthnumber
	
	if (monthday.length==1)
		monthday="0" + monthday
		
	timeNow=monthday + "." + monthnumber + "." + year + " " +  hour + ":" + minute + ":" + second
	return timeNow
}


function createAlertDiv(intWidth, intHeight, strMesaj)
{
	alertDiv = document.createElement('div');
	alertDiv.setAttribute('id', 'alertDiv');
	alertDiv.style.width = intWidth;
	alertDiv.style.height = intHeight;
	alertDiv.style.position = "absolute";
	alertDiv.style.left = "0px";
	alertDiv.style.top = "0px";
	
	alertDiv.innerHTML = "<table border=" + ciftTirnakErr + "0" + ciftTirnakErr + " width=" + ciftTirnakErr + "100%" + ciftTirnakErr + " class=" + ciftTirnakErr + "alertTable" + ciftTirnakErr + " style=" + ciftTirnakErr + "border-collapse: collapse" + ciftTirnakErr + "><tr><td>" + strMesaj + "</td>";
//	alertDiv.style.display='none';
	
	document.body.appendChild(alertDiv);
}

function logVisit(strUserID, strPageURL)
{
	strXML="";
	strXML="<?xml version='1.0' encoding='UTF-8' ?>"
	strXML+="<myXML>"
	strXML+="<USER_ID>" + strUserID + "</USER_ID>"
	strXML+="<PAGE_URL>" + strPageURL + "</PAGE_URL>"
	strXML+="</myXML>"

	executeAjax("POST", "logs.asp", false, strXML)
//	strSonuc=ajaxResult;
//	alert(strSonuc);
}

function changeColor(strObjID, strClassName)
{
	document.getElementById(strObjID).className=strClassName;
}

function createLoadingTable(strMessage)
{
	if (document.getElementById("tblLoading")==null)
	{
		var objNewTable=document.createElement("TABLE");
		var objNewTBody=document.createElement("TBODY");
		var objNewTR=document.createElement("TR");
		var objNewTD=document.createElement("TD");
		
		objNewTR.appendChild(objNewTD);
		objNewTBody.appendChild(objNewTR);
		objNewTable.appendChild(objNewTBody);
		
		objNewTable.setAttribute("border", "0");
		objNewTable.setAttribute("id", "tblLoading");
		objNewTable.setAttribute("style", "border-collapse: collapse");
		objNewTable.style.position="absolute";
		objNewTable.style.display="none";
		objNewTable.style.zIndex="11";
		objNewTable.className="tb_form";
	
		strInnerHTML="<table border='0' style='border-collapse: collapse'>"
		strInnerHTML+="<tr bgcolor='#FFFFFF'>"
		strInnerHTML+="<td><img border='0' src='images/loading.gif'></td>"
		strInnerHTML+="<td><b><font style='font-size: 20px' color='#A7A7A7' id='fntMessage'>"+strMessage+"</font></b></td>"
		strInnerHTML+="</tr>"
		strInnerHTML+="</table>"
		
		objNewTable.getElementsByTagName("TD")[0].innerHTML+=strInnerHTML;
		document.body.appendChild(objNewTable);
	}
	else
	{
		document.getElementById("fntMessage").innerText=strMessage;
	}

	return document.getElementById("tblLoading");
}

function hideLoadingTable()
{
	document.getElementById("tblLoading").style.display="none";
}

function createDarkDiv()
{
	if (document.getElementById("darkDiv")==null)
	{
		var objDarkDiv=document.createElement("DIV");
		objDarkDiv.setAttribute("id", "darkDiv");
		objDarkDiv.className="darkDiv";
		objDarkDiv.style.display="none";
		document.body.appendChild(objDarkDiv);
	}
	
	return document.getElementById("darkDiv");
}

function hideDarkDiv()
{
	document.getElementById("darkDiv").style.display="none";
}

function raiseDialog(objDialog, objDarkDiv)
{
	browserName=navigator.userAgent.toLowerCase();
	
	if (browserName.indexOf('msie') > -1)
	{
		browserWidth=document.body.offsetWidth;
	}
	else
	{
		browserWidth=window.innerWidth;
	}

	objDialog.style.display="";
	intDialogWidth=parseInt(objDialog.offsetWidth);
	objDialog.style.left=parseInt((browserWidth-intDialogWidth)/2).toString()+"px";
	intYukseklik=parseInt(document.body.scrollTop)+300
	objDialog.style.top=intYukseklik.toString()+"px";
	
	objDarkDiv.style.display="";
	objDarkDiv.style.width=document.body.scrollWidth.toString()+"px";

	if (parseInt(document.body.scrollHeight)<parseInt(document.body.clientHeight))
	{
		darkDivHeight=document.body.clientHeight.toString()+"px";
	}
	else
	{
		darkDivHeight=document.body.scrollHeight.toString()+"px";
	}
	
	objDarkDiv.style.height=darkDivHeight;
}

function check_uncheck_all(strObjMainTableId)
{
	objTable=document.getElementById(strObjMainTableId);
	objTopCheckBox=document.getElementById("cb_0");

	
	if (objTopCheckBox.checked==true)
	{
		for (i = 2; i < objTable.rows.length-1; i++)
		{
			dummyArr=objTable.rows[i].cells[0].getElementsByTagName("INPUT");
			if (dummyArr.length==0)
			{
				break;
			}
			
			dummyArr[0].checked=true;
			objTable.rows[i].className='value-chosen';
		}
	}
	else
	{
		for (i = 2; i < objTable.rows.length-1; i++)
		{
			dummyArr=objTable.rows[i].cells[0].getElementsByTagName("INPUT");
			if (dummyArr.length==0)
			{
				break;
			}
			dummyArr[0].checked=false;
			objTable.rows[i].className='value';
		}
	}
}

function showBorders(objGelen)
{
	strSRC=objGelen.src;
	dummyArrSRC=strSRC.split(".");
	strSRCnew=""
	
	for (i = 0; i < dummyArrSRC.length-1; i++)
	{
		strSRCnew+=dummyArrSRC[i] + ".";
	}
	
	strSRCnew=strSRCnew.substr(0,strSRCnew.length-1);
	
	strSRCnew+="_border." + dummyArrSRC[i];
	objGelen.src=strSRCnew;
}

function hideBorders(objGelen)
{
	strSRC=objGelen.src;
	dummyArrSRC=strSRC.split("_border.");
	
	strSRCnew=""
	
	for (i = 0; i < dummyArrSRC.length-1; i++)
	{
		strSRCnew+=dummyArrSRC[i] + ".";
	}
	
	strSRCnew+=dummyArrSRC[i];
	objGelen.src=strSRCnew;
}

function comboBoxSelector(strComboID, strSelectValue)
{
	objComboBox=document.getElementById(strComboID);
	
	for (k=0; k<objComboBox.length; k++)
	{
		if (objComboBox[k].value==strSelectValue)
		{
			objComboBox[k].selected=true;
			break;
		}
	}
}

function comboReSort4OnTalep(objCombo2ReSort)
{
	objUrunHizmetCombo=objCombo2ReSort;
	newOptionIndex=0
	for (k=0; k<objUrunHizmetCombo.length; k++)
	{
		if (objUrunHizmetCombo[k].text=="Ön Talep")
		{
			newValue=objUrunHizmetCombo[k].value;
			newText=objUrunHizmetCombo[k].text;
			newOptionIndex=k;
			break;			
		}
	}

	if (newOptionIndex!=0)
	{
		var selValues = new Array();
		var selTexts = new Array();
		intComboLength=objUrunHizmetCombo.length;
		intOptionIndex=0
	
		for (k=0; k<intComboLength; k++)
		{
			if (k==1)
			{
				selValues[intOptionIndex]="";
				selTexts[intOptionIndex]="";
				intOptionIndex+=1;
			}
	
			selValues[intOptionIndex]=objUrunHizmetCombo[k].value;
			selTexts[intOptionIndex]=objUrunHizmetCombo[k].text;
			intOptionIndex+=1;
		}
	
		for (k=0; k<intComboLength; k++)
		{
			objUrunHizmetCombo.options[0] = null;
		}
		
		for (k=0; k<selValues.length; k++)
		{
			objUrunHizmetCombo.options[k] = new Option(selTexts[k], selValues[k]);
		}
	
		newOptionIndex=0
		for (k=0; k<objUrunHizmetCombo.length; k++)
		{
			if (objUrunHizmetCombo[k].text=="Ön Talep")
			{
				newValue=objUrunHizmetCombo[k].value;
				newText=objUrunHizmetCombo[k].text;
				newOptionIndex=k;
				break;			
			}
		}
		
		objUrunHizmetCombo.options[1] = new Option(newText, newValue);
		objUrunHizmetCombo.options[newOptionIndex] = null;
	}
}
