/*------------------------------------------------------------------------
# JA Voice - Version 1.3.0 - Licence Owner JA557.4202154236
# ------------------------------------------------------------------------
# Copyright (C) 2004-2008 J.O.O.M Solutions Co., Ltd. All Rights Reserved.
# @license - Copyrighted Commercial Software
# Author: J.O.O.M Solutions Co., Ltd
# Websites:  http://www.joomlart.com -  http://www.joomlancers.com
# This file may not be redistributed in whole or significant part.
-------------------------------------------------------------------------*/
// JavaScript Document
// Must re-initialize window position
function jaCreatForm(jatask, cid, jaWidth, jaHeight, title,
		dsave,titlesave,location) {	
	jav_displayLoadingSpan();
	if (!cid)
		cid = 0;
	if (!jaWidth)
		jaWidth = 700;
	if (!jaHeight)
		jaHeight = 500;
	if(!titlesave)titlesave="Kaydet";
	var Obj = document.getElementById('jaForm');
	if (!Obj) {
		var content = jQuery('<div>').attr( {
			'id' :'ja-wrap-content'
		}).appendTo(document.body);
		
		var jaForm = jQuery('<div>').attr( {
			'id' :'jaForm',
			'style' :'top: 0px;display:none;'
		});
		
		jaForm.appendTo(content);
		jQuery('<div>').attr( {
			'id' :'javoice_tl'
		}).appendTo(jaForm);
		jQuery('<div>').attr( {
			'id' :'javoice_tm'
		}).appendTo(jaForm);
		jQuery('<div>').attr( {
			'id' :'javoice_tr'
		}).appendTo(jaForm);
		jQuery('<a>').attr( {
			'id' :'javoice_ar',
			'href' :'javascript:void(0);',
			'onclick' :'jaFormHide();'
		}).appendTo(jQuery('#javoice_tr'));
		jQuery("#javoice_ar").click( function() { jaFormHide(); } );
		jQuery('<div>').attr( {
			'style' :'clear:both'
		}).appendTo(jaForm);
		jQuery('<div>').attr( {
			'id' :'javoice_ml'
		}).appendTo(jaForm);
		jQuery('<div>').attr( {
			'id' :'jaFormContentOuter'
		}).appendTo(jaForm);
		if (title) {
			jQuery('<div>').attr( {
				'id' :'jaFormContentTop',
				'style' :'font-weight: bold;font-size:10pt;'
			}).appendTo(jQuery('#jaFormContentOuter'));

			jQuery('#jaFormContentTop').html(title);
		}
		jQuery('<div>').attr( {
			'id' :'jaFormContent',
			'style' :'position:relative;jaFormContent;overflow:scroll',
			'class' :''
		}).appendTo(jQuery('#jaFormContentOuter'));
		jQuery('<div>').attr( {
			'id' :'jaFormContentBottom',
			'style':'bottom:0px;',
			'style' :'font-weight: bold;font-size:10pt;'
		}).appendTo(jQuery('#jaFormContentOuter'));		
		if (!dsave) {
			jQuery('<button>').attr( {
				'id' :'javoice_as',
				'style':'width:60px;'
			}).html(titlesave).appendTo(jQuery('#jaFormContentBottom'));		
			jQuery("#javoice_as").click( function() { jav_submitbutton(); } );
		}	
		jQuery('<button>').attr( {
			'id' :'javoice_ac',
			'style':'width:60px;'
		}).html('Vazgec').appendTo(jQuery('#jaFormContentBottom'));	
		jQuery("#javoice_ac").click( function() { jaFormHide(); } );
		
		jQuery('<div>').attr( {
			'id' :'javoice_bl'
		}).appendTo(jaForm);
		jQuery('<div>').attr( {
			'id' :'javoice_bm'
		}).appendTo(jaForm);
		jQuery('<div>').attr( {
			'id' :'javoice_br'
		}).appendTo(jaForm);			
		jQuery('<div>').attr( {
			'style' :'clear: both;'
		}).appendTo(jaForm);
	}
	// Set jaFormWidth + 40
	jQuery('#jaForm').width(jaWidth);

	jQuery('#jaFormContentOuter').width(jaWidth);
	jQuery('#jaFormContentBottom').width(jaWidth);
	jQuery('#jaFormContent').width(jaWidth);

	jQuery('#javoice_bm').width(jaWidth);
	jQuery('#javoice_tm').width(jaWidth);
	var myWidth = 0, myHeight = 0;

	myWidth = jQuery(window).width();
	myHeight = jQuery(window).height();

	var yPos;

	if (jQuery.browser.opera && jQuery.browser.version > "9.5"
			&& jQuery.fn.jquery <= "1.2.6") {
		yPos = document.documentElement['clientHeight'] - 20;
	} else {
		yPos = jQuery(window).height() - 20;
	}

	var leftPos = (myWidth - jaWidth) / 2;

	jQuery('#jaForm').css('zIndex', cGetZIndexMax() + 1);

	/*
	 * jQuery.ajax({ url: jatask, cache: false, success: function(html){
	 * jQuery("#jaFormContent").append(html); } });
	 */
	jatask = encodeURIComponent(jatask);
	var url = siteurl + "&task=" + jatask + "&cid[]=" + cid;
	var forum_id = jQuery('#jav-forum-select').attr('value');
	if(forum_id>0)url +="&forum_id="+forum_id;
	
	new Ajax(url, {method: 'get', onComplete: function (text){
		$('jaFormContent').innerHTML = text;
		jQuery(document).ready( function($) {
			if($('#loader')) {
				id='#'+jav_header;
				$(id).css('z-index','10');			
				$('#loader').hide();
			}			
			$('li').click( function() {
				var active = $$('li');
				for ( var i = 0; i < active.length; i++) {
					active[i].removeClass('focused');
				}
				this.addClass('focused');
			});
		});		
	}}).request();

	ajax_loaded = true;

	jQuery("#jaForm").css('marginTop', '5px');

	/*
	 * Set height and width for transparent window
	 */
	if (title)
		jQuery('#jaFormContentTop').width(jaWidth-20);	
	jQuery('#jaForm').css('height', jaHeight);
	jQuery('#jaForm').css('left', leftPos);
	jQuery('#jaFormContent').css('height', (jaHeight-40)); // - 30px title and 20px
														// border
	jQuery('#jaFormContent').css('width', (jaWidth)); // -20px border
	jQuery('#jaFormContentOuter').css('height', jaHeight);
	jQuery('#javoice_ml').css('height', jaHeight);
	jQuery('#javoice_mr').css('height', jaHeight);
	jQuery('#javoice_as').css('display','block');
	jQuery('#javoice_ac').css('display','block');	
	jQuery('#jaFormContentBottom').animate( {
		bottom :"0px",
		left:"0px",
		height :"30px"
	}, 200);
	jQuery('#jaForm').fadeIn();

}

