/** @author - BMSdesign - Bartek Stankowski, copyrights BMSdesign 2009
   *
   *
   * @return unknown
   */



function set_position(objParent, objChild, top, left)
{
	if(!top) top = 30; //30;
	if(!top) left = 10;//10;
	var left_pos, top_pos;

	top_pos = objParent.offsetLeft;
	left_pos = objParent.offsetTop;

	while(objParent.offsetParent)
	{
		left_pos = left_pos + objParent.offsetParent.offsetLeft;
		top_pos = top_pos + objParent.offsetParent.offsetTop;
		if(objParent==document.getElementsByTagName('body')[0])
		{
			break;
		}
		else
		{
			objParent=objParent.offsetParent;
		}
	}
	objChild.style.top = top_pos + top + 'px';
	objChild.style.left = left_pos + left + 'px';
}
function show_navigation(intActual_image, intMax_image)
{
	if(document.getElementById('image').complete){
		if(intActual_image == 0)
		{
			if(intActual_image == intMax_image - 1)
				document.getElementById('next').style.display = 'none';
			else
				document.getElementById('next').style.display = 'block';
			document.getElementById('prev').style.display = 'none';
			document.getElementById('count').style.display = 'block';
		}
		else if(intActual_image > 0 && intActual_image < intMax_image -1)
		{
			document.getElementById('prev').style.display = 'block';
			document.getElementById('next').style.display = 'block';
			document.getElementById('count').style.display = 'block';
		}
		else if(intActual_image == intMax_image - 1)
		{
			document.getElementById('next').style.display = 'none';
			document.getElementById('prev').style.display = 'block';
			document.getElementById('count').style.display = 'block';
		}
		else
		{
			document.getElementById('next').style.display = 'block';
			document.getElementById('prev').style.display = 'block';
			document.getElementById('count').style.display = 'block';
		}
	}
	else
	{
		hide_navigation();

	}
}
function hide_navigation()
{
		document.getElementById('prev').style.display = 'none';
		document.getElementById('next').style.display = 'none';
		document.getElementById('count').style.display = 'none';
}
function navigation_position(intActual_image, intMax_image)
{

	objElement = document.getElementById('image');
	//alert(objElement.height);
	document.getElementById('prev').style.top = objElement.offsetTop + objElement.height - 40 + 'px';
	document.getElementById('prev').style.left = objElement.offsetLeft + 3 +'px';
	document.getElementById('next').style.top = objElement.offsetTop + objElement.height - 40 + 'px';
	document.getElementById('next').style.left = objElement.offsetLeft + objElement.width - 50 + 5 + 'px'; //41 rozmiar next i 5 ramka
	document.getElementById('count').style.top = objElement.offsetTop + 'px';
	//alert(objElement.style.top);
	document.getElementById('count').style.left = objElement.offsetLeft + objElement.width - 100 + 5 + 'px';

	show_navigation(intActual_image, intMax_image);

}
function navigation_position_ie(intActual_image, intMax_image)
{

	objElement = document.getElementById('image');
	//alert(findPos(document.getElementById('image')));
	document.getElementById('count').style.top = findPos(objElement) +'px';
	document.getElementById('count').style.left = findPos(objElement,1) + parseInt(arrImages[intActual_image].width) - 94 +'px';
	document.getElementById('next').style.top = findPos(objElement) + parseInt(arrImages[intActual_image].height) - 50 +'px';
	document.getElementById('next').style.left = findPos(objElement,1) + parseInt(arrImages[intActual_image].width) - 47 +'px';
	document.getElementById('prev').style.top = findPos(objElement) + parseInt(arrImages[intActual_image].height) - 50 +'px';
	document.getElementById('prev').style.left = findPos(objElement,1) +'px';
	//document.getElementById('prev').style.top = 310 + objElement.height - 40 + 'px';
	//document.getElementById('prev').style.left = 269 +'px';
	//document.getElementById('next').style.top = 310 + objElement.height - 40 + 'px';
	//document.getElementById('next').style.left = 269+ objElement.width - 50 + 5 + 'px'; //41 rozmiar next i 5 ramka
	//document.getElementById('count').style.top = 200 +'px';
	//document.getElementById('count').style.left = 269 + objElement.width - 100 + 5 + 'px';

	show_navigation(intActual_image, intMax_image);

}
function navigation_block(intActual_image, intMax_image)
{

	objElement = document.getElementById('image');
	//alert(findPos(document.getElementById('image')));
	//document.getElementById('next_space').style.top = findPos(objElement) +'px';
	//document.getElementById('count').style.left = findPos(objElement,1) + parseInt(arrImages[intActual_image].width) - 94 +'px';
	document.getElementById('next_space').style.width = parseInt(arrImages[intActual_image].width)/2 + 3 +'px';
	document.getElementById('next_space').style.height = parseInt(arrImages[intActual_image].height)+ + 4 +'px';
	document.getElementById('next_space').style.top = findPos(objElement)+'px';
	document.getElementById('next_space').style.left = findPos(objElement,1)+parseInt(arrImages[intActual_image].width)/2+'px';
	document.getElementById('prev_space').style.width = parseInt(arrImages[intActual_image].width)/2 + 3 +'px';
	document.getElementById('prev_space').style.height = parseInt(arrImages[intActual_image].height)+ + 4 +'px';
	document.getElementById('prev_space').style.top = findPos(objElement)+'px';
	document.getElementById('prev_space').style.left = findPos(objElement,1)+'px';

		if(intActual_image == 0)
			{
				if(intActual_image == intMax_image - 1)
					document.getElementById('next_space').style.display = 'none';
				else
					document.getElementById('next_space').style.display = 'block';
				document.getElementById('prev_space').style.display = 'none';
			}
			else if(intActual_image > 0 && intActual_image < intMax_image -1)
			{
				document.getElementById('prev_space').style.display = 'block';
				document.getElementById('next_space').style.display = 'block';
			}
			else if(intActual_image == intMax_image - 1)
			{
				document.getElementById('next_space').style.display = 'none';
				document.getElementById('prev_space').style.display = 'block';
			}
			else
			{
				document.getElementById('next_space').style.display = 'block';
				document.getElementById('prev_space').style.display = 'block';
			}
}
function findPos(obj, left) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
	do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;


		} while (obj = obj.offsetParent);
	if (left == 1)
		return curleft;
	else
		return curtop;
	}
}
function slideshow(intNext_image, intActual_image, intMax_image, browser)
{
	if(intNext_image == 0)
	{
		if(arrImages[parseInt(intActual_image)-1])
		{

			document.getElementById('image').src = arrImages[parseInt(intActual_image)-1].src;
			document.getElementById('image').title = arrImages[parseInt(intActual_image)-1].title;
			document.getElementById('actual').value = parseInt(intActual_image)-1;
			document.getElementById('count').innerHTML = intActual_image + " of " + intMax_image;
			if(browser)
				navigation_position_ie(parseInt(intActual_image)-1, intMax_image, intNext_image);
			else
				navigation_position(parseInt(intActual_image)-1, intMax_image, intNext_image);
			xajax_change_picture_slideshow_menu(arrImages_id[parseInt(intActual_image)-1]);

		}
	}
	else
	{
		if(arrImages[parseInt(intActual_image)+1])
		{

			document.getElementById('image').src = arrImages[parseInt(intActual_image)+1].src;
			document.getElementById('image').title = arrImages[parseInt(intActual_image)+1].title;
			document.getElementById('actual').value = parseInt(intActual_image)+1;
			document.getElementById('count').innerHTML = parseInt(intActual_image)+2 + " of " + intMax_image;
			if(browser)
				navigation_position_ie(parseInt(intActual_image)+1, intMax_image, intNext_image);
			else
				navigation_position(parseInt(intActual_image)+1, intMax_image, intNext_image);
//			xajax_change_picture_slideshow_menu(arrUsers_id[parseInt(intActual_image)+1], arrUsers_login[parseInt(intActual_image)+1]);
			xajax_change_picture_slideshow_menu(arrImages_id[parseInt(intActual_image)+1]);
		}

	}
}

