// мои скрипты
	//нестандартные селекты для формы
var params = {
	changedEl: "#city13",
	visRows: 5,
	scrollArrows: true
}
cuSel(params);

var params = {
	changedEl: "#city14",
	visRows: 5,
	scrollArrows: true
}
cuSel(params);
	var params = {
	changedEl: "#city15",
	visRows: 5,
	scrollArrows: true
}
cuSel(params);
	var params = {
	changedEl: "#city16",
	visRows: 5,
	scrollArrows: true
}
cuSel(params);
//конец нестандартных селектов
	


//выплывающие подсказки для драг металлов
$(document).ready(function(){	


						   
	$("#im1").easyTooltip({
		useElement: "it1"				   
	});
	$("#im2").easyTooltip({
		useElement: "it2"				   
	});
	$("#im3").easyTooltip({
		useElement: "it3"				   
	});
	$("#im4").easyTooltip({
		useElement: "it4"				   
	});
	$("#im5").easyTooltip({
		useElement: "it5"				   
	});
	$("#im6").easyTooltip({
		useElement: "it6"				   
	});
	$("#im7").easyTooltip({
		useElement: "it7"				   
	});


// главное меню появления подменю


mb1=0;
// физические лица
$('#m1').mouseenter(function(){
							  var kol =  $('.ui-sortable-placeholder').length;
	
	if (kol==0)
	{
							 if (mb1==1)
	{

	$('#txt1').html($('#mb1').html());
		
	}
	
	if (mb1==2)
	{

	$('#txt2').html($('#mb2').html());
		
	}
	
	if (mb1==3)
	{

	$('#txt3').html($('#mb3').html());
		
	}
	$('.text1').html("<div id='mb1' style='width:100%;height:262px; display:none;'></div>");
	$('#mb1').css("background","url(/incom/template/template1/images/m_bg.jpg) no-repeat 0px 0px");
	$('#m1').css("border-bottom","none");
	$('#m2').css("border-bottom","none");
	$('#m3').css("border-bottom","none");
	$('.text1').css("visibility","visible");
	$('#mb1').html($('#txt1').html());
	$('#txt1').html("");
	$('#m1').css("color","white");
	$('#mb1').fadeIn(500);
	mb1=1;
	
	// Example 2.3: Save items automaticly
	$('.sort1').sortable({
		connectWith: '.sort1',
		handle: '.h7',
		update: function(){
			//$.cookie('cookie-m1', getItems2('#txt1'),{expires: 1000});
		}
	});
	
	$( ".sort1" ).disableSelection();
	
	}
	
});


		
// юридические лица		
$('#m2').mouseenter(function(){
							  var kol =  $('.ui-sortable-placeholder').length;
	
	if (kol==0)
	{
							 if (mb1==1)
	{

	$('#txt1').html($('#mb1').html());
		
	}
	
	if (mb1==2)
	{

	$('#txt2').html($('#mb2').html());
		
	}
	
	if (mb1==3)
	{

	$('#txt3').html($('#mb3').html());
		
	}
	$('.text1').html("<div id='mb2' style='width:100%;height:262px;display:none;'></div>");
	$('#mb2').css("background","url(/incom/template/template1/images/m_bg1.jpg) no-repeat 0px 0px");
	$('#m2').css("border-bottom","none");
	$('#m1').css("border-bottom","none");
	$('#m3').css("border-bottom","none");
	$('.text1').css("visibility","visible");
	$('#mb2').html($('#txt2').html());
	$('#txt2').html("");
	$('#m1').css("color","white");
	$('#mb2').fadeIn(500);
	mb1=2;
	// Example 2.3: Save items automaticly
	$('.sort1').sortable({
		connectWith: '.sort1',
		handle: '.h7',
		update: function(){
			//$.cookie('cookie-m2', getItems3('#txt2'),{expires: 1000});
		}
	});
	
	$( ".sort1" ).disableSelection();
	}
});

// малый и средний бизнес		
$('#m3').mouseenter(function(){
							 
							  var kol =  $('.ui-sortable-placeholder').length;
	
	if (kol==0)
	{
							 if (mb1==1)
	{

	$('#txt1').html($('#mb1').html());
		
	}
	
	if (mb1==2)
	{

	$('#txt2').html($('#mb2').html());
		
	}
	
	if (mb1==3)
	{

	$('#txt3').html($('#mb3').html());
		
	}
	$('.text1').html("<div id='mb3' style='width:100%;height:262px; display:none'></div>");
	$('#mb3').css("background","url(/incom/template/template1/images/m_bg2.jpg) no-repeat 0px 0px");
	$('#m3').css("border-bottom","none");
	$('#m1').css("border-bottom","none");
	$('#m2').css("border-bottom","none");
	$('.text1').css("visibility","visible");
	$('#mb3').html($('#txt3').html());
	$('#txt3').html("");
	$('#m1').css("color","white");
	$('#mb3').fadeIn(500);
	mb1=3;
	// Example 2.3: Save items automaticly
	$('.sort1').sortable({
		connectWith: '.sort1',
		handle: '.h7',
		update: function(){
			//$.cookie('cookie-m3', getItems4('#txt3'),{expires: 1000});
		}
	});
	
	$( ".sort1" ).disableSelection();
	}
});
		
//закрытие менюшки
$('#menu').mouseleave(function(){
							   
    var kol =  $('.ui-sortable-placeholder').length;
	
	if (kol==0)
	{
							   
	//alert (mb1);
	if (mb1==1)
	{

	$('#txt1').html($('#mb1').html());
		
	}
	
	if (mb1==2)
	{

	$('#txt2').html($('#mb2').html());
		
	}
	
	if (mb1==3)
	{

	$('#txt3').html($('#mb3').html());
		
	}
							   
	mb1=0;
	
	
	
	$('#mb3').fadeOut(500);
	$('#mb2').fadeOut(500);
	$('#mb1').fadeOut(500);
	$('#m1').css("color","white");
	$('#m3').css("border-bottom","none");
	$('#m1').css("border-bottom","none");
	$('#m2').css("border-bottom","none");
	}
});


// обработка селекта для выбора города

var cur;
	$('.select').click(function(){
		if ($("#gorod").val()!="")
		{
			
			cur=$("#gorod").val();
			$("#gorod").val("");
			//$('.scrolling').show();
			$('.list').show();
			$('#scrolling').jScrollPane({showArrows:false});
			$('.jspDrag').css({"background":"url(/incom/template/template1/images/drag1.png) no-repeat left top","left":"6px","height":"48px !important"});
			$('.jspContainer').css({"height":"380px","margin-top":"10px"});
			
			
			 
		}
		else
		{
			$("#gorod").val(cur);
			$(".list").hide();	
		}
	});

	$('.pseudoselect option').each(function(){
		$('.list').append('<em><a href="#" style=""><div onclick="" style="margin-left:15px; width:180px;  font-style:normal;">'+$(this).val()+'</div></a></em>');
	});
	$('.list').append('<div class="foot"></div>');

	$("em").click(function(){
		$("#gorod").val($(this).text());
		$(".list").hide();
	});					   
	$("em a div").mouseenter(function(){
		$(this).css("color", "#00823C");
	});
			
	$("em a div").mouseleave(function(){
		$(this).css("color", "#7C7C7C");
	});
		
	$(".list").mouseenter(function(){
		$('#cap').css("z-index","-1");
	});
		
	$(".list").mouseleave(function(){
		$('#cap').css("z-index","0");
	});
	
	$("#gorod").mouseenter(function(){
		$('#cap').css("z-index","-1");
	});
		
	$("#gorod").mouseleave(function(){
		$('#cap').css("z-index","0");
	});
	


// обработка вывода филиалов, банкоматов, ИПТ

	//	закрытие окна
	$("#close1").click(function(){
		$('#opaco1').toggleClass('hidden').removeAttr('style');
		document.getElementById('mol1').style.display='none';
		$('#ser').val("Быстрый поиск/");
		$('#mytest').html("<p style=\"color:#555\">Пожалуйста, подождите, идет загрузка!</p>");
		
	});
	
	// показ филиалов
	$("#mod12").click(function(){
		$("#vallue").attr("alt","1");
		$("#gr").html('<h6 style="font-size:24px; float:left; display:block; color:#18723c; font-weight:normal; margin:0px; padding:0px; margin-left:25px; font-family:Arial, Helvetica, sans-serif; margin-right:5px; padding-top:0px;">Филиалы г.</h6>'+$("#gorod").val());
		document.getElementById('mol1').style.display="none";
		document.getElementById('mol1').style.left='0px';
		document.getElementById('mol1').style.top='105px';
		if($.browser.msie)
   		{
     	$('#opaco1').height($(document).height()).toggleClass('hidden');
   		}
   		else
   		{
     	$('#opaco1').height($(document).height()).toggleClass('hidden').fadeTo('slow', 0.7);
   		}
		$('#mol1').show();
		$("#bbb").html("<p style=\"color:#555\">Пожалуйста, подождите, идет загрузка!</p>");
		// аякс подгрузка филиалов
		$.ajax({url: "/ru/filial.php",
				data: "do=send1&gorod="+$("#gorod").val()+"&x=secure",
				type: "POST",
				dataType : "html",
				cache: false,
				beforeSend: function()         {  }, 
				success:  function(data)  { $('.scroll-pane').jScrollPane(); var pane2api = $('#pane2').data('jsp');	var originalContent = pane2api.getContentPane().html(); pane2api.getContentPane().html(data); pane2api.reinitialise();  },
				error: function()         { $("#pane2").html("<p style=\"color:#e12a73;\">Невозможно связаться с сервером!</p>"); }
			});
	});
	
	//  показ банкоматов
	$("#mod13").click(function()
	{
		$("#vallue").attr("alt","2");
		$("#gr").html('<h6 style="font-size:24px; float:left; display:block; color:#18723c; font-weight:normal; margin:0px; padding:0px; margin-left:25px; font-family:Arial, Helvetica, sans-serif; margin-right:5px; padding-top:0px;">Банкоматы г.</h6>'+$("#gorod").val());
		document.getElementById('mol1').style.display="none";
		document.getElementById('mol1').style.left='0px';
		document.getElementById('mol1').style.top='105px';
		if($.browser.msie)
   		{
     	$('#opaco1').height($(document).height()).toggleClass('hidden');
   		}
   		else
   		{
     	$('#opaco1').height($(document).height()).toggleClass('hidden').fadeTo('slow', 0.7);
   		}
		$('#mol1').show();
		$("#bbb").html("<p style=\"color:#555\">Пожалуйста, подождите, идет загрузка!</p>");
		// аякс подгрузка филиалов
			$.ajax({url: "/ru/bank.php",
			data: "do=send1&gorod="+$("#gorod").val()+"&x=secure",
			type: "POST",
			dataType : "html",
			cache: false,
			beforeSend: function()    {  }, 
			success:  function(data)  { $('.scroll-pane').jScrollPane();var pane2api = $('#pane2').data('jsp');	var originalContent = pane2api.getContentPane().html();pane2api.getContentPane().html(data);pane2api.reinitialise(); },
			error: function()         { $("#pane2").html("<p style=\"color:#e12a73;\">Невозможно связаться с сервером!</p>"); }
			});
	});
	
	//  показ ипт
	$("#mod14").click(function()
	{
		$("#vallue").attr("alt","3");
		$("#gr").html('<h6 style="font-size:24px; float:left; display:block; color:#18723c; font-weight:normal; margin:0px; padding:0px; margin-left:25px; font-family:Arial, Helvetica, sans-serif; margin-right:5px; padding-top:0px;">Платежные терминалы</h6>');
		document.getElementById('mol1').style.display="none";
		document.getElementById('mol1').style.left='0px';
		document.getElementById('mol1').style.top='105px';
		if($.browser.msie)
   		{
     	$('#opaco1').height($(document).height()).toggleClass('hidden');
   		}
   		else
   		{
     	$('#opaco1').height($(document).height()).toggleClass('hidden').fadeTo('slow', 0.7);
   		}
		$('#mol1').show();
		$("#bbb").html("<p style=\"color:#555\">Пожалуйста, подождите, идет загрузка!</p>");
		// аякс подгрузка филиалов
			$.ajax({url: "/ru/ipt.php",
			data: "do=send1&gorod="+$("#gorod").val()+"&x=secure",
			type: "POST",
			dataType : "html",
			cache: false,
			beforeSend: function()    {  }, 
			success:  function(data)  { $('.scroll-pane').jScrollPane();var pane2api = $('#pane2').data('jsp');	var originalContent = pane2api.getContentPane().html();pane2api.getContentPane().html(data);pane2api.reinitialise(); },
			error: function()         { $("#pane2").html("<p style=\"color:#e12a73;\">Невозможно связаться с сервером!</p>"); }
			});
	});
	// кнопка закрытия карты					
$("#close12").click(function()
{
	$('#opaco').toggleClass('hidden').removeAttr('style');
	$('#maps').hide();
});



});