function jaFormHide() {
	if (jQuery('#jaFormAction').get().length > 0)
		jQuery('#jaFormAction').animate( {
			bottom :"-40px"
		}, 200, '', function() {
			jQuery('#jaForm').fadeOut('fast', function() {
				jQuery(this).remove();
				jQuery('#ja-wrap-content').remove();
			});
		});
	else {

		jQuery('#jaForm').fadeOut('fast', function() {
			jQuery(this).remove();
			jQuery('#ja-wrap-content').remove();
		});
	}
}

function jaFormActions(action) {

	jQuery('#jav-form-wait').show();
	jQuery('#jaFormContent input').attr('disabled', true);
	jQuery('#jaFormContent textarea').attr('disabled', true);
	jQuery('#jaFormContent button').attr('disabled', true);

}

function jaFormResize(newheight) {
	jQuery("#jaFormContentOuter").animate( {
		"left" :"+=50px"
	}, "slow");

	jQuery("#jaFormContent").animate( {
		"left" :"+=50px"
	}, "slow");
	jQuery("#iContent").animate( {
		"left" :"+=50px"
	}, "slow");

}

function cGetZIndexMax() {
	var allElems = document.getElementsByTagName ? document
			.getElementsByTagName("*") : document.all; // or test for that too
	var maxZIndex = 0;

	for ( var i = 0; i < allElems.length; i++) {
		var elem = allElems[i];
		var cStyle = null;
		if (elem.currentStyle) {
			cStyle = elem.currentStyle;
		} else if (document.defaultView
				&& document.defaultView.getComputedStyle) {
			cStyle = document.defaultView.getComputedStyle(elem, "");
		}

		var sNum;
		if (cStyle) {
			sNum = Number(cStyle.zIndex);
		} else {
			sNum = Number(elem.style.zIndex);
		}
		if (!isNaN(sNum)) {
			maxZIndex = Math.max(maxZIndex, sNum);
		}
	}
	return maxZIndex;
}

