function setMapHeight(){
 
	var myWidth = 0, myHeight = 0;
	/*if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		 //IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	} else {
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	if(document.getElementById('body_your').clientHeight<myHeight)	
	document.getElementById('body_your').style.height=myHeight+"px";	*/
	
}

//пересчет содержимого корзины
function calc_products( id, type ){
	$('#btn_sc'+id).html('');
	
	var qty = $('#qty_'+id).val();
	$.get( '/ajax/shop/shopcart.php', { 'id' : id, 'qty' : qty }, function(data){
		
		my_purchases();
		if(type==0){ add_item_to_shoping_cart( 0 );document.getElementById('administrative_control').innerHTML  =  data;} else ref_list_products();
	});

}

//Мои покупки
function my_purchases( ){
	var param = {};
		$.get( "/source/purchased", 
			param, 
			function( json ){
			j = eval('('+json+')');
			var str = '<a href="javascript:void(0);" onClick="add_item_to_shoping_cart( 0 );" class="button_bg">Мои покупки</a>';
			
			str += j.message ;
			
			$('#package').html( str );

	});
			
}

function button_conv_products( id, type ){
	$('#btn_sc'+id).html('<a href="javascript:calc_products( '+id+','+type+' )"><img src="/images/tick.png" /></a>')
}

//Удаление товара
function remove_goods( id, type ){
	$.get( '/ajax/shop/remove_goods.php', { 'id': id }, function(json){
		my_purchases();
		if(type==0) add_item_to_shoping_cart( 0 ); else ref_list_products();
	});
}

//листинг товаров на форме оформления товара
function ref_list_products(){
	$('#ref_list_products').html('<div align="center"><img src="/images/loading.gif" /></div>' );
	$.get( '/ajax/shop/shopcart_checkout.php', {  }, function( data ){
		$('#ref_list_products').html( data );
	});
}

//Покупка товара
function add_item_to_shoping_cart( id ){

	document.getElementById('administrative_control').innerHTML = "<div align='center'><img src='/images/loading.gif' /></div>";
	$('#administrative_control').dialog('destroy');
	$("#administrative_control").dialog({
        width: 600,
		height: 450,
		title: 'Список покупок',
       	 	resizable: true,
        	draggable: true,
        	modal : true,
        overlay: {
            backgroundColor: '#000',
            opacity: 0.5
        },
		buttons: {
			
			'Оформить заказ' : function() {  document.location = $( '#checkout' ).val(); },
			'Продолжить покупки' : function() {$(this).dialog('destroy');}
		}
    });
	

	$.get( '/ajax/shop/shopcart.php', { 'id': id }, function(json){
		
		document.getElementById('administrative_control').innerHTML  =  json;
		$('.ui-dialog').css('position', 'fixed');
		var myHeight = getClientHeight();
		var top =  (myHeight-document.getElementById('administrative_control').clientHeight)/2-50;
		$('.ui-dialog').css('top', top);
		$("#administrative_control").dialog({autoOpen: false});
		$("#administrative_control").dialog('open');
		my_purchases();
		

	});
	
	
}

function getClientHeight(){
	var myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		 //IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myHeight = document.body.clientHeight;
	} else {
		myHeight = document.body.clientHeight;
	}
	return myHeight;
}

function getClientWidth(){
	var myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
	} else if( document.documentElement && ( document.documentElement.clientWidth ) ) {
		 //IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
	} else if( document.body && ( document.body.clientWidth ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
	} else {
		myWidth = document.body.clientWidth;
	}
	return myWidth;
}

//
var g_ruleName = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_-abcdefghijklmnopqrstuvwxyz'";
var m_rulePhone = "0123456789-";
var g_ruleNumber = ".0123456789";
var g_ruleSSNNo = "-0123456789";

var g_ruleUri = ".ABCDEFGHIJKLMNOPQRSTUVWXYZ_-abcdefghijklmnopqrstuvwxyz'";

function isRule(oComp, sRule, nLength, fdecimal)
{

	if (fdecimal == "" || typeof(fdecimal) == "undefined")
	{
		fdecimal = false;
	}

	//If the object is not specified return false
	if (typeof(oComp) == 'undefined' || oComp == null || oComp == '')
	{
		alert('Error: Input object not specified.');
		return false;
	}
	//If neither rule nor max length is specified, return false
	else if (typeof(sRule) == 'undefined' && typeof(nLength) == 'undefined')
	{
		alert('Error: No rule/maximum lenght for input object specified.');
		return false;
	}

	var noErrorFlg = true;

	//If object is specified and either of rule is specified,
	if (typeof(sRule) != 'undefined' && sRule != null)
	{
		var temp;
		sRule = sRule + "";
		var discardChars = false;
		if (sRule.length > 0 && sRule.charAt(0) == "~")
		{
			sRule = sRule.substring(1);
			discardChars = true;
		}

		if (typeof(oComp) == "undefined" || typeof(sRule) == "undefined")
			return false;

		for (var i = 0;i < oComp.value.length;i++)
		{
			temp = oComp.value.charAt(i);

			if ((!discardChars && sRule.indexOf(temp) == -1) || (discardChars && sRule.indexOf(temp) >= 0))
			{
				alert("Введен неверный символ!");
				oComp.value = oComp.value.substring(0,i);// + (oComp.value.length > i ? oComp.value.substring(i+1):"");
				noErrorFlg = false;
				break;
			}
		}
	}
	if (nLength)
	{
		if (fdecimal)
		{
			nLength -= fdecimal;
			var dp = oComp.value.indexOf(".");
			var p1;
			var p2 = "";
			if (dp >= 0)
			{
				p1 = oComp.value.substring(0,dp);
				p2 = oComp.value.substring(dp+1);
			}
			else
			{
				p1 = oComp.value;
			}
			if (p1.length > nLength)
			{
				oComp.value = oComp.value.substring(0,nLength);
				return noErrorFlg;
			}
			for (var i = 0;i < p2.length;i++)
			{
				var ch = p2.charAt(i);
				if (ch < '0' || ch > '9')
				{
					oComp.value = p1 + "." + p2.substring(0,i);
					return noErrorFlg;
				}
			}
			if (p2.length > fdecimal)
			{
				oComp.value = p1 + "." + p2.substring(0,fdecimal);
			}
		}
		else if (oComp.value.length > nLength)
		{
			oComp.value = oComp.value.substring(0,nLength);
		}
	}
	return noErrorFlg;
}


function wordwrap( str, width, brk, cut ) {
/*
текст,разбить на строки
width - ширина будущей строки
brk - разделитель (для html кода "<br>")
*/
   brk = brk || '\n';
   width = width || 75;
   cut = cut || false;
   if (!str) { return str; }
   var regex = '.{1,' +width+ '}(\\s|$)' + (cut ? '|.{' +width+ '}|.+$' : '|\\S+?(\\s|$)');
   return str.match( RegExp(regex, 'g') ).join( brk );
}