function addNew_select(intNew_item)
{
	if(intNew_item == 1)
	{
		document.getElementById('tr_category_name').style.display= "";
		document.getElementById('tr_category_description').style.display= "";
		document.getElementById('tr_category_select').style.display= "none";
		document.getElementById('tr_image_main').style.display= "none";
		document.getElementById('tr_image_upload').style.display= "none";
	}
	else
	{
		document.getElementById('tr_category_name').style.display= "none";
		document.getElementById('tr_category_description').style.display= "none";
		document.getElementById('tr_category_select').style.display= "";
		document.getElementById('tr_image_main').style.display= "";
		document.getElementById('tr_image_upload').style.display= "";
	}

}

function count_textarea_chars(strSource_text, strRemain_field, intMaximum_characters)
 {
	var strDiv_error_id = 'div_message';
	var strDiv_error_css_class = 'div_error_view';
	var strError_css_class = 'div_error_view';
	var strMessage = 'Error found:<br/> - too many characters in Category description<br/>';
	var intRest =  intMaximum_characters - document.getElementById(strSource_text).value.length;

 	if(document.getElementById(strSource_text).value.length >= intMaximum_characters)
 	{
 		/*document.getElementById(strDiv_error_id).className = strDiv_error_css_class;
    	 document.getElementById(strDiv_error_id).innerHTML = strMessage; */
    	document.getElementById(strRemain_field).value = intMaximum_characters;
    	document.getElementById(strSource_text).value = document.getElementById(strSource_text).value.substring(0, intMaximum_characters);

 	}
 	else
 	{
 		/* document.getElementById(strDiv_error_id).className = '';
 		document.getElementById(strDiv_error_id).innerHTML = ''; */
 		document.getElementById(strRemain_field).value = document.getElementById(strSource_text).value.length;
 	}

 }
