// JavaScript Document
	
function getURL(lnk,trgt){
	trgt.location.href = lnk
	}

function wOp(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function popFormRelease(frm,rszPop){
	var theForm = document.getElementById(frm);
	var popForm = window.open("","popForm","width=300,height=150,scrollbars=no,status=yes");
	if (rszPop){resizeWindow(popForm,300,220)}
	theForm.submit();
	}

function resizeWindow(win,wid,heg) {
	if(win!=""){obj = win}else{obj = window}
	var topAlign = (screen.height/2)-(heg/2);	//Ortalama için üst boşluk
	var leftAlign = (screen.width/2)-(wid/2);	//Ortalama için sol boşluk
	obj.moveTo(leftAlign, topAlign);
	obj.resizeTo(width=wid, height=heg);
}

function checkFormValues(form,clr,email){
	for (i=0;i<form.elements.length;i++){
		if (form.elements[i].id.indexOf("g_") != -1){
			if (form.elements[i].value == ""){form.elements[i].parentNode.bgColor=clr;form.elements[i].focus();return false;var sendForm = false;}else{form.elements[i].parentNode.bgColor='';var sendForm = true;}
		}
	}
	if (email!=""){
	if (checkEmail(form.email)=='0'){form.email.parentNode.bgColor=clr;form.email.focus();var sendForm = false;}else{form.email.parentNode.bgColor='';var sendForm = true;}
	}
	if (sendForm == true){form.submit();}
	}

function checkEmail(field){
	var email = field.value
	if (email.indexOf("@") == "-1"){return "0"}else{
		if (email.lastIndexOf(".") == "-1"){return "0"}
		}
	}

function CorrectDateStr(field){
	if(field.value.length>7){
		var tarih = field.value
		if (tarih != ""){
			tarihSpl = tarih.split(".")
			gun = Number(tarihSpl[0])
			ay = Number(tarihSpl[1])
			yil = Number(tarihSpl[2])
			
			if (gun < 10){gun = "0"+""+gun;}
			
			if (ay < 10){ay = "0"+""+ay;}
			
			field.value = gun+"."+ay+"."+yil
		}
	}
}

var xmlhttp=false;
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

function sendLoad(nesne, lnk){
	var nesne_ = document.getElementById(nesne)
	nesne_.innerHTML = "<span style='color:#CCCCCC'><em>Yükleniyor</em></span>";
	xmlhttp.open("GET", lnk ,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4){
		var alinan = xmlhttp.responseText
		nesne_.innerHTML = alinan;
		}else{nesne_.innerHTML = "";}
	}
	xmlhttp.send(null);
}

function getListProperty(str,fldGrp,fldCat){
	var lnk = "_aListener.asp?page="+str+"&grupID="+fldGrp.options[fldGrp.selectedIndex].value+"&kategoriID="+fldCat.options[fldCat.selectedIndex].value
	sendLoad(str, lnk);
	}
	
function setPageTitle(str){
		pageTitle.innerHTML = str
	}
	
function setPageSubTitle(str){
		pageSubTitle.innerHTML = str
	}
	
function siparisFormSubmit(){
	var sForm = document.getElementById("siparisForm")
	if(document.getElementById("firma").value==""){
		sendForm = false;
		al("* Bu alan gerekli: Hastane Adı");
		document.siparisForm.firma.focus();
		return false;
	}else{
		sendForm = true;
	}
	
	if(document.getElementById("yetkili").value==""){
		sendForm = false;
		al("* Bu alan gerekli: Yetkili Adı");
		document.siparisForm.yetkili.focus();
		return false;
	}else{
		sendForm = true;
	}
	
	if(document.getElementById("gsm").value==""){
		sendForm = false;
		al("* Bu alan gerekli: Gsm No");
		document.siparisForm.gsm.focus();
		return false;
	}else{
		sendForm = true;
	}
	
	if(document.getElementById("basket").value==""){
		sendForm = false;
		al("* Lütfen Ürün Seçiniz!");
		document.siparisForm.urunler.focus();
		return false;
	}else{
		sendForm = true;
	}
	
	if(sendForm == true){sForm.submit();}
}

function al(str){
	document.getElementById("resultSpan").innerHTML = str;
}

function transferCount(fld){
		var cnt = fld.options[fld.selectedIndex].title
		document.getElementById("adet").value = cnt
		document.getElementById("ekleButton").disabled=false;
	}
	
function siparisEkle(tblID,opt1,opt2){
	var str1 = opt1.options[opt1.selectedIndex].value
	var str2 = opt2.value
	if(str1!=""&&str2!=""){
		var tbl = document.getElementById(tblID)
		var td = tbl.getElementsByTagName("TD");
		insertRow(tblID)
		var row1 = td[td.length-3]
		var row2 = td[td.length-2]
		row1.innerHTML = str1
		row2.innerHTML = str2
		al("");
		}else{
			al("Lütfen Ürün Seçiniz!."+retOptValue(opt1)+" / "+str2)
		}
		addBasket(str1,str2)
		document.getElementById("ekleButton").disabled=true;
}

function deleteRowByLink(lnk){
  var tableRow = lnk.parentNode.parentNode;
  tableRow.parentNode.deleteRow(tableRow.rowIndex);
}

function insertRow(tblID){
	var tbl = document.getElementById(tblID);
	var tr = tbl.getElementsByTagName("TR")
	var rowIndex = tr.length;
	try {
		var newRow = tbl.insertRow(rowIndex);
		var newCell = newRow.insertCell(0);
		var newCel2 = newRow.insertCell(1);
		var newCel3 = newRow.insertCell(2);
		newCell.innerHTML = '&nbsp;';
		newCel2.className = 'siparisAdet'
		newCel2.innerHTML = '&nbsp;';
		newCel3.align = "center"
		newCel3.innerHTML = '<a href="javascript:void(0)" onClick="deleteRowByLink(this)">Sil</a>';
	} catch (ex) {
		al(ex);
	}
}

function addBasket(prodName,prodCount){
	document.siparisForm.basket.value += prodName + "[]" + prodCount + "&"
}


function chgCls(field,cls){
field.className = cls;
	}

function chgClsx(field,cls1,cls2){
if (field.className == cls1){field.className = cls2}else{field.className = cls1}
	}

function showImage(img){
		var imgSrc = img.src.split("small/");
		wOp('bigImg.asp?page='+imgSrc[1],'bigImg','width=500,height=400,scrolling=no,resizable=yes,status=yes');
	}
	
function setPersonImg(fld){
	if(fld.value!=''){
		var file = fld.value;
		if(controlFileFormat(file) == true){
			document.getElementById("tmbImg").src=fld.value;
			}else{
			alert("Lütfen seçtiğiniz dosya formatının resim formatlarından biri olduğundan emin olun!");
			}
	}
	}
	
function controlFileFormat(val){
	var iterFileType = new Array(".JPG",".GIF");
	var fileType = val.substring(val.lastIndexOf("."),val.length).toUpperCase();
	for(i=0;i<iterFileType.length;i++){
		if(iterFileType[i]==fileType){
			return true;
			break
			}else{
				return false;
				}
		}
	}