// JavaScript Document
function signup(formName, step)
{
	$('#loader-bg').ajaxStart(function() {
		$('#alert-bg').hide();
		$(this).show();
		$("#right").fadeOut();
	}).ajaxStop(function() {
		$(this).hide();
		$("#right").fadeIn();
	});
	$('#alert-bg').hide();
	var postData = $('#'+formName).serialize();
	$.post('index.php?page=signup&cmd='+step, postData, function(data)
	{
		if(data.length > 70){
			$('#right').html(data);
		}else {
			$('#alert-bg').fadeIn();
			$('#alert-text').html(data);
		}
	});
	return false;
};

function addArticle(formName, step)
{
	$('#loader-bg').ajaxStart(function() {
		$('#alert-bg').hide();
		$(this).show();
		$("#right").fadeOut();
	}).ajaxStop(function() {
		$(this).hide();
		$("#right").fadeIn();
	});
	$('#alert-bg').hide();
	var postData = $('#'+formName).serialize();
	$.post('index.php?section=user&page=addarticle&cmd='+step, postData, function(data)
	{
		if(data.length > 70){
			$('#right').html(data);
		}else {
			$('#alert-bg').fadeIn();
			$('#alert-text').html(data);
		}
	});
	return false;
};

function author(page, formName, id)
{	
	$('#loader-bg').ajaxStart(function() {
		$('#alert-bg').hide();
		$(this).show();
		$("#right").fadeOut();
	}).ajaxStop(function() {
		$(this).hide();
		$("#right").fadeIn();
	});
	$('#alert-bg').hide();
	var postData = $('#'+formName).serialize();
	$.post('index.php?section=user&page=addarticle&cmd='+page+'&id='+id, postData, function(data)
	{
		if(data.length > 70){
			$('#right').html(data);
		}else {
			$('#alert-bg').fadeIn();
			$('#alert-text').html(data);
		}
	});
	return false;
}

function reviewer(page, formName, id)
{
	$('#loader-bg').ajaxStart(function() {
		$('#alert-bg').hide();
		$(this).show();
		$("#right").fadeOut();
	}).ajaxStop(function() {
		$(this).hide();
		$("#right").fadeIn();
	});
	$('#alert-bg').hide();
	var postData = $('#'+formName).serialize();
	$.post('index.php?section=user&page=addarticle&cmd='+page+'&id='+id, postData, function(data)
	{
		if(data.length > 70){
			$('#right').html(data);
		}else {
			$('#alert-bg').fadeIn();
			$('#alert-text').html(data);
		}
	});
	return false;
}

function runPage(section, page, cmd, id, formName)
{
	$('#loader-bg').ajaxStart(function() {
		$('#alert-bg').hide();
		$(this).show();
		$("#right").fadeOut();
	}).ajaxStop(function() {
		$(this).hide();
		$("#right").fadeIn();
	});
	$('#alert-bg').hide();
	var postData = '';
	if(typeof formName == "string") {
		postData = $('#'+formName).serialize();
	}
	$.post('index.php?section='+section+'&page='+page+'&cmd='+cmd+'&id='+id, postData, function(data)
	{
		if(data.length > 70){
			$('#right').html(data);
		}else {
			$('#alert-bg').fadeIn();
			$('#alert-text').html(data);
		}
	});
	return false;
}

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9")) || (i==0 && c==0)) return false;
    }
    // All characters are numbers.
    return true;
}

function showPrice()
{
	var participantTypePrice = 0;
	var hotelPrice = 0;
	var tourPrice = 0;
	var fullPrice = 0;
	var quantity = 1;
	var tempPrice = 0;
	
	if(typeof $("input[name='participanttype']:checked").val() != "undefined") {
		participantTypePrice = parseInt(pTypePrice[$("input[name='participanttype']:checked").val()]);
	}
	/*
	if(typeof $("input[name='hotelprice']:checked").val() != "undefined") {
		hotelPrice = parseInt(hPrice[$("input[name='hotelprice']:checked").val()]);
	}*/
	
	var j=$("input:checkbox", document.forms[0]);
	$.each( j, function(j, v){
	if (v.checked==true) {
		t=v.value;t=t.split("**");
		if (t[0]==3 || t[0]==4) 
		tourPrice += parseInt(t[1]);
		else
	  	hotelPrice += parseInt(t[1]);
	}
     });
	
	var temp=$("#quantity").val();
	if (!isInteger(temp)) {
	alert('Please enter number');
	$("#quantity").val(1);
	}
	else if(temp!='') quantity=parseInt(temp);
	if (temp=='') $("#quantity").val(1);
	if(typeof $("#attachperson").val() != "undefined") {
		fullPrice = parseInt($("#attachperson").text()) * parseInt($("#personcount").text());
	}
	
	tempPrice = fullPrice +hotelPrice;
	//fullPrice += (participantTypePrice + hotelPrice);
	$("#showprice").text(tempPrice);
	fullPrice = (quantity*tempPrice)+tourPrice+participantTypePrice;

	$("#showfullprice").text(fullPrice);
	$("input[name='fullprice']").val(fullPrice);
	setTimeout('showPrice()',100);
}

function WorkshopShowPrice() 
{
	var fullPrice=parseInt(0);var off=parseInt(0);
	var t=parseInt(0);
	
	if(typeof $("input[name='usertype']:checked").val() != "undefined") {
   	 	off=$("input[name='usertype']:checked").val();
		off=off.split("**");off=parseInt(off[0]);
	}
	else off=0;
	
	var j=$("input:checkbox", document.forms[0]);
	$.each( j, function(j, v){
	if (v.checked==true && v.name!='usertype') {
		t=v.value;t=t.split("**");
    	fullPrice+=parseInt(t[0]);
	}
     });
	
   off=(fullPrice*off)/100;
   fullPrice=fullPrice-off;
   $("#showfullprice").text(fullPrice);
   $("input[name='fullprice']").val(fullPrice);
   setTimeout('WorkshopShowPrice()',100);
}

function ajaxFileUpload(adsTypeId)
{
	$("#fileLoading")
	.ajaxStart(function(){
		$("#fileAlert").hide();				
		$(this).show();
	})
	.ajaxComplete(function(){
		$(this).hide();
	});

	$.ajaxFileUpload
	(
		{
			url:'showImage.php?adstype='+adsTypeId ,
			secureuri:false,
			fileElementId:'img',
			dataType: 'script',
			success: function (data, status)
			{
				if(typeof(data.error) != 'undefined')
				{
					if(data.error != '')
					{
						alert(data.error);
					}else
					{
						alert(data.msg);
					}
				}
			},
			error: function (data, status, e)
			{
				alert(e);
			}
		}
	)
	
	return false;

}

function getTypeId()
{
	ajaxFileUpload(adsType);
	$("#fileLoading").hide();
	$("#fileAlert").show();
};

function creatf () {
$("#area").html("<iframe style='display:block' name='uploadarea' id='uploadarea' frameborder='0' src='' ></iframe>");
}