function write_comment()
{
	document.getElementById('button_comment_1').className = 'button_comment';
	document.getElementById('button_comment_2').className = 'button_comment';
	document.getElementById('td_comment_add').className = 'td_comment_add';
	document.getElementById('comment_content').className = 'textarea_comment';
	document.getElementById('comment_content').value = '';
}
function cancel_write_comment()
{
	document.getElementById('button_comment_1').className = 'button_comment_sleep';
	document.getElementById('button_comment_2').className = 'button_comment_sleep';
	document.getElementById('td_comment_add').className = 'td_comment_add_sleep';
	document.getElementById('comment_content').className = 'textarea_comment_sleep';
	document.getElementById('comment_content').value = 'Write comment here ...';
}

function display_wait_comment_add_set(){
		document.getElementById('img_loading_add').src = imgLoading.src;
		set_position(document.getElementById('comment_content'), document.getElementById('img_loading_add'), 46, 190)
		document.getElementById('img_loading_add').style.display = 'block';
}
function display_wait_comment_add_remove(){
	document.getElementById('img_loading_add').style.display = 'none';
}
function display_wait_wakespot_filter(){
	document.getElementById('img_loading_wakespots').src = imgLoading.src;
	set_position(document.getElementById('td_wakespot_search'), document.getElementById('img_loading_wakespots'), 40, 380)
	document.getElementById('img_loading_wakespots').style.display = 'block';
}
function display_wait_wakespot_filter_remove(){
document.getElementById('img_loading_wakespots').style.display = 'none';
}
function display_wait_comment_list_set(){
	document.getElementById('img_loading_list').src = imgLoading.src;
	//alert(document.getElementById('img_relative').offsetTop);
	// document.getElementById('img_loading_list').offsetTop = document.getElementById('img_relative').offsetTop + 'px';
	//set_position(document.getElementById('img_relative'), document.getElementById('img_loading_list'), 0, 0);
	//document.getElementById('img_loading_list').style.left = '620px';
	document.getElementById('img_loading_list').style.display = 'block';
}
function display_wait_comment_list_remove(){
document.getElementById('img_loading_list').style.display = 'none';
}
function scroll_up_comment_list(){
	window.scrollTo(0,document.getElementById("comment_block_add_div").offsetTop);
}
function check_selected_rate()
{
var radioGrp = document['forms']['form_rate']['radio_rate'];
for(i=0; i < radioGrp.length; i++){
    if (radioGrp[i].checked == true) {
        return radioValue = radioGrp[i].value;
    }
}
}
function check_wakeSpot(strGlobal_www, intNew_window){
	if(document.getElementById('wakespot').value != 0 && intNew_window == 0)
	{
		window.location = strGlobal_www + 'wakeboard-wakespots/' + document.getElementById('wakespot').value+'-'+document.getElementById('wakespot_name').value;
	}
	else if(document.getElementById('wakespot').value != 0 && intNew_window == 1)
	{
		window.opener.location = strGlobal_www + 'wakeboard-wakespots/' + document.getElementById('wakespot').value+'-'+document.getElementById('wakespot_name').value;
	}
}


function check_code(objForm, objEvent) {
	var code;
	if (window.event) code = window.event.keyCode;
	else if (objEvent) code = objEvent.which;
	else return true;
	if (code == 13){
		objForm.submit();
		return false;
	}
	else
	   return true;
}

function checkOverwrite_picture(objOverwrite_picture_checkbox,  strId_picture_file, strId_picture_title, strId_picture_description){
	if ( objOverwrite_picture_checkbox.checked )
	{
		document.getElementById(strId_picture_file).disabled = false;
		document.getElementById(strId_picture_title).disabled = false;
		document.getElementById(strId_picture_description).disabled = false;
		document.getElementById(strId_picture_file).className = 'txt_file';
		document.getElementById(strId_picture_title).className = 'txt';
		document.getElementById(strId_picture_description).className = 'textarea';
	}
	else
	{
		document.getElementById(strId_picture_file).disabled = true;
		document.getElementById(strId_picture_title).disabled = true;
		document.getElementById(strId_picture_description).disabled = true;
		document.getElementById(strId_picture_file).className = 'txt_file_readonly';
		document.getElementById(strId_picture_title).className = 'txt_readonly';
		document.getElementById(strId_picture_description).className = 'textarea_readonly';
	}
}

function show_answer(strAnswer_td){

	if (document.getElementById(strAnswer_td).style.display == 'none')
	{
		document.getElementById(strAnswer_td).style.display = 'block';
	}
	else
	{
		document.getElementById(strAnswer_td).style.display = 'none';
	}
}

function show_admission_content(strContent_td){

	if (document.getElementById(strContent_td).style.display == 'none')
	{
		document.getElementById(strContent_td).style.display = 'block';
	}
	else
	{
		document.getElementById(strContent_td).style.display = 'none';
	}
}
