﻿//UPDATED Y. Cengeloglu 13.8.2007
//Cantekin GÜNEŞER
//BizListBoxDual'ta listitem'lari tasimak icin kullaniliyor.
function  MoveItem(cId,rmv,direction)
{
	var srcItem;
	var destItem;
	var hdnDest;
	var hdnSrc;
	if(direction == "LtR")
	{
		srcItem = document.getElementById(cId + "__lbxDualSource");
		destItem = document.getElementById(cId + "__lbxDualDestination");		
		hdnDest = document.getElementById(cId + "__hdnDestItems");	
		hdnSrc = document.getElementById(cId + "__hdnSrcItems");
	}
	else
	{
		srcItem = document.getElementById(cId + "__lbxDualDestination");
		destItem = document.getElementById(cId + "__lbxDualSource");		
		hdnDest = document.getElementById(cId + "__hdnSrcItems");	
		hdnSrc = document.getElementById(cId + "__hdnDestItems");
	}
		
	for(var i = srcItem.options.length - 1; i >= 0; i--)
	{
		if(srcItem.options[i].selected)
		{
			if(!IsExist(hdnDest.value,seperatorThird + srcItem.options[i].value+seperatorThird ))
			{
				destItem.options[destItem.length] = new Option(srcItem.options[i].text,srcItem.options[i].value);
				hdnDest.value += seperatorThird + srcItem.options[i].value + seperatorThird + seperatorFirst + srcItem.options[i].text + seperatorSecond;
				
			}
			if(rmv)
			{
				hdnSrc.value = hdnSrc.value.replace( seperatorThird + srcItem.options[i].value + seperatorThird + seperatorFirst + srcItem.options[i].text + seperatorSecond ,'');
				srcItem.options[i] = null;				
			}
			else
			{
				if(direction == "RtL")
				{
					hdnSrc.value = hdnSrc.value.replace( seperatorThird + srcItem.options[i].value + seperatorThird + seperatorFirst + srcItem.options[i].text + seperatorSecond ,'');
					srcItem.options[i] = null;
				}	
			}	
		}
	}	
}

function IsExist(hdnSrc,val)
{
	if(hdnSrc.indexOf(val) == -1)
	{	
		return false;		
	}
		
	return true;	
}
 

//DECLARATION
var displayLanguages = 0;

function OnFormSubmit() {
    if (typeof(ListBoxes)!="undefined"){        
        for (var OuterCount = 0; OuterCount < ListBoxes.length; OuterCount++){        
            var LangS  = document.all[ListBoxes[OuterCount]];
            if(LangS!="undefined"){
                var len = LangS.options.length;
                for (var count = 0; count < len; count++) LangS.options[count].selected=true;            
            }
        }     
    }
}


/* MENU FUNCS */
function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

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 ShowHideLanguage(divName)
{
	if(displayLanguages==0)
	{
		ShowLanguages(divName);
	}
	else if(displayLanguages==1)
	{
		HideLanguages(divName);
	}
}

function ShowLanguages(divName)
{
	var dLanguages = document.getElementById(divName);
	if(dLanguages)
	{
		dLanguages.style.display='block';
		displayLanguages = 1;
	}
}

function HideLanguages(divName)
{
	var dLanguages = document.getElementById(divName);
	if(dLanguages)
	{
		dLanguages.style.display='none';
		displayLanguages = 0;
	}
}
/* END OF MENU FUNCS */

//Date: 2005-04-11
//Purp: This method sets text element's readOnly attribute..
function SetFormElementReadOnlyState(elementID, readOnlyState)
{
	var txtElement = document.getElementById(elementID)
	if(txtElement != null)
	{
		txtElement.readOnly = readOnlyState;
		if(txtElement.readOnly)
		{
			txtElement.value="";
		}
	}
}//<SetTxtElementReadOnlyState>


//BizNumeric control'unde kullaniliyor
//Click ile sayiyi arttirip, azaltman icin kullaniliyor
function UpDown(dr,object)	
{
	var chc = document.getElementById(object + '_numeric')
	if(dr == "up")
	{
		chc.value =  Number(chc.value) + 1;
	}
	else
	{
		if(Number(chc.value) > 0 )
		{
			chc.value =  Number(chc.value) - 1;
		}	
	}
}

//BizNumeric control'unde kullaniliyor
function ControlNumeric( obj,e,sep )
{
	var k;	
	k = e.keyCode;		
	
	//ğ = 287; ş = 351; ı = 305 ;  
	if(k == 351 || k == 287 || k == 305)
	{
		return false;
	}
	if( k>=32 && k<=255 )
	{
		if( (k>=48 && k<58))
		{ 
			return true;
		}
		return false;
	}
	
	if (sep == ",")
	{
		if ((k==46) || (k==44 && (obj.value.indexOf(sep,0) >= 0 ||  obj.value.length == 0)))
		{
			return false;
		}
	}
	if (sep == ".")
	{
		if ((k==44) || (k==46 && (obj.value.indexOf(sep,0) >= 0 ||  obj.value.length == 0)))
		{
			return false;
		}
	}
	if( k>=32 && k<=255 ) {
		if( (k>=48 && k<58) || k==44 || k==46) 
			return true;
		return false;
	}
}	

function addSrcToDestListC(sourceList, destionationList) {
				
    destList = document.getElementById(destionationList);
    srcList = document.getElementById(sourceList);
    var len = destList.length;
    for(var i = 0; i < srcList.length; i++) {
	    if ((srcList.options[i] != null) && (srcList.options[i].selected)) {
		    //Check if this value already exist in the destList or not
		    //if not then add it otherwise do not add it.
		    var found = false;
		    for(var count = 0; count < len; count++) {
			    if (destList.options[count] != null) {
				    if (srcList.options[i].text == destList.options[count].text) {
					    found = true;
					    break;
				    }
			    }
		    }
		    if (found != true) 
		    {
    			
			    destList.options[len] = new Option();
			    destList.options[len].text = srcList.options[i].text;
			    destList.options[len].value = srcList.options[i].value;
    			
			    destList.options[len].selected=true;
			    len++;
		    }
	    }
    }
}

function deleteFromDestListT(destionationList) {
	destList = document.getElementById(destionationList);
	var len = destList.options.length;
	for(var i = (len-1); i >= 0; i--) {
		if ((destList.options[i] != null) && (destList.options[i].selected == true) && (destList.options[i].value != 'sil')) {
		destList.options[i] = null;
		}
	}
}
function addSrcToDestListCLimited(sourceList, destionationList, maxCount) {
	destList = document.getElementById(destionationList);
    srcList = document.getElementById(sourceList);
	
	var len = destList.length;
	for(var i = 0; i < srcList.length; i++) {
		if ((srcList.options[i] != null) && (srcList.options[i].selected)) {
			//Check if this value already exist in the destList or not
			//if not then add it otherwise do not add it.
			var found = false;
			for(var count = 0; count < len; count++) {
				if (destList.options[count] != null) {
					if (srcList.options[i].text == destList.options[count].text) {
						found = true;
						break;
					}
				}
			}
			if (found != true) {
				if (len >= maxCount)
				{
				    alert("En fazla "+maxCount+" farklı seçim yapabilirsiniz !" )
					return;
				}
				destList.options[len] = new Option(srcList.options[i].text);
				destList.options[len].value = srcList.options[i].value;
				
				//destList.options[1en].selected=true;
				len++;
			}
		}
	}
}
function addSrcToDestListCLimited(sourceList, destionationList, maxCount) {
				destList = document.getElementById(destionationList);
                srcList = document.getElementById(sourceList);			
								
				var len = destList.length;
				for(var i = 0; i < srcList.length; i++) {
					if ((srcList.options[i] != null) && (srcList.options[i].selected)) {
						//Check if this value already exist in the destList or not
						//if not then add it otherwise do not add it.
						var found = false;
						for(var count = 0; count < len; count++) {
							if (destList.options[count] != null) {
								if (srcList.options[i].text == destList.options[count].text) {
									found = true;
									break;
								}
							}
						}
						if (found != true) {
							if (len >= maxCount)
							{
							    alert("En fazla "+maxCount+" farklı seçim yapabilirsiniz !" )
								return;
							}
							destList.options[len] = new Option(srcList.options[i].text);
							destList.options[len].value = srcList.options[i].value;
							
							destList.options[len].selected=true;
							len++;
						}
					}
				}
			}
			
// Popup pencere açan fonksiyon
function popup(url,name,width,height,scrollbars,resizable,status,toolbar,menubar,location,directories)
{    
	var scrollbars = 'yes'
	var winl = (screen.width - width) / 2;
	var wint = (screen.height - height) / 2;                
	var option = "top=" + wint + ",left=" + winl + ",toolbar="+ toolbar +",location="+ location +",directories=" 
		+ directories +",status="+ status +",menubar="+ menubar +",scrollbars="  
		+ scrollbars +",resizable="  + resizable +",width=" + width +",height="+ height;
	var win = window.open(url,name,option);
	win.opener = window;
}

// Maksimum karkater kontrolü
function TextCounter(field, maxlimit) 
{
if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);
}
