﻿// JScript File

// Trim
function Trim(s,c) 
   {
   	// Remove leading spaces and carriage returns
   	while ((s.substring(0,1) == c) || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
   	 { s = s.substring(1,s.length); }
     
   	// Remove trailing spaces and carriage returns
    while ((s.substring(s.length-1,s.length) == c) || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
   	 { s = s.substring(0,s.length-1); }
     
   	return s;
   }
   
// Maksimum karkater kontrolü
function TextCounter(field, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);
}

// 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;
	
	return win
}

// Popup modal açan fonksiyon
function popupModal(url,name,width,height,scrollbars,resizable,status,toolbar,menubar,location,directories)
{    
    if(window.showModalDialog)
    {
	    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 +";dialogWidth=" + width +"px;dialogHeight="+ height + "px;";
		    
		var o = new Object();
        o.opener = window;

	    window.showModalDialog(url,o,option);	
	    return o;	    
	}
	else
	{
	    	var scrollbars = 'yes'	    	
	        var winl = (screen.width - width) / 2;
	        var wint = (screen.height - height) / 2; 	        
	        var option = "modal=yes,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;
	        return win;
	}
}

// Kursoru alanın sonuna getirir
function insertAtCursor(myField, myValue) 
{
    myField.value = '';
    
    //IE support
    if (document.selection) {
    myField.focus();
    sel = document.selection.createRange();
    sel.text = myValue;
    }
    
    //MOZILLA/NETSCAPE support
    else if (myField.selectionStart || myField.selectionStart == 0) {
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
    myField.value = myField.value.substring(0, startPos)
    + myValue
    + myField.value.substring(endPos, myField.value.length);
    } else {
    myField.value += myValue;
    }
}

//Geçerleme için(kontrol onBlur eventinde) 
function ControlOnBlur(obj)
{    
    if(Trim(obj.value,' ') != '' || (obj.Changed != null && obj.Changed)){try{ValidateControl(obj);obj.Changed=true;}catch(e){}}
}    

// Girilen kontrol için geçerleme yapar
function ValidateControl(obj)
{
    if (obj.Validators != null)
    {
        var vals = obj.Validators;
        var i;
    
        for (i = 0; i < vals.length; i++) {
            ValidatorValidate(vals[i]);
        }
        
        ValidatorUpdateIsValid();
     }    
}

// İlk hatalı alana odaklanır
function FocusOnError()
{
    if (Page_Validators != null)
    {
        for( var i=0; i < Page_Validators.length; i++ )
        { 
            if( !Page_Validators[i].isvalid ) 
            {               
              var obj = document.getElementById(Page_Validators[i].controltovalidate);
              obj.focus(); 
              if(obj.value != null)
                insertAtCursor(obj,obj.value);
              return; 
            } 
        }
    }
}

// Listelerden aktarma yapan fonksiyonlar
function moveOver(from,to,hdn, separatorFirst, separatorSecond)  
{
	var selectedItem = from.selectedIndex;		
	var boxLength = to.length;
	
	if (selectedItem < 0) return;
	var selectedText = from.options[selectedItem].text;
	var selectedValue = from.options[selectedItem].value;
	var i;
	var isNew = true;

	if (boxLength != 0) {
		for (i = 0; i < boxLength; i++) {
			thisitem = to.options[i].text;
			if (thisitem == selectedText) {
			isNew = false;
			break;
	      }
	   }
} 
if (isNew) {
	newoption = new Option(selectedText, selectedValue, false, false);
	to.options[boxLength] = newoption;
	hdn.value = hdn.value + selectedText + separatorSecond + selectedValue + separatorFirst;	
	if (boxLength == 0 ){ValidateControl(to)};
}
from.selectedIndex=-1;
}

function moveAllOver(from,to)  
{
	var boxLength = from.length;

	if (boxLength != 0) {
		for (i = 0; i < boxLength; i++) 
		{
			moveOver(from,to,i)
		}
	}
}

function removeMe(list,isAll,hdn, separatorFirst, separatorSecond) 
{
	var boxLength = list.length;
	arrSelected = new Array();
	var count = 0;
	for (i = 0; i < boxLength; i++) {
		if (list.options[i].selected || isAll) {
		arrSelected[count] = list.options[i].value;
		hdn.value = hdn.value.replace(list.options[i].text + separatorSecond + list.options[i].value + separatorFirst,'');
		}
	count++;
	}
	var x;
	for (i = 0; i < boxLength; i++) {
		for (x = 0; x < arrSelected.length; x++) {
			if (list.options[i].value == arrSelected[x]) {
				list.options[i] = null;
		   }
		}
		boxLength = list.length;
	   }
}

