var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

function close_tab(tab_name) {
    jQuery('#'+tab_name).hide("slow");
}
function open_tab(tab_name) {    
    jQuery('#'+tab_name).show("slow");
}
function toggle_tab(tab_name) {
	jQuery('#'+tab_name).toggle("slow");
}
function check_tab(tab_name) {
	if (document.getElementById(tab_name).style.display == 'none') {
		open_tab(tab_name);
	} else {
		close_tab(tab_name);
	}
}

function blockButton(name) {
	if (document.getElementById(name)) {
		document.getElementById(name).style.display = 'none';
	}	
}

function editRequestPayment(name) {
	if (document.getElementById(name).disabled) {
		document.getElementById(name).disabled = false;
		open_tab('form_'+name);
		close_tab('text_'+name);
	} else {
		document.getElementById(name).disabled = true;
		close_tab('form_'+name);
		open_tab('text_'+name);
	}
}

function open_banner(afiliate_id) {
	for (var i = 1; i <= 7; i++) {
		if (afiliate_id == i) {
			open_tab('banner_'+i);
		} else {
			close_tab('banner_'+i);
		}
	} 
}

function SendMessage() {
	toggle_tab('SendMessage');
}

function ActionSendMessage() {
	var error = new Boolean();
	error = false;
	var user_email = document.getElementById('user_email').value;
	var user_name = document.getElementById('user_name').value;
	var user_message = document.getElementById('user_message').value;
	var action_message = document.getElementById('action_message').value;
	var page_message = document.getElementById('page_message').value;
	var message_user_id = document.getElementById('message_user_id').value;
	if (user_email == '') error = true;
	if (user_name == '') error = true;
	if (user_message == '') error = true;
	
	if (error) {
		alert ("Error\nNot all the files filled.");
	} else {
		toggle_tab('SendMessage');
		AjaxSendMessage(user_email,user_name,user_message,action_message,page_message,message_user_id);
	}
}

function go_to_link (newlink) {
	location = newlink;
}

function changeCategory (categoryName) {
	var subcategoryId = document.getElementById('filter_category').value;
	for(i = document.getElementById('filter_category').options.length-1; i > 0; i--) {
		if (document.getElementById('filter_category').options[i].value == subcategoryId) {
			var subcategoryText = document.getElementById('filter_category').options[i].text;
		}
	} 	
	if (subcategoryId == 0) {
		newlink = '/'+categoryName+'.html';
	} else {
		newlink = '/'+subcategoryText.replace(/ /g,'-')+'/'+categoryName+'-Category'+subcategoryId+'.html';
	}
	go_to_link (newlink);
}

function check_password (tab_name) {
	if (document.getElementById('password_tab_check').style.display == 'block') {
		close_tab('password_tab_check');
	}
	if (document.getElementById(tab_name).style.display == 'none') {
		document.getElementById('edit_password').value = '';
		document.getElementById('edit_password').disabled = false;
		document.getElementById('edit_confirm_password').value = '';
		document.getElementById('edit_confirm_password').disabled = false;
		open_tab(tab_name);
	} else {
		document.getElementById('edit_password').value = '';
		document.getElementById('edit_password').disabled = true;
		document.getElementById('edit_confirm_password').value = '';
		document.getElementById('edit_confirm_password').disabled = true;
		close_tab(tab_name);
	}
}

function checkUploadFile() {
	error = false;
	if ((document.getElementById('approved_images_th_hidden').value == '') || (document.getElementById('approved_preview_source_hidden').value == '') || (document.getElementById('approved_preview_source_swf_hidden').value == '') || (document.getElementById('approved_source_files_hidden').value == ''))
	error = true;
	if (document.getElementById('preview_at_fullscreen').checked && document.getElementById('approved_preview_files_hidden').value == '') 
	error = true;
	
	if (error) { 
		returnValue = false;
		alert ("Error\nNot all the files filled.");
	} else 
		returnValue = true;
}

function changePreviewFlash() {
	if (document.getElementById('preview_at_fullscreen').checked) {
		//open_tab('block_is_checked_full_screen');
		close_tab('block_is_not_full_screen');
	} else {
		//close_tab('block_is_checked_full_screen');
		open_tab('block_is_not_full_screen');
	}
}

function forgotPassword() {
	toggle_tab('forgot_name_form');
}
function forgotUserName() {
	toggle_tab('forgot_pass_form');
}

var W3CDOM = (document.createElement && document.getElementsByTagName);

function initFileUploads() {
	if (!W3CDOM) return;
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'fakefile';
	fakeFileUpload.appendChild(document.createElement('input'));
	var image = document.createElement('img');
	image.src='pix/button_select.gif';
	fakeFileUpload.appendChild(image);
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		if (x[i].parentNode.className != 'fileinputs') continue;
		x[i].className = 'file hidden';
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
		}
	}
}


function AjaxSendMessage(user_email,user_name,user_message,action_message,page_message,message_user_id) {
	user_email = user_email.replace(/'/,"\'");
	user_name = user_name.replace(/'/,"\'");
	user_message = user_message.replace(/'/,"\'");	
	var url =       '/index.html';
	var params =    'user_email='+user_email+'&user_name='+user_name+'&user_message='+user_message+'&page='+page_message+'&action='+action_message+'&user_id='+message_user_id;	
	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(params);
	xmlhttp.onreadystatechange = function() {//Call a function when the state changes.
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			document.getElementById('body_page').innerHTML = xmlhttp.responseText + document.getElementById('body_page').innerHTML;
			open_tab('resultMessage');
		}
	}
}

function DeleteComment(BlogId, CommentId) {
	var url =       '/index.html';
	var params =    'deletePost=1&action=action&page=comment&commentId='+CommentId+'&blogId='+BlogId+'&ajax=1';
	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(params);
	xmlhttp.onreadystatechange = function() {//Call a function when the state changes.
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var text = xmlhttp.responseText;
			if (text.indexOf("class='good'") != -1) {
				document.getElementById('commentId'+CommentId).innerHTML = text;
			} else {
				document.getElementById('commentId'+CommentId).innerHTML = text+document.getElementById('commentId'+CommentId).innerHTML;
			}
		}
	}
}