function popupFrame(vw, vh)
{
	$.nyroModalManual({
      url: 'popupFrame.php',
	  width: vw,
	  height: vh,
	  resizable: false,
	  closeButton: false,
	  modal: true
    });
	return false;
}

function popupFrameSwf(vw, vh, swf)
{
	$.nyroModalManual({
      url: swf,
	  width: vw,
	  height: vh,
	  resizable: false,
	  closeButton: false,
	  modal: true,
	  swf: {
		wmode: 'window',
		height: vh,
		width: vw
	  }
    });
	return false;
}

function read_me(id)
{
	popupFrame(600, 600);
	setTimeout(function(){
		var ud=new Date();
		var mt=ud.getTime();
		var link='ajax/sms.php?req=create&num_id='+id+'&mt='+mt;
		$.get(link, function(data){
			$("#popup_content").html(data);
			$("#popup_content").show("slow");
		});
	}, 1000);
}

function share_read_me(id)
{
	popupFrame(600, 600);
	setTimeout(function(){
		var ud=new Date();
		var mt=ud.getTime();
		var link='ajax/sms.php?req=share_read&num_id='+id+'&mt='+mt;
		$.get(link, function(data){
			$("#popup_content").html(data);
			$("#popup_content").show("slow");
		});
	}, 1000);
}

function checkSharePay(){
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/sms.php?req=checkSharePay&mt='+mt;
	$.get(link);
}

function read_me_advanced(id)
{
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/sms.php?req=create&num_id='+id+'&mt='+mt;
	$.get(link, function(data){
		$("#popup_content").html(data);
		$("#popup_content").show("slow");
	});
}


function prevm_sms()
{
	popupFrame(600, 600);
	setTimeout(function(){
		var ud=new Date();
		var mt=ud.getTime();
		var link='ajax/sms.php?req=prevm_sms&mt='+mt;
		$.get(link, function(data){
			$("#popup_content").html(data);
			$("#popup_content").show("slow");
		});
	}, 1000);
}

function choose_number()
{
	$("#error_place").html("");
	$("#error_place").show();
	var ecode=$("#acc_code").val();
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/inside.php?req=check_prevm_code&code='+ecode+'&mt='+mt;
	$.get(link, function(data){
		var errors=parseInt(data);
		if(errors)
		{	
			wrong_code_old_numbers(errors);
		} else
		{
			close_sms();
			setTimeout(function(){
				popupFrame(700, 600);
			}, 1000);
			setTimeout(function(){
				var ud=new Date();
				var mt=ud.getTime();
				var link='ajax/inside.php?req=old_numbers_list&mt='+mt;
				$.get(link, function(data){
					$("#popup_content").html(data);
					$("#popup_content").show("slow");
				});
			}, 1000);
		}
	});
}

function wrong_code_old_numbers(error)
{
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/inside.php?req=wrong_code_old_numbers&error='+error+'&mt='+mt;
	$.get(link, function(data){
		$("#error_place").html(data);
		$("#error_place").show("slow");
	});
}

function read_this(id)
{
	close_sms();
	page_layout("inside");
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/inside.php?req=read_this&id='+id+'&mt='+mt;
	$.get(link, function(data){
		$("#script_container").html(data);
		$("#script_container").show("slow");
	});
}

function about_partners()
{
	popupFrame(600, 600);
	setTimeout(function(){
		var ud=new Date();
		var mt=ud.getTime();
		var link='ajax/inside.php?req=about_partners&mt='+mt;
		$.get(link, function(data){
			$("#popup_content").html(data);
			$("#popup_content").show("slow");
		});
	}, 1000);
}

function about_minutes()
{
	popupFrame(600, 600);
	setTimeout(function(){
		var ud=new Date();
		var mt=ud.getTime();
		var link='ajax/inside.php?req=about_minutes&mt='+mt;
		$.get(link, function(data){
			$("#popup_content").html(data);
			$("#popup_content").show("slow");
		});
	}, 1000);
}

function about_nepratigie()
{
	popupFrame(600, 600);
	setTimeout(function(){
		var ud=new Date();
		var mt=ud.getTime();
		var link='ajax/inside.php?req=about_nepratigie&mt='+mt;
		$.get(link, function(data){
			$("#popup_content").html(data);
			$("#popup_content").show("slow");
		});
	}, 1000);
}

function about_download()
{
	popupFrame(600, 600);
	setTimeout(function(){
		var ud=new Date();
		var mt=ud.getTime();
		var link='ajax/inside.php?req=about_download&mt='+mt;
		$.get(link, function(data){
			$("#popup_content").html(data);
			$("#popup_content").show("slow");
		});
	}, 1000);
}