// карта яндекс с параметрамми филиалов key1,key2 координаты, desc описание
function init (key1,key2,desc) {
	if ($('#maps').css("display")=="none"){
		$('#maps').alignCenter();
		$('#maps').show();
		if($.browser.msie){
		     $('#opaco').height($(document).height()).toggleClass('hidden');
   		}
   		else{
     		$('#opaco').height($(document).height()).toggleClass('hidden').fadeTo('slow', 0.7);
   		}
	}
	// Создание экземпляра карты и его привязка к созданному контейнеру
    var map = new YMaps.Map(YMaps.jQuery("#YMapsID")[0]);
    // Установка для карты ее центра и масштаба
    map.setCenter(new YMaps.GeoPoint(key1,key2), 17);
	// Создание метки
	// Создание стиля для значка метки
            var s = new YMaps.Style();
            s.iconStyle = new YMaps.IconStyle();
            s.iconStyle.href = "/sb.png";
            s.iconStyle.size = new YMaps.Point(29, 28);
            s.iconStyle.offset = new YMaps.Point(-9, -29);
            
            s.iconStyle.shadow = new YMaps.IconShadowStyle();
            s.iconStyle.shadow.href = "/sb.png";
            s.iconStyle.shadow.size = new YMaps.Point(29, 28);
            s.iconStyle.shadow.offset = new YMaps.Point(-9, -29);
	//var styleKeys = ["default#greenPoint"];
    // Создание метки с пользовательским стилем и добавление ее на карту
    var placemark = new YMaps.Placemark(new YMaps.GeoPoint(key1,key2), {style: s} );
    placemark.description = desc;
    map.addOverlay(placemark);
    // Открытие балуна
    placemark.openBalloon();
}

