﻿// JavaScript Document
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];}}
}

/**
* Default function.  Usually would be overriden by the component
*/
function submitbutton(pressbutton) {
	submitform(pressbutton);
}

/**
* Submit the admin form
*/
function submitform(pressbutton){
	document.adminForm.task.value=pressbutton;

	try {
		if(!control())
			return false;
	}
	catch(e){}
	document.adminForm.submit();
}

var formats = new Array("swf","gif","jpg","png");
function extension_control(el){
	var val = el.value.toLowerCase();
	if((val.length == 0) || !validateFormat(val)){
		alert("Lütfen swf, gif, jpg veya png formatında dosya giriniz !");
		return false;
	}
	if((val.indexOf('.swf') != -1) || (val.indexOf('.jpg') != -1) || (val.indexOf('.gif') != -1) || (val.indexOf('.png') != -1)){
		//alert(val);
		if(val.indexOf('.swf') != -1)
			document.getElementById("view_imagetd").innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" id="obj1" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" border="0" width="120" height="75">' +
																'<param name="movie" value="' + val + '">' + 
																'<param name="quality" value="High">' +
																'<embed src="' + val + '" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="obj1" width="120" height="75"></object>';
		else{
			if(el.name.indexOf("_en") == -1)
				document.view_imagefiles.src = val;
			else
				document.view_imagefiles_en.src = val;	
		}
	}
	return true;
}
function validateFormat(val){
	for (i = 0; i < formats.length; i++)
		if(val.indexOf('.' + formats[i]) != -1)
			return true;
	return false;
}

function listItemTask( id, task ) {
    var f = document.adminForm;
    cb = eval( 'f.' + id );
    if (cb) {
        for (i = 0; true; i++) {
            cbx = eval('f.cb'+i);
            if (!cbx) break;
            cbx.checked = false;
        } // for
        cb.checked = true;
        f.boxchecked.value = 1;
        submitbutton(task);
    }
    return false;
}

function checkAll( n, fldName ) {
  if (!fldName) {
     fldName = 'cb';
  }
	var f = document.adminForm;
	var c = f.toggle.checked;
	var n2 = 0;
	for (i=0; i < n; i++) {
		cb = eval( 'f.' + fldName + '' + i );
		if (cb) {
			cb.checked = c;
			n2++;
		}
	}
	if (c) {
		document.adminForm.boxchecked.value = n2;
	} else {
		document.adminForm.boxchecked.value = 0;
	}
}

function isChecked(isitchecked){
	if (isitchecked == true){
		document.adminForm.boxchecked.value++;
	}
	else {
		document.adminForm.boxchecked.value--;
	}
}

function previewImage( list, image, base_path ) {
	form = document.adminForm;
	srcList = eval( "form." + list );
	srcImage = eval( "document." + image );
	var fileName = srcList.options[srcList.selectedIndex].text;
	var fileName2 = srcList.options[srcList.selectedIndex].value;
	//alert(fileName + ' - ' + fileName2 + ' - ' + base_path);
	if (fileName.length == 0 || fileName2.length == 0) {
		srcImage.src = 'images/admin/blank.png';
	} else {
		srcImage.src = base_path + fileName2;
	}
}

/**
* Adds a select item(s) from one list to another
*/
function addSelectedToList( frmName, srcListName, tgtListName ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );
	var tgtList = eval( 'form.' + tgtListName );

	var srcLen = srcList.length;
	var tgtLen = tgtList.length;
	var tgt = "x";

	//build array of target items
	for (var i=tgtLen-1; i > -1; i--) {
		tgt += "," + tgtList.options[i].value + ","
	}

	//Pull selected resources and add them to list
	//for (var i=srcLen-1; i > -1; i--) {
	for (var i=0; i < srcLen; i++) {
		if (srcList.options[i].selected && tgt.indexOf( "," + srcList.options[i].value + "," ) == -1) {
			opt = new Option( srcList.options[i].text, srcList.options[i].value );
			tgtList.options[tgtList.length] = opt;
		}
	}
}

function delSelectedFromList( frmName, srcListName ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );

	var srcLen = srcList.length;

	for (var i=srcLen-1; i > -1; i--) {
		if (srcList.options[i].selected) {
			srcList.options[i] = null;
		}
	}
}

function getSelectedValue( frmName, srcListName ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );

	i = srcList.selectedIndex;
	if (i != null && i > -1) {
		return srcList.options[i].value;
	} else {
		return null;
	}
}