function close_sms()
{
	close_popup();
}

function close_popup()
{
	$("#popup_content").html("");
	$("#popup_content").hide("slow");
	unload_nyroModal();
}

function unload_nyroModal()
{
	$.nyroModalRemove();
}

function enter_pratigie()
{
	var ecode=$("#acc_code").val();
	close_sms();
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/inside.php?req=enter&code='+ecode+'&mt='+mt;
	$.get(link, function(data){
		$("#script_container").html(data);
		$("#script_container").show("slow");
	});
}

function sample_read()
{
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/inside.php?req=sample_read&mt='+mt;
	$.get(link, function(data){
		$("#script_container").html(data);
		$("#script_container").show("slow");
	});
}

function advanced_sample_read()
{
	close_sms();
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/inside.php?req=sample_read&mt='+mt;
	$.get(link, function(data){
		$("#script_container").html(data);
		$("#script_container").show("slow");
	});
}

function happy_15_minutes()
{
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/inside.php?req=happy_15_minutes&mt='+mt;
	$.get(link, function(data){
		$("#script_container").html(data);
		$("#script_container").show("slow");
	});
}

function returnToIndex(timeout)
{
	setTimeout(function(){window.location='index.php'}, timeout);
}

function kill_session()
{
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/inside.php?req=kill_session&mt='+mt;
	$.get(link);
}

function already_in()
{
	$("#script_container").html("");
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/inside.php?req=restore_after_refresh&mt='+mt;
	$.get(link, function(data){
		$("#script_container").html(data);
		$("#script_container").show();
	});
}

function get_downloads(rq)
{
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/inside.php?req=get_downloads&crk='+rq+'&mt='+mt;
	$.get(link, function(data){
		$("#image_content").html("");
		$("#image_content").show();
		$("#image_content").html(data);
		$("#image_content").show("slow");
	});
	scroll(0,0);
}

function download_action(rq)
{
	var download_id=0;
	download_id=$('#downform input:radio:checked').val();
	var mail=$("#cright_mail").val();
	popupFrame(300, 300);
	setTimeout(function(){
		var ud=new Date();
		var mt=ud.getTime();
		var link='ajax/inside.php?req=download&id='+download_id+'&mail='+mail+'&crk='+rq+'&mt='+mt;
		$.get(link, function(data){
			if(data.length && data!='error')
			{
				//window.open("content/mp3/"+data+".mp3");
				//location.href="content/mp3/"+data+".mp3";
				$("#popup_content").html(data);
				$("#popup_content").show();

			} else
			{
				close_sms();
			}
		});
	}, 1000);
	already_in();
}

function get_picture(rq)
{
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/image.php?req='+rq+'&sreq=i&mt='+mt;
	$.get(link, function(data){
		$("#image_content").html("");
		$("#image_content").show();
		$("#image_content").html(data);
		$("#image_content").show("slow");
	});
}

function get_preloaded_picture(img_nr)
{
	var image_html="<div style='text-align: center;'><div style='background: url("+ci[img_nr-1]+"); background-repeat: no-repeat; height: 480px; width: 990px; margin-left: auto; margin-right: auto; background-position: center center;'><img src='img/transparent.png' width='990px' height='480px' /></div></div>";
	alert(image_html);
	$("#image_content").html(image_html);
	$("#image_content").show();
}

function get_navigation(rq)
{
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/image.php?req='+rq+'&sreq=nb&mt='+mt;
	$.get(link, function(data){
		$("#navigation_buttons").html("");
		$("#navigation_buttons").show();
		$("#navigation_buttons").html(data);
		$("#naviagtion_buttons").show("slow");
	});
}

function navigation(actual_page, page_count)
{

}

function get_thumbnails(rq)
{
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/image.php?req='+rq+'&sreq=t&mt='+mt;
	$.get(link, function(data){
		$("#extend_content").html("");
		$("#extend_content").show();
		$("#extend_content").html(data);
		$("#extend_content").show("slow");
	});
}

function refresh_thumbnails(old_active, new_active)
{
	document.getElementById("th_"+old_active).className='inactive';
	document.getElementById("th_"+new_active).className='active';
}

function rc_disabled()
{
	popupFrame(300, 300);
	setTimeout(function(){
		$("#popup_content").html("<div style='text-align: center;' class='code_error'>Prātīgajiem nepatīk labais taustiņš, neizmanto to šeit! Uzgaidi brītiņu un varēsi turpināt!</div>");
		$("#popup_content").show("slow");
	}, 1000);
	setTimeout(function(){close_popup()}, 15000);
}

