function popUp(url,w,h)
{
	window.open(url,"anneyizPopUp","width="+w+",height="+h);
}

function popUp2(url,w,h, t,l)
{
	window.open(url,"commentPop","width="+w+",height="+h +",left=" + l+ ",top="+t);
}

function _toggle(id)
{
	s = document.getElementById(id);
	if(s.style.display=="none")
		s.style.display = "block";
	else
		s.style.display = "none";
}

function isNumberKey(evt)
{
	
	 var charCode = (evt.which) ? evt.which : event.keyCode;

	 if (charCode > 31 && (charCode < 48 || charCode > 57))
	 {
		if(charCode == 46)
		{
			return true;
		}
		return false;
	}

	 return true;
}

function appendFileField()
{
	newContainer = document.createElement("div");
	newFileField = document.createElement("input");
	newFileField.setAttribute("type","file");
	newFileField.setAttribute("name","productPictures[]")
	newFileField.setAttribute("class","textfield2");
	newContainer.appendChild(newFileField);
	document.getElementById("imgs").appendChild(newContainer);
}

var gift_field_counter = 1;
function appendTextField()
{
	gift_field_counter++;
	newContainer = document.createElement("div");
	
	newTextField = document.createElement("input");
	newTextField.setAttribute("type","text");
	newTextField.setAttribute("name","gift[]");
	newTextField.setAttribute("class","textfield3");

	newButtonField = document.createElement('input');
	newButtonField.setAttribute("class","textfield2");
	newButtonField.setAttribute("type","button");
	
	sss = "popUp('productList.php?c=gift" + gift_field_counter + "',800,400)";
	
	newButtonField.setAttribute("onclick", sss);
	newButtonField.setAttribute("value","Ürün Seç");	
	
	newTextField.id = "gift" + gift_field_counter;
	newContainer.appendChild(newTextField);
	newContainer.innerHTML +=" ";
	newContainer.appendChild(newButtonField);
	document.getElementById('gifts').appendChild(newContainer);
}

var related_product_counter = 1;
function appendTextField2()
{
	related_product_counter++;
	newContainer = document.createElement("div");
	newTextField = document.createElement("input");
	newTextField.setAttribute("type","text");
	newTextField.setAttribute("name","relatedProducts[]");
	newTextField.setAttribute("class","textfield3");
	
	newButtonField = document.createElement('input');
	newButtonField.setAttribute("class","textfield2");
	newButtonField.setAttribute("type","button");
	
	sss = "popUp('productList.php?c=rel_prod" + related_product_counter + "',800,400)";
	
	newButtonField.setAttribute("onclick", sss);
	newButtonField.setAttribute("value","İlişkili Ürünleri Belirle");
	
	newTextField.id = "rel_prod" + related_product_counter;
	newContainer.appendChild(newTextField);
	newContainer.innerHTML +=" ";
	newContainer.appendChild(newButtonField);
	newContainer.innerHTML +="<br>";
	document.getElementById('rel_products').appendChild(newContainer);
}


var product_variation_counter = 1;
function appendTextField3()
{
	newContainer = document.createElement("div");
	newTextField = document.createElement("input");
	newTextField.setAttribute("type","text");
	newTextField.setAttribute("name","productVariationNames[]");
	newTextField.setAttribute("class","textfield");
	newTextField2 = document.createElement("input");
	newTextField2.setAttribute("type","text");
	newTextField2.setAttribute("name","productVariationValues[]");
	newTextField2.setAttribute("class","textfield");
	
	newContainer.innerHTML +="<br>";
	newContainer.appendChild(newTextField);
	newContainer.innerHTML +=" - ";
	newContainer.appendChild(newTextField2);
	document.getElementById('product_variations').appendChild(newContainer);
}

function showHide(id)
{
	s = document.getElementById(id);
	s.style.position ="absolute";
	
	if(s.style.display=="none")
	{
		if(navigator.appName == "Microsoft Internet Explorer")
		{
			document.getElementById('supplier').style.display = 'none';
			document.getElementById('currency').style.display = 'none';
			document.getElementById('brand').style.display = 'none';
		}
		s.style.display = "block";
		s.style.left = 0;
	}
	else
	{
		if(navigator.appName == "Microsoft Internet Explorer")
		{
			document.getElementById('supplier').style.display = 'block';
			document.getElementById('currency').style.display = 'block';
			document.getElementById('brand').style.display = 'block';
		}
		s.style.display = "none";
		
	}
}

function showHide1(id)
{
	s = document.getElementById(id);
	s.style.position ="absolute";
	
	if(s.style.display=="none")
	{
		s.style.display = "block";
		s.style.left = 0;
	}
	else
	{
		s.style.display = "none";
	}
}

function checkedCount(f, fieldname)
{
	var total = "";
	chkArray = f.elements[fieldname];
	for(var i=0; i < chkArray.length; i++)
	{
		if(chkArray[i].checked)
			total += chkArray[i].value;
	}
	
	if(total=="")
		return false;
	return true;
}


function checkAddPrForm(f)
{
	if(!checkedCount(f,"c[]"))
	{
		alert('Lütfen ürünü en az 1 kategori ile ilişkilendiriniz.');
		showHide('categories');
		return false;
	}
	
	if(selectedValue(f.supplier)== 0)
	{
		alert("Lütfen Tedarikçi Seçiniz");
		return false;
	}
	if(selectedValue(f.brand)==0)
	{
		alert("Lütfen Marka Seçiniz");
		return false;		
	}

	if(f.productName.value=="")
	{
		alert("Lütfen Ürün Adı Giriniz");
		return false;		
	}
	
	if(f.price.value=="")
	{
		alert("Lütfen Ürün Fiyatını Giriniz");
		return false;		
	}	

	if(f.amount.value=="")
	{
		alert("Lütfen Ürün Stok Adetini Giriniz");
		return false;		
	}
	
	return true;
}