function setSelectedValue( frmName, srcListName, value ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );

	var srcLen = srcList.length;

	for (var i=0; i < srcLen; i++) {
		srcList.options[i].selected = false;
		if (srcList.options[i].value == value) {
			srcList.options[i].selected = true;
		}
	}
}

// Form specific functions for editting content images

function showImageProps(base_path) {
	form = document.adminForm;
	value = getSelectedValue( 'adminForm', 'imagelist' );
	parts = value.split( '|' );
	form._source.value = parts[0];
	setSelectedValue( 'adminForm', '_align', parts[1] || '' );
	form._alt.value = parts[2] || '';
	form._border.value = parts[3] || '0';
	//form._caption.value = parts[4] || '';
	setSelectedValue( 'adminForm', '_caption_position', parts[4] || '' );
	setSelectedValue( 'adminForm', '_caption_align', parts[5] || '' );
	form._width.value = parts[6] || '';

	//previewImage( 'imagelist', 'view_imagelist', base_path );
	srcImage = eval( "document." + 'view_imagelist' );
	srcImage.src = base_path + parts[0];
}

function moveInList( frmName, srcListName, index, to) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );
	var total = srcList.options.length-1;

	if (index == -1) {
		return false;
	}
	if (to == +1 && index == total) {
		return false;
	}
	if (to == -1 && index == 0) {
		return false;
	}

	var items = new Array;
	var values = new Array;

	for (i=total; i >= 0; i--) {
		items[i] = srcList.options[i].text;
		values[i] = srcList.options[i].value;
	}
	for (i = total; i >= 0; i--) {
		if (index == i) {
			srcList.options[i + to] = new Option(items[i],values[i], 0, 1);
			srcList.options[i] = new Option(items[i+to], values[i+to]);
			i--;
		} else {
			srcList.options[i] = new Option(items[i], values[i]);
	   }
	}
	srcList.focus();
}

/**
* Changes a dynamically generated list
* @param string The name of the list to change
* @param array A javascript array of list options in the form [key,value,text]
* @param string The key to display
* @param string The original key that was selected
* @param string The original item value that was selected
*/
function changeImageFilesList( listname, source, key, orig_key, orig_val ) {
	var list = eval( 'document.adminForm.' + listname );

	// empty the list
	for (i in list.options.length) {
		list.options[i] = null;
	}
	i = 0;
	//alert(key);
	for (x in source) {
		if (source[x][0] == key) {
			opt = new Option();
			opt.value = source[x][1];
			opt.text = source[x][2];

			if ((orig_key == key && orig_val == opt.value) || i == 0) {
				opt.selected = true;
			}
			list.options[i++] = opt;
		}
	}
	list.length = i;
}

function applyImageProps() {
	form = document.adminForm;
	if (!getSelectedValue( 'adminForm', 'imagelist' )) {
		alert( "Select and image from the list" );
		return;
	}
	value = form._source.value + '|'
	+ getSelectedValue( 'adminForm', '_align' ) + '|'
	+ form._alt.value + '|'
	+ parseInt( form._border.value ) + '|'
	//+ form._caption.value + '|'
	+ getSelectedValue( 'adminForm', '_caption_position' ) + '|'
	+ getSelectedValue( 'adminForm', '_caption_align' ) + '|'
	+ form._width.value;
	//alert(value);
	changeSelectedValue( 'adminForm', 'imagelist', value );
}

function changeSelectedValue( frmName, srcListName, value ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );

	i = srcList.selectedIndex;
	if (i != null && i > -1) {
		srcList.options[i].value = value;
		return true;
	} else {
		return false;
	}
}

// JS Calendar
var calendar = null; // remember the calendar object so that we reuse
// it and avoid creating another

// This function gets called when an end-user clicks on some date
function selected(cal, date) {
	cal.sel.value = date; // just update the value of the input field
}

// And this gets called when the end-user clicks on the _selected_ date,
// or clicks the "Close" (X) button.  It just hides the calendar without
// destroying it.
function closeHandler(cal) {
	cal.hide();			// hide the calendar

	// don't check mousedown on document anymore (used to be able to hide the
	// calendar when someone clicks outside it, see the showCalendar function).
	Calendar.removeEvent(document, "mousedown", checkCalendar);
}