function clickIE4(){
	if (event.button==2){
		rc_disabled();
		return false;
	}
}

function clickNS4(e){
	if (document.layers||document.getElementById&&!document.all){
		if (e.which==2||e.which==3){
			rc_disabled();
			return false;
		}
	}
}

function loader()
{
	popupFrameSwf(300, 40, 'swf/loader.swf');
}

function remove_loader()
{
	unload_nyroModal();
}

function change_picture(picture_nr)
{
	//loader();
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/inside.php?req=change_picture&pnr='+picture_nr+'&mt='+mt;
	$.get(link, function(data){
		$("#script_container").html("");
		$("#script_container").html(data);
		$("#script_container").show("slow");
	});
}

function go_away()
{
	//loader();
	$("#middle_part").html("");
	$("#navigation_buttons").html("");
	$("#extend_content").html("");
	$("#image_content").html("");
	$("#middle_part").show("slow");
	$("#navigation_buttons").show("slow");
	$("#extend_content").show("slow");
	$("#image_content").show("slow");
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/inside.php?req=go_away&mt='+mt;
	$.get(link, function(data){
		$("#image_content").html(data);
		$("#image_content").show("slow");
	});
}

function accept_away()
{
	//loader();
	$("#away").html("");
	$("#away").show("slow");
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/inside.php?req=accept_away&mt='+mt;
	$.get(link);
	page_layout("away");
	already_away();
}

function already_away()
{
	setTimeout(function(){
		var ud=new Date();
		var mt=ud.getTime();
		var link='ajax/inside.php?req=away_top&mt='+mt;
		$.get(link, function(data){
			$("#image_content").html(data);
			$("#image_content").show("slow");
		});
		var ud=new Date();
		var mt=ud.getTime();
		var link='ajax/inside.php?req=away_choose&mt='+mt;
		$.get(link, function(data){
			$("#extend_content").html(data);
			$("#extend_content").show("slow");
		});
	}, 2000);
}

function tell_text()
{
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/inside.php?req=tell_text&mt='+mt;
	$.get(link, function(data){
		$("#tell").html(data);
		$("#tell").show("slow");
	});
}

function page_layout(type)
{
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/inside.php?req=page_layout&type='+type+'&mt='+mt;
	$.get(link, function(data){
		$("#page_layout").html(data);
		$("#page_layout").show("slow");
	});
}

function comments(page)
{
	$("#image_content").html("");
	$("#image_content").show("small");
	$("#tell").html("");
	$("#tell").show("small");
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/inside.php?req=comments&page='+page+'&mt='+mt;
	$.get(link, function(data){
		$("#free_space").html(data);
		$("#free_space").show("slow");
	});
}

function write_us()
{
	$("#image_content").html("");
	$("#image_content").show("small");
	$("#tell").html("");
	$("#tell").show("small");
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/inside.php?req=writeus&mt='+mt;
	$.get(link, function(data){
		$("#free_space").html(data);
		$("#free_space").show("slow");
	});
}

function tell_friends()
{
	$("#image_content").html("");
	$("#image_content").show("small");
	$("#tell").html("");
	$("#tell").show("small");
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/inside.php?req=tellfriends&mt='+mt;
	$.get(link, function(data){
		$("#free_space").html(data);
		$("#free_space").show("slow");
	});
}

function req_sec_code()
{
	var ut=new Date();
	var mt=ut.getTime();
	var link="ajax/inside.php?req=sec_code&mt="+mt;
	$.get(link, function(data){
		$("#seccode").html(data);
		$("#seccode").show();
	});
}

function add_fmail(id)
{
	var new_fmail="<div><input type='text' name='friendmail["+id+"]' id='friendmail_"+id+"' value='Drauga e-pasts' onFocus=\"javascript: if(this.value=='Drauga e-pasts'){this.value=''; this.style.color='#000';}\" style='color: #cfcfcf; font-weight: bold; font-family: verdana; font-size: 9pt;' /></div>";
	$("#fmails_div").append(new_fmail);
}

function check_seccode(field, form)
{
	var status=0;
	var code=$('#'+field).val();
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/inside.php?req=check_sec_code&code='+code+'&mt='+mt;
	$.get(link, function(data){
		var errors=parseInt(data);
		if(errors)
		{
			code_wrong();
			$("#"+field).val('');
			req_sec_code();
		} else
		{
			$("#"+form).submit();
		}
	});
}