function selectAll(list)
{
   	if (list != null)
	{
		var boxLength =list.length;

		if (boxLength != 0) {
			for (i = 0; i < boxLength; i++) 
			{
				list.options[i].selected = true;
			}
		}	
	}
}
 
function getSelectedValues(list, seperator) 
{
    var selectedValue = '';
    
   	if (list != null)
	{
		var boxLength =list.length;

		if (boxLength != 0) {
			for (i = 0; i < boxLength; i++) 
			{
				if (list.options[i].selected == true)				
				    selectedValue = list.options[i].value + seperator + selectedValue;				    
			}
		}	
	}
	
	if(selectedValue != '')	
	    selectedValue = Trim(selectedValue,seperator);
	    
	return selectedValue;
}

// Kayan kutu        
var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
var px = document.layers ? "" : "px";

function JSFX_FloatDiv(id, sx, sy)
{    
	var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;
	el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};
	el.flt=function()
	{
		var pX, pY;
		
		pX = (this.sx >= 0) ? 0 : ns ? innerWidth + pageXOffset : 
		document.documentElement && document.documentElement.clientWidth ? 
		document.documentElement.clientWidth + document.documentElement.scrollLeft: document.body.clientWidth + document.body.scrollLeft;
		
		pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
		document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0) 
		pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
		document.documentElement.clientHeight : document.body.clientHeight;
		
		this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
		this.sP(this.cx, this.cy);		
		setTimeout(this.id + "_obj.flt()", 20);
	}
	return el;
}


// Css class değiştirmek için kullanılır
function changeClasses(currentdoc)
{
    var inputElements = currentdoc.getElementsByTagName('input');
    
	for (var i=0; i<inputElements.length; i++)
	{
	    if(inputElements[i].className == '')
	    {
		    if(inputElements[i].type == "button" || inputElements[i].type == "submit")
		    {
			    inputElements[i].className = inputElements[i].className + " button";			    
		    }
		    else if (inputElements[i].type == "checkbox")
		    {
			    inputElements[i].className = inputElements[i].className + " checkbox";		
		    } 
		    else if (inputElements[i].type == "radio")
		    {
			    inputElements[i].className = inputElements[i].className + " radio";
		    } 
		    else if (inputElements[i].type == "text")
		    {
			    inputElements[i].className = inputElements[i].className + " textbox";
		    }
		}	
	}
}

// Yazdırma modunda sayfa açar
function OpenPageInPrintPreview(PrintAreaHTML,PrintAreaScript)
{
        var win = popup('', 'Print',800,800,1,1,0,1,1);
        if(win != null)
        {         	
	        win.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"><link rel="stylesheet" href="Style.css" media="screen" /><link rel="stylesheet" href="Script/Calendar/calendar.css" media="screen" /><script type="text/javascript" language="javascript" src="Script/JsLib.js"></script><meta http-equiv="content-type" content="text-html; charset=utf-8"><base target="_self"></head><body>');        	
	        win.document.write(PrintAreaHTML);						
	        win.document.write('<script>' + PrintAreaScript + '</script>');						
	        win.document.write('</body>');
	        win.document.write('</html>');	
        }        
}
    
// Yazdırma modunda sayfa açar
function OpenPageInPrintPreview () { 
   var browserObject; 
   if (document.getElementById) { 
     browserObject = document.getElementById('printWB'); 
     try
     {
     if (browserObject && typeof browserObject.execWB != 'undefined') { 
       browserObject.execWB(7, 0); 
     }
     }
     catch(e)
     {
        return;
     } 
   } 
}

//İlgili kutucukları tikler
function SetAllCheckBox(controlNameIndex,status)
{ 
	var cbs = new Array;
	cbs = document.getElementsByTagName('input');
	
	for(i=0; i < cbs.length ; i++)
	{
		if( cbs[i].id.indexOf(controlNameIndex) != -1)
		{	
		    if(!cbs[i].disabled)				
		        cbs[i].checked = status;
		}		
	} 
}

//Seçili kutucuk olup oladığını döner
function CheckSelectedItem(controlNameIndex)
{ 
	var cbs = new Array;
	cbs = document.getElementsByTagName('input');
	
	for(i=0; i < cbs.length ; i++)
	{
		if( cbs[i].id.indexOf(controlNameIndex) != -1 && cbs[i].checked)
		{					
		    return true; 
		}		
	} 
	
	return false;
}