function atoprint1(aId) {
var atext = document.getElementById(aId).innerHTML;
var alink = window.document.location;
var prwin = open('');
prwin.document.open();
prwin.document.writeln('<html><head><title>Версия для печати<\/title><\/head><body text="#000000" bgcolor="#FFFFFF"><div onselectstart="return false;" oncopy="return false;">');
prwin.document.writeln(atext);
prwin.document.writeln('<\/div><script type="text\/javascript">window.print();<\/script><\/body><\/html>');
}

$(document).ready(function(){
   //align element in the middle of the screen
  $.fn.alignCenter = function() {
   //get margin left
   var marginLeft = Math.max(40, parseInt($(window).width()/2 - $(this).width()/2)) + 'px';
   //get margin top
   var marginTop = Math.max(40, parseInt($(window).height()/2 - $(this).height()/2)) + 'px';
   //return updated element
   return $(this).css({'margin-left':marginLeft, 'margin-top':marginTop});
  };
});

$(document).ready(function(){

});

$(document).ready(function () {

	
	
	
	$("#zak12").click(function()
	{
			$.ajax(
			{
				url: "/ru/ajax.php",
				data: "do=show_tel&x=secure",
				type: "POST",
				dataType : "html",
				cache: false,
				success:  function(data)  { $("#mess").html(data);
				
				$('#tel_bg').fadeIn('500');
				params = {
					refreshEl: "#city123", 
					visRows: 5
				}
				cuSelRefresh(params);
							
				 },
				error: function()         {  }
			});
	
	});
	
	
	$("#ban2").click(function()
	{
			$.ajax(
			{
				url: "/ru/ajax.php",
				data: "do=show_obsl&x=secure",
				type: "POST",
				dataType : "html",
				cache: false,
				success:  function(data)  { $("#mess").html(data);
				
				if ($('#tel_bg1').css("display")=="none")
		{
			$('#tel_bg1').alignCenter();
			$('#tel_bg1').show();
			params = {
			refreshEl: "#city, #city1, #city2, #city3, #city4, #city5, #city6, #city7", /* перечисляем через запятую id селектов, которые нужно обновить */
			visRows: 5
			}
			cuSelRefresh(params);

			if($.browser.msie)
   			{
     			$('#opaco').height($(document).height()).toggleClass('hidden');
   			}
   			else
   			//in all the rest browsers - fade slowly
   			{
     			$('#opaco').height($(document).height()).toggleClass('hidden').fadeTo('slow', 0.7);
   			}
		}
							
				 },
				error: function()         {  }
			});
	
	});
	
	$("#men1").click(function()
	{
			$.ajax(
			{
				url: "/ru/ajax.php",
				data: "do=show_kred&x=secure",
				type: "POST",
				dataType : "html",
				cache: false,
				success:  function(data)  { $("#mess").html(data);
				
		$('#zak_kred').alignCenter();

		$('#zak_kred').show();
		params = {
	refreshEl: "#kred_vid, #kred_val, #kred_ot1", /* перечисляем через запятую id селектов, которые нужно обновить */
	visRows: 5
	}
	cuSelRefresh(params);
		if($.browser.msie)
   {
     $('#opaco').height($(document).height()).toggleClass('hidden');
   }
   else
   //in all the rest browsers - fade slowly
   {
     $('#opaco').height($(document).height()).toggleClass('hidden').fadeTo('slow', 0.7);
   }
							
				 },
				error: function()         {  }
			});
	
	});
	
	$("#men2").click(function()
	{
			$.ajax(
			{
				url: "/ru/ajax.php",
				data: "do=show_dep&x=secure",
				type: "POST",
				dataType : "html",
				cache: false,
				success:  function(data)  { $("#mess").html(data);
				
		$('#zak_dep').alignCenter();

		$('#zak_dep').show();
	params = {
	refreshEl: "#dep_val, #dep_vid, #dep_ot1", /* перечисляем через запятую id селектов, которые нужно обновить */
	visRows: 5
	}
	cuSelRefresh(params);
	if($.browser.msie)
   {
     $('#opaco').height($(document).height()).toggleClass('hidden');
   }
   else
   //in all the rest browsers - fade slowly
   {
     $('#opaco').height($(document).height()).toggleClass('hidden').fadeTo('slow', 0.7);
   }
							
				 },
				error: function()         {  }
			});
	
	});
	
	$("#men3").click(function()
	{
			$.ajax(
			{
				url: "/ru/ajax.php",
				data: "do=show_cart&x=secure",
				type: "POST",
				dataType : "html",
				cache: false,
				success:  function(data)  { $("#mess").html(data);
				
		$('#zak_kart').alignCenter();

		$('#zak_kart').show();
	params = {
	refreshEl: "#kart_ot1, #kart_vid, #kart_val", /* перечисляем через запятую id селектов, которые нужно обновить */
	visRows: 5
	}
	cuSelRefresh(params);
	if($.browser.msie)
   {
     $('#opaco').height($(document).height()).toggleClass('hidden');
   }
   else
   //in all the rest browsers - fade slowly
   {
     $('#opaco').height($(document).height()).toggleClass('hidden').fadeTo('slow', 0.7);
   }
							
				 },
				error: function()         {  }
			});
	
	});
	
	$("#men4").click(function()
	{
			$.ajax(
			{
				url: "/ru/ajax.php",
				data: "do=show_mon&x=secure",
				type: "POST",
				dataType : "html",
				cache: false,
				success:  function(data)  { $("#mess").html(data);
				
		$('#zak_mon').alignCenter();

		$('#zak_mon').show();
		params = {
	refreshEl: "#mon_vid, #mon_ot1", /* перечисляем через запятую id селектов, которые нужно обновить */
	visRows: 5
	}
	cuSelRefresh(params);
	if($.browser.msie)
   {
     $('#opaco').height($(document).height()).toggleClass('hidden');
   }
   else
   //in all the rest browsers - fade slowly
   {
     $('#opaco').height($(document).height()).toggleClass('hidden').fadeTo('slow', 0.7);
   }
							
				 },
				error: function()         {  }
			});
	
	});
	
	$("#men5").click(function()
	{
			$.ajax(
			{
				url: "/ru/ajax.php",
				data: "do=show_sms&x=secure",
				type: "POST",
				dataType : "html",
				cache: false,
				success:  function(data)  { $("#mess").html(data);
				
		$('#zak_sms').alignCenter();

		$('#zak_sms').show();
		params = {
	refreshEl: "#sms_ot1, #sms_val, #sms_vid", /* перечисляем через запятую id селектов, которые нужно обновить */
	visRows: 5
	}
	cuSelRefresh(params);
	if($.browser.msie)
   {
     $('#opaco').height($(document).height()).toggleClass('hidden');
   }
   else
   //in all the rest browsers - fade slowly
   {
     $('#opaco').height($(document).height()).toggleClass('hidden').fadeTo('slow', 0.7);
   }
							
				 },
				error: function()         {  }
			});
	
	});
	
	$("#men6").click(function()
	{
			$.ajax(
			{
				url: "/ru/ajax.php",
				data: "do=show_sch&x=secure",
				type: "POST",
				dataType : "html",
				cache: false,
				success:  function(data)  { $("#mess").html(data);
				
		$('#zak_sch').alignCenter();

		$('#zak_sch').show();
		params = {
	refreshEl: "#sch_ot1, #sch_vall", /* перечисляем через запятую id селектов, которые нужно обновить */
	visRows: 5
	}
	cuSelRefresh(params);
	if($.browser.msie)
   {
     $('#opaco').height($(document).height()).toggleClass('hidden');
   }
   else
   //in all the rest browsers - fade slowly
   {
     $('#opaco').height($(document).height()).toggleClass('hidden').fadeTo('slow', 0.7);
   }
							
				 },
				error: function()         {  }
			});
	
	});
	
		// быстрый поиск в всплывающем окне
	$("#serch").click(function()
	{
		
		// если филиалы
		if ($('#vallue').attr("alt")==1)
		{
			if ($('#ser').val()=='Быстрый поиск/')
			{
				alert('Введите слово для поиска');	
			}	
			else
			{
				$.ajax({url: "/ru/filial.php",
				data: "do=send_serch&gorod="+$("#gorod").val()+"&slovo="+$("#ser").val()+"&x=secure",
				type: "POST",
				dataType : "html",
				cache: false,
				beforeSend: function() {  }, 
				success:  function(data)  { $('.scroll-pane').jScrollPane(); var pane2api = $('#pane2').data('jsp');	var originalContent = pane2api.getContentPane().html(); pane2api.getContentPane().html(data); pane2api.reinitialise();  },
				error: function()         { $("#pane2").html("<p style=\"color:#e12a73;\">Невозможно связаться с сервером!</p>"); }
				});	
			}
		}
		// елси банкоматы
		if ($('#vallue').attr("alt")==2)
		{
			if ($('#ser').val()=='Быстрый поиск/')
			{
				alert('Введите слово для поиска');	
			}	
			else
			{
				$.ajax({url: "/ru/bank.php",
				data: "do=send_serch&gorod="+$("#gorod").val()+"&slovo="+$("#ser").val()+"&x=secure",
				type: "POST",
				dataType : "html",
				cache: false,
				beforeSend: function() {  }, 
				success:  function(data)  { $('.scroll-pane').jScrollPane(); var pane2api = $('#pane2').data('jsp');	var originalContent = pane2api.getContentPane().html(); pane2api.getContentPane().html(data); pane2api.reinitialise();  },
				error: function()         { $("#pane2").html("<p style=\"color:#e12a73;\">Невозможно связаться с сервером!</p>"); }
				});	
			}
		}
		// если ИПТ
		if ($('#vallue').attr("alt")==3)
		{
			if ($('#ser').val()=='Быстрый поиск/')
			{
				alert('Введите слово для поиска');	
			}	
			else
			{
				$.ajax({url: "/ru/ipt.php",
				data: "do=send_serch&gorod="+$("#gorod").val()+"&slovo="+$("#ser").val()+"&x=secure",
				type: "POST",
				dataType : "html",
				cache: false,
				beforeSend: function() {  }, 
				success:  function(data)  { $('.scroll-pane').jScrollPane(); var pane2api = $('#pane2').data('jsp');	var originalContent = pane2api.getContentPane().html(); pane2api.getContentPane().html(data); pane2api.reinitialise();  },
				error: function()         { $("#pane2").html("<p style=\"color:#e12a73;\">Невозможно связаться с сервером!</p>"); }
				});	
			}
		}
		
		
	});
	
	
});

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
}