function selectedValue(selBox) 
{  
   retVal = selBox.options[selBox.selectedIndex].value;
   return retVal;
}

function redirect(par1)
{
	url  = "users.php?t=" + par1;
	document.location.href = url;
}

//swap
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
// /swap

//selecboxda val degerli optioni secmek icin
function selectOption(selectbox, val)
{
	for(i = 0; i < selectbox.options.length; i++)
	{
		if(typeof(selectbox.options[i]) != 'undefined')
		{
			if(selectbox.options[i].value == val)
			{
				selectbox.options[i].selected = 'true';
			}
		}
	}
}

function IsBankSelected(f)
{
	if(selectedValue(f.bank) == 0)
	{
		alert('Lütfen Banka seçiniz.');
		return false;
	}
	return true;
}

//check payment form's requiered fields
function checkPaymentForm(f)
{
	if(f.ccNo.value.length < 15 )
	{
		alert('Kredi Kartı Numaranızı Eksik Girdiniz!');
		return false;
	}
	
	if(f.ccCV2.value.length < 3)
	{
		alert('Kredi Kartı Güvenlik Numarasını eksik girdiniz (CV2)!');
		return false;
	}
	
	if(f.ccFullname.value == '')
	{
		alert('Kart Üzerindeki İsmi Yazmadınız');
		return false;
	}	
	
	if(f.ccExMonth.value.length < 2)
	{
		alert('Son Kullanım Tarihini Ay Bilgisini Eksik Girdiniz!');
		return false;
	}	
	
	if(f.ccExYear.value.length < 2)
	{
		alert('Son Kullanım Tarihini Yıl Bilgisini Eksik Girdiniz!');
		return false;
	}	
}

function checkOneField(el)
{
	
	if(!document.getElementById('paymentTypeT').checked && 
	   !document.getElementById('paymentTypeHP').checked && 
	   !document.getElementById('paymentTypeKO').checked )
	{
		if(selectedValue(el) == 0)
		{
			alert('Lütfen, ödeme yapacağınız kartı seçiniz.');
			return false;
		}
	}
}

function checkEmail(email){
		if(email.indexOf(".") != -1 && email.indexOf("@") != -1 )
			return true;
		return false;
}

function checkFormPass(f)
{
	if(f.email.value == '' )
	{
		alert('E-Postanızı yazınız.');
		return false;
	}
	
	if(!checkEmail(f.email.value))
	{
		alert('Geçerli bir E-posta adresi giriniz.');
		return false;
	}
}

Array.prototype.sum = function(){
	for(var i=0,sum=0;i<this.length;sum+=this[i++]);
	return sum;
}
Array.prototype.max = function(){
	return Math.max.apply({},this)
}
Array.prototype.min = function(){
	return Math.min.apply({},this)
}


function fill_installments(bankId){
	
	if(document.getElementById('ccPayment2').checked)
	{
		str = "<select name =\"taksit\" id=\"taksit\">";		
	}
	else if(document.getElementById('taksit').disabled)
		str = "<select name =\"taksit\" id=\"taksit\" disabled = \"disabled\">";
	else
		str = "<select name =\"taksit\" id=\"taksit\">";
		
	for (k = 0; k < InstallmentArray[bankId].length ; k++)
	{
		if(InstallmentArray[bankId][k] > 0)
			str += "<option>" + InstallmentArray[bankId][k] + "</option>";
	}
	str += "</select>";
	document.getElementById('taksitler').innerHTML = str;
}

function changeFormAction(formName, actionPage)
{
	if(document.getElementById('txtSearch').value.length > 0)
	{
		document.forms[formName].action = actionPage;
		return true;
	}
	else
		return false;
}

function SetMonthRange(selBox, inputId1,inputId2)
{
	selVal = selectedValue(selBox);
	inp1 = document.getElementById(inputId1);
	inp2 = document.getElementById(inputId2);
	
	switch(selVal)
	{
		case "January":
		    inp1.value = "01/01/2008";
			inp2.value = "01/31/2008";
			break;
		case "February":
		    inp1.value = "02/01/2008";
			inp2.value = "02/29/2008";
			break;
		case "March":
		    inp1.value = "03/01/2008";
			inp2.value = "03/31/2008";
			break;
		case "April":
		    inp1.value = "04/01/2008";
			inp2.value = "04/30/2008";
			break;
		case "May":
		    inp1.value = "05/01/2008";
			inp2.value = "05/31/2008";
			break;
		case "June":
		    inp1.value = "06/01/2008";
			inp2.value = "06/30/2008";
			break;
		case "July":
		    inp1.value = "07/01/2008";
			inp2.value = "07/31/2008";
			break;
		case "August":
		    inp1.value = "08/01/2008";
			inp2.value = "08/31/2008";
			break;
		case "September":
		    inp1.value = "09/01/2008";
			inp2.value = "09/30/2008";
			break;
		case "October":
		    inp1.value = "10/01/2008";
			inp2.value = "10/31/2008";
			break;
		case "November":
		    inp1.value = "11/01/2008";
			inp2.value = "11/31/2008";
			break;
		case "December":
		    inp1.value = "12/01/2008";
			inp2.value = "12/31/2008";
			break;																																
	}
}