//Seçili değerleri döner
function GetSelectedItems(controlNameIndex)
{ 
	var cbs = new Array;
	cbs = document.getElementsByTagName('input');
	var selectedItems = '';
	var objProp='';
	
	for(i=0; i < cbs.length ; i++)
	{
		if( cbs[i].id.indexOf(controlNameIndex) != -1 && cbs[i].checked)
		{					
		    selectedItems = cbs[i].ItemId + ',' + selectedItems; 
		}		
	} 
	
	if(selectedItems != '')
        selectedItems = selectedItems.substring(0,selectedItems.length -1);
	
	return selectedItems;
}

/** Kontrollerin görünürlüğü belirlenir */
function SetVisibility(visibilitySetterId,visibilityHolderId,controlId,hiddenModeValue,visibleModeValue,hiddenModeTitle,visibleModeTitle,hiddenModeImageUrl,visibleModeImageUrl,mode)
{
    var visibilitySetter = document.getElementById(visibilitySetterId);
    var visibilityHolder = document.getElementById(visibilityHolderId); 
    var control = document.getElementById(controlId);        
    
    if (control != null)
    {
        if (mode != null)
        {
            if (mode == '')
                control.mode = visibilityHolder.value;        
            else
                control.mode = mode;
        }
            
        if(control.mode == hiddenModeValue)
        {
           control.style.display = 'none';
           control.mode = visibleModeValue;
           visibilitySetter.title = visibleModeTitle;
           visibilitySetter.src = visibleModeImageUrl;
           visibilityHolder.value = hiddenModeValue;
        }
        else if(control.mode == visibleModeValue)
        {
           control.style.display = 'inline';
           control.mode = hiddenModeValue;
           visibilitySetter.title = hiddenModeTitle;
           visibilitySetter.src = hiddenModeImageUrl;    
           visibilityHolder.value = visibleModeValue;  
        }      
    }
}

/** Parasal formatlama yapar*/
function FormatCurrency (n, c, d, t){
    c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "",
    i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
    return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t)
    + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};

/** Adet ve fiyat alınarak, toplam değer güncellenir*/
function CalculateTotal(countControlId,priceControlId,totalControlId,thousandSeparator,decimalSeperator)
{              
     var countControl = document.getElementById(countControlId);
     var priceControl = document.getElementById(priceControlId);
     var totalControl = document.getElementById(totalControlId);
     
     if(countControl.value != '' && priceControl.value != '')            
     {  
        var prc;
        var sep = ",";

        if(thousandSeparator == '.')          
        {
            prc = priceControl.value.replace(/\./g,'').replace(',','.');            
        }
        else
        {
            prc = priceControl.value.replace(/,/g,'').replace(',','.');
        }   
        if(countControl.value * prc < Number.MAX_VALUE)    
        {
            var value = (parseFloat(countControl.value) * parseFloat(prc)).toString();                 
            var dec = 0;
            var pos = value.indexOf('.') + 1;
            if (pos>0)
                dec = 2;
                       
            totalControl.innerHTML = FormatCurrency(value,dec,decimalSeperator,thousandSeparator);            
        }
        else
        {
            totalControl.value = '';
        }  
        //totalControl.focus();
        //totalControl.blur();                
     }
}

// SlideShow parameters and functions

var slideImages = new Object();
var slideCounters = new Object();
var slideTimeouts = new Object();
var slideState = new Object();

function Image(Id, PartId, PartName, ContentId, ContentName, TypeId, Name, Description, Path, Width, Height, ThumbnailWidth, ThumbnailHeight)
{
    this.Id = Id
    this.PartId = PartId
    this.PartName = PartName
    this.ContentId = ContentId
    this.ContentName = ContentName
    this.TypeId = TypeId
    this.Name = Name
    this.Description = Description
    this.Path = Path
    this.Width = Width
    this.Height = Height
    this.ThumbnailWidth = ThumbnailWidth
    this.ThumbnailHeight = ThumbnailHeight    
} 

function SetProcessSlide(Index, TimeOut, ImageControlId, ImageDescriptionControlId, Order)
{
    if(Order < 0 || Order >= slideImages[Index].length) Order = 0;    
    
    var images = slideImages[Index];    
    var imageInfo = images[Order];
    var imageControl = document.getElementById(ImageControlId);
    var imageDescriptionControl = document.getElementById(ImageDescriptionControlId);    
    
    imageControl.src = imageInfo.Path;
    imageControl.width = imageInfo.Width;
    imageControl.height = imageInfo.Height;
    if(imageDescriptionControl != null)
        imageDescriptionControl.text = ((imageInfo.Description != '') ? imageInfo.Description : ((imageInfo.ContentName != '') ? imageInfo.ContentName : imageInfo.PartName));
    
    slideCounters[Index] = Order;
    if(typeof slideState[Index] == 'undefined')
        slideState[Index] = 1;
        
    if(slideState[Index] == 1)
    {
        Order = Order + 1;        
        if(Order >= slideImages[Index].length) Order = 0;
        slideTimeouts[Index] = setTimeout("ProcessSlide('" + Index + "'," + TimeOut + ",'" + ImageControlId +  "','" + ImageDescriptionControlId + "'," + Order + ")", TimeOut);                
    }
}

function ProcessSlide(Index, TimeOut, ImageControlId, ImageDescriptionControlId, Order)
{
    var images = slideImages[Index];
    var imageInfo = images[Order];
    var imageControl = document.getElementById(ImageControlId);
    var imageDescriptionControl = document.getElementById(ImageDescriptionControlId);
    var canSlide = (slideState[Index] == 1 );
    
    imageControl.src = imageInfo.Path;
    imageControl.width = imageInfo.Width;
    imageControl.height = imageInfo.Height;
    if(imageDescriptionControl != null)
        imageDescriptionControl.text = ((imageInfo.Description != '') ? imageInfo.Description : ((imageInfo.ContentName != '') ? imageInfo.ContentName : imageInfo.PartName));
    
    if(canSlide)
    {
        slideCounters[Index] = Order;
        if (images.length > (Order + 1))
            Order++;
        else
            Order = 0;        
        
        slideTimeouts[Index] = setTimeout("ProcessSlide('" + Index + "'," + TimeOut + ",'" + ImageControlId +  "','" + ImageDescriptionControlId + "'," + Order + ")", TimeOut);                
    }
}

function SlideShowPlay(Index, TimeOut, ImageControlId, ImageDescriptionControlId)
{
    clearTimeout(slideTimeouts[Index]);
    slideState[Index] = 1;        
    SetProcessSlide(Index, TimeOut, ImageControlId, ImageDescriptionControlId, slideCounters[Index]); 
}

function SlideShowPause(Index, TimeOut, ImageControlId, ImageDescriptionControlId)
{
    clearTimeout(slideTimeouts[Index]);
    slideState[Index] = 2           
}

function SlideShowNext(Index, TimeOut, ImageControlId, ImageDescriptionControlId)
{
    clearTimeout(slideTimeouts[Index]);   
    SetProcessSlide(Index, TimeOut, ImageControlId, ImageDescriptionControlId, slideCounters[Index] + 1);                
}

function SlideShowPrevious(Index, TimeOut, ImageControlId, ImageDescriptionControlId)
{
    clearTimeout(slideTimeouts[Index]);  
    SetProcessSlide(Index, TimeOut, ImageControlId, ImageDescriptionControlId, slideCounters[Index] - 1);         
}

function SlideShowStop(Index, TimeOut, ImageControlId, ImageDescriptionControlId)
{
    clearTimeout(slideTimeouts[Index]);
    slideState[Index] = 2;      
    SetProcessSlide(Index, TimeOut, ImageControlId, ImageDescriptionControlId, 0);    
}
/*
function CenterDiv(Xwidth,Yheight,divid) 
{ 

    // First, determine how much the visitor has scrolled 
    var scrolledX, scrolledY; 
    if( self.pageYOffset ) { 
    scrolledX = self.pageXOffset; 
    scrolledY = self.pageYOffset; 
    } else if( document.documentElement && document.documentElement.scrollTop ) { 
    scrolledX = document.documentElement.scrollLeft; 
    scrolledY = document.documentElement.scrollTop; 
    } else if( document.body ) { 
    scrolledX = document.body.scrollLeft; 
    scrolledY = document.body.scrollTop; 
    } 

    // Next, determine the coordinates of the center of browser's window 
    var centerX, centerY; 
    if( self.innerHeight ) { 
    centerX = self.innerWidth; 
    centerY = self.innerHeight; 
    } else if( document.documentElement && document.documentElement.clientHeight ) { 
    centerX = document.documentElement.clientWidth; 
    centerY = document.documentElement.clientHeight; 
    } else if( document.body ) { 
    centerX = document.body.clientWidth; 
    centerY = document.body.clientHeight; 
    } 

    // Xwidth is the width of the div, Yheight is the height of the 
    // div passed as arguments to the function: 
    var leftOffset = scrolledX + (centerX - Xwidth) / 2; 
    var topOffset = scrolledY + (centerY - Yheight) / 2; 
    // the initial width and height of the div can be set in the 
    // style sheet with display:none; divid is passed as an argument to // the function 
    var o=document.getElementById(divid); 
    var r=o.style; 
    r.position='absolute'; 
    r.top = topOffset + 'px'; 
    r.left = leftOffset + 'px'; 
    //r.display = "block"; 
} 
*/