function code_wrong()
{
	popupFrame(400, 125);
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/inside.php?req=code_wrong&mt='+mt;
	$.get(link, function(data){
		$("#popup_content").html(data);
		$("#popup_content").show("slow");
	});
}

function try_send_writeus(sec_field)
{
	check_seccode(sec_field, "writeus_form");
}

function try_send_tellfriends(sec_field)
{
	check_seccode(sec_field, "tellfriends_form");
}

function try_add(sec_field)
{
	var cname=$("#cname").val();
	var ctext=$("#ctext").val();
	if(cname.length && ctext.length)
	{
		check_seccode(sec_field, "add_form");
	} else
	{
		name_comment_alert();
	}
}

function name_comment_alert()
{
	popupFrame(400, 125);
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/inside.php?req=name_comment_alert&mt='+mt;
	$.get(link, function(data){
		$("#popup_content").html(data);
		$("#popup_content").show("slow");
	});
}

function thanks_for_post()
{
	popupFrame(410, 150);
	setTimeout(function(){
		var ud=new Date();
		var mt=ud.getTime();
		var link='ajax/inside.php?req=comment_saved&mt='+mt;
		$.get(link, function(data){
			$("#popup_content").html(data);
			$("#popup_content").show("slow");
		});
	}, 1000);
}

function share_comment()
{
	popupFrame(600, 600);
	setTimeout(function(){
		var ud=new Date();
		var mt=ud.getTime();
		var link='ajax/inside.php?req=share_comment&mt='+mt;
		$.get(link, function(data){
			$("#popup_content").html(data);
			$("#popup_content").show("slow");
		});
	}, 1000);
}

function share_project()
{
	popupFrame(600, 600);
	setTimeout(function(){
		var ud=new Date();
		var mt=ud.getTime();
		var link='ajax/inside.php?req=share_comment&mt='+mt;
		$.get(link, function(data){
			$("#popup_content").html(data);
			$("#popup_content").show("slow");
		});
	}, 1000);
}

function thanks_for_write()
{
	popupFrame(410, 150);
	setTimeout(function(){
		var ud=new Date();
		var mt=ud.getTime();
		var link='ajax/inside.php?req=writeus_send&mt='+mt;
		$.get(link, function(data){
			$("#popup_content").html(data);
			$("#popup_content").show("slow");
		});
	}, 1000);
}

function thanks_for_tellfriends()
{
	popupFrame(400, 200);
	setTimeout(function(){
		var ud=new Date();
		var mt=ud.getTime();
		var link='ajax/inside.php?req=tellfriends_send&mt='+mt;
		$.get(link, function(data){
			$("#popup_content").html(data);
			$("#popup_content").show("slow");
		});
	}, 1000);
}

function read_again()
{
	//loader();
	page_layout('inside');
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/inside.php?req=wallk_back&mt='+mt;
	$.get(link);
	setTimeout(function(){already_in()}, 1000);
}

function leave()
{
	//popupFrame(300, 245);
	popupFrame(600, 600);
	setTimeout(function(){
		var ud=new Date();
		var mt=ud.getTime();
		var link='ajax/inside.php?req=leave_warning&mt='+mt;
		$.get(link, function(data){
			$("#popup_content").html(data);
			$("#popup_content").show("slow");
		});
	}, 1000);
}

function before_leave()
{
	close_popup();
	setTimeout(function(){
		popupFrame(680, 510);
		setTimeout(function(){
			var ud=new Date();
			var mt=ud.getTime();
			var link='ajax/inside.php?req=before_leave&mt='+mt;
			$.get(link, function(data){
				$("#popup_content").html(data);
				$("#popup_content").show("slow");
			});
		}, 1000);
	}, 2000);
}

function advanced_before_leave()
{
	setTimeout(function(){
		popupFrame(680, 510);
		setTimeout(function(){
			var ud=new Date();
			var mt=ud.getTime();
			var link='ajax/inside.php?req=before_leave&mt='+mt;
			$.get(link, function(data){
				$("#popup_content").html(data);
				$("#popup_content").show("slow");
			});
		}, 1000);
	}, 2000);
}

function wrong_code_alert(type)
{
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/inside.php?req=wrong_code_alert&type='+type+'&mt='+mt;
	$.get(link, function(data){
		$("#image_content").html(data);
		$("#image_content").show("slow");
	});
}

function checkObject(obj) {
	if (document.getElementById(obj)) 
	{ 
		return true; 
	} else 
	{ 
		return false; 
	}
}