// This gets called when the user presses a mouse button anywhere in the
// document, if the calendar is shown.  If the click was outside the open
// calendar this function closes it.
function checkCalendar(ev) {
	var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);
	for (; el != null; el = el.parentNode)
	// FIXME: allow end-user to click some link without closing the
	// calendar.  Good to see real-time stylesheet change :)
	if (el == calendar.element || el.tagName == "A") break;
	if (el == null) {
		// calls closeHandler which should hide the calendar.
		calendar.callCloseHandler(); Calendar.stopEvent(ev);
	}
}

// This function shows the calendar under the element having the given id.
// It takes care of catching "mousedown" signals on document and hiding the
// calendar if the click was outside.
function showCalendar(id) {
	var el = document.getElementById(id);
	if (calendar != null) {
		// we already have one created, so just update it.
		calendar.hide();		// hide the existing calendar
		calendar.parseDate(el.value); // set it to a new date
	} else {
		// first-time call, create the calendar
		var cal = new Calendar(true, null, selected, closeHandler);
		calendar = cal;		// remember the calendar in the global
		cal.setRange(1900, 2070);	// min/max year allowed
		calendar.create();		// create a popup calendar
		calendar.parseDate(el.value); // set it to a new date
	}
	calendar.sel = el;		// inform it about the input field in use
	calendar.showAtElement(el);	// show the calendar next to the input field

	// catch mousedown on the document
	Calendar.addEvent(document, "mousedown", checkCalendar);
	return false;
}

//****************************************************************************************************************
//PENCERELERI SAYFANIN TAM ORTASINDA AÇTIRIR. BUYUKLUKLER STANDARTIZE EDILIYOR
//****************************************************************************************************************
function windowopen(theURL,winSize) {
  if (winSize == "normal") 	    { myWidth=400 ; myHeight=300 ; features = "scrollbars=1, resizable=1" ; }
  if (winSize == "minimal") 	{ myWidth=600 ; myHeight=300 ; features = "scrollbars=1, resizable=1" ; }
  if (winSize == "maximum") 	{ myWidth=900 ; myHeight=500 ; features = "scrollbars=1, resizable=1" ; }
  if (winSize == "form") 	    { myWidth=800 ; myHeight=450 ; features = "scrollbars=1, resizable=1" ; }
  if (winSize == "myhome") 		{ myWidth=500 ; myHeight=400 ; features = "scrollbars=1, resizable=1" ; }
  if (winSize == "detail") 		{ myWidth=500 ; myHeight=470 ; features = "scrollbars=1, resizable=1" ; }
  if (winSize == "liststyle") 	{ myWidth=600 ; myHeight=400 ; features = "scrollbars=1, resizable=1" ; }
  if (winSize == "datestyle") 	{ myWidth=300 ; myHeight=250 ; features = "scrollbars=1, resizable=1" ; }
  if (winSize == "pagestyle") 	{ myWidth=700 ; myHeight=500 ; features = "scrollbars=1, resizable=1" ; }
  if (winSize == 'small') 		{ myWidth=500 ; myHeight=330 ; features = 'scrollbars=1, resizable=1, menubar=1' ; }
  if (winSize == "mini") 		{ myWidth=300 ; myHeight=40 ; features = "scrollbars=1, resizable=1"; }
  if (winSize == "gorev") 		{ myWidth=350 ; myHeight=400 ; features = "scrollbars=1, resizable=1"; }
  if (winSize == "tutanak") 	{ myWidth=500 ; myHeight=300 ; features = "scrollbars=1, resizable=1"; }
  if (winSize == "normal2") 	{ myWidth=500 ; myHeight=250 ; features = "scrollbars=1, resizable=1"; }
  if (winSize == "longstyle") 	{ myWidth=850 ; myHeight=300 ; features = "scrollbars=1, resizable=1" ; }
  if (winSize == "companystyle") { myWidth=580 ; myHeight=700 ; features = "scrollbars=1, resizable=1" ; }
  if(window.screen)
  {
    var myLeft = (screen.width-myWidth)/2;
    var myTop = (screen.height-myHeight)/2;
  features+=(features!='')?',':''; 
  features+=',left='+myLeft+',top='+myTop; 
  }
  window.open(theURL,'',features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}

function gizleGoster(id){
	var obj = document.getElementById(id);
	if(obj.style.visibility == '')
		obj.style.visibility = 'hidden';
	else
		obj.style.visibility = '';
}

function openPopWin(url, name, width, height) 
  {
    var bg = window.open(url,name,"dependent,width=" + width + ",height=" + height + ",left=100,top=50,resizable=no,scrollbars=yes"); 
    if (bg && bg.focus) bg.focus();
  }