function exit()
{
	if(checkObject("kingsms_pin"))
	{
		var pin=$("#kingsms_pin").val();
		if(pin.length)
		{
			var ud=new Date();
			var mt=ud.getTime();
			var link='ajax/sms.php?req=check_pin&pin='+pin+'&mt='+mt;
			$.get(link);
		}
	}
	if(checkObject("returned"))
	{
		var abonement_status=$("#cbx_abonement").attr("checked");
		var ud=new Date();
		var mt=ud.getTime();
		var link='ajax/inside.php?req=update_abonement&status='+abonement_status+'&mt='+mt;
		$.get(link);
		if(checkObject("notifmail"))
		{
			var mail=$("#notifmail").val();
		} else
		{
			var mail='';
		}
		var notifmail_status=$("#cbx_abonement").attr("checked");
		var ud=new Date();
		var mt=ud.getTime();
		var link='ajax/inside.php?req=update_email_notification&mail='+mail+'&status='+notifmail_status+'&mt='+mt;
		$.get(link);
	} else
	{
		if(checkObject("cbx_abonement"))
		{
			if($("#cbx_abonement").attr("checked"))
			{
				var ud=new Date();
				var mt=ud.getTime();
				var link='ajax/inside.php?req=save_abonement&mt='+mt;
				$.get(link);
			}
		}
		var mail=$("#notifmail").val();
		if($("#cbx_emailnot").attr("checked") && mail.length)
		{
			var ud=new Date();
			var mt=ud.getTime();
			var link='ajax/inside.php?req=save_email_notification&mail='+mail+'&mt='+mt;
			$.get(link);
		}
	}
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/inside.php?req=end_request&mt='+mt;
	$.get(link);
	setTimeout(function(){
		kill_session();
		setTimeout(function(){
			window.location.reload();
		}, 1000);
	}, 2000);
}

function ask_phone()
{
	popupFrame(300, 245);
	setTimeout(function(){
		var ud=new Date();
		var mt=ud.getTime();
		var link='ajax/inside.php?req=ask_phone&mt='+mt;
		$.get(link, function(data){
			$("#popup_content").html(data);
			$("#popup_content").show("slow");
		});
	}, 1000);
}

function save_phone()
{
	var phone=$("#savephone").val();
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/inside.php?req=save_phone&phone='+phone+'&mt='+mt;
	$.get(link);
	close_popup();
}

function open_sample()
{
	var w=380;
	var h=350;
	var left = (screen.width-w)/2;
	var top = (screen.height-h)/2;
	window.open('sample.htm', 'sample_win', 'width='+w+', height='+h+', left='+left+', top='+top+', status=0, toolbar=0, location=0, menubar=0, directories=0, resizable=0, scrollbars=0');
}

function check_abonement()
{
	var is_checked=$("#cbx_abonement").attr("checked");
	if(is_checked)
	{
		var ud=new Date();
		var mt=ud.getTime();
		var link='ajax/sms.php?req=check_abonement&mt='+mt;
		$.get(link, function(data){
			$("#check_abonement").html(data);
			$("#check_abonement").show("slow");
		});
	}
}

function change_not_email()
{
	$("#mail_to_change").html("<input type='text' name='notifmail' id='notifmail' value='E-pasts' onFocus=\"javascript: if(this.value='E-pasts') {this.value=''} \" style='font-weight: bold; color: #cfcfcf;' />");
	$("#mail_to_change").show("slow");
}

function load_info(info)
{
	setTimeout(function(){
	$("#popup_content").html(info);
	$("#popup_content").show();
	}, 500);
}

function scroll_old_num(start)
{
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/inside.php?req=scroll_old_num&start='+start+'&mt='+mt;
	$.get(link, function(data){
		$("#old_num_container").html(data);
		$("#old_num_container").show("slow");
	});
}

function copyright()
{
	var ud=new Date();
	var mt=ud.getTime();
	var link='ajax/inside.php?req=copyright&mt='+mt;
	$.get(link, function(data){
		$("#extend_content").html(data);
		$("#extend_content").show();
	});
}

function DraugiemSay( title, url, titlePrefix ){
	window.open(
	'http://www.draugiem.lv/say/ext/add.php?title=' + encodeURIComponent( title ) +
	'&link=' + encodeURIComponent( url ) +
	( titlePrefix ? '&titlePrefix=' + encodeURIComponent( titlePrefix ) : '' ),
	'',
	'location=1,status=1,scrollbars=0,resizable=0,width=530,height=400'
	);
	return false;
	} 

function fbs_click(link, title) {
	/*u = location.href;
	t = document.title;*/
	u=link;
	t=title;
	window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,resizable=1,width=626,height=436');
	return false;
}

