var domain = 'http://www.softmagazin-eka.ru/';
var imagePrefix='insImage';
var imagePrefixSmall='smallInsImage'; 
var filePrefix = 'insFile';


function pop_win(url, win, height, width) {
  	var scroll = 'no';
	var top=0, left=0;
	if(width > screen.width-10 || height > screen.height-28)
		scroll = 'yes';
	if(height < screen.height-28)
		top = Math.floor((screen.height - height)/2-14);
	if(width < screen.width-10)
		left = Math.floor((screen.width - width)/2);
	width = Math.min(width, screen.width-10);	
	height = Math.min(height, screen.height-28);
	width+=20;
	height+=10;
  popwin = window.open(url,win,"width="+width+",height="+height+",toolbar=no,resizable=no,scrollbars=yes,status=yes");
  popwin.focus();
}


function clickButton(e, buttonid){ 
      var bt = document.getElementById(buttonid); 
      if (typeof bt == 'object'){ 
            if(navigator.appName.indexOf("Netscape")>(-1)){ 
                  if (e.keyCode == 13){ 
                        bt.click(); 
                        return false; 
                  } 
            } 
            if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
                  if (event.keyCode == 13){ 
                        bt.click(); 
                        return false; 
                  } 
            } 
      } 
} 


function CloseOrderWindow()
{				
 window.close();	   
        //if (window.opener)
	//{
	//window.opener.location=window.opener.location;
	//window.opener.focus();
	//window.close();	
	//}
}

function Anthem_Error(result) {
//alert('Anthem_Error was invoked with the following error message: ' + result.error);
}

function SetDefaultLinks()
{		
        var mLinks=document.links;
        for (i = 0; i < mLinks.length; ++i) {
            var urlOld = new String(trim(mLinks[i].href)); //url from link
            var urlOldPart = urlOld.match(/\/m\/\w+$/);
            var urlOldPart2 = urlOld.match(/\/m\/\w+#w+$/);
            if (urlOldPart != null) {
                var urlNew = domain + urlOldPart[0].substring(1); //new url for link
                mLinks[i].href = urlNew;
            } else
                if (urlOldPart2 != null) {
                var urlNew = domain + urlOldPart2[0].substring(1); //new url for link
                mLinks[i].href = urlNew;
            } else {
                var str = new String(trim(mLinks[i].name));
                var nameParts = str.split('_', 2);
                if (nameParts != null && nameParts[0] == filePrefix) {
                    var urlSrc = new String(trim(mLinks[i].href)); //url from file          
                    var fileId = urlSrc.match(/id=\d+/);
                    var urlNew = domain + 'file.ashx?' + fileId; //new url for file
                    mLinks[i].href = urlNew;
                }
            }
        }
}

function SetDefaultImage()
{	
	var mImg=document.images;	
	for (i=0;i<mImg.length;++i)
	{					
		var str=new String(trim(mImg[i].name));
		var nameParts=str.split('_',2);	
		if (nameParts[0]==imagePrefix || nameParts[0]==imagePrefixSmall)
		{		
			var urlSrc= new String(trim(mImg[i].src)); //url from image
			var url=domain+'image.aspx?'; //new url for full image
			var urlSmall=domain+'imagesmall.aspx?';	//new url for miniature								
			var imageId=0; // default imageId
			var width=200; // default width 
			var height=250; // default height
			var linkId=urlSrc.match(/id=\d+/);
			var linkWidth=urlSrc.match(/width=\d+/);		
			var linkHeight=urlSrc.match(/height=\d+/);			
			if (linkId!=null && linkId.length==1)
			{
				var tId=linkId[0].split('=',2);
				if (tId!=null && tId.length==2)
					imageId=tId[1];	
			}
			if (linkWidth!=null && linkWidth.length==1)
			{
				var tWidth=linkWidth[0].split('=',2);
				if (tWidth!=null && tWidth.length==2)
					width=tWidth[1];	
			}	
			if (linkHeight!=null && linkHeight.length==1)
			{
				var tHeight=linkHeight[0].split('=',2);
				if (tHeight!=null && tHeight.length==2)			
					height=tHeight[1];	
			}
			url+='id='+imageId;
			urlSmall+='id='+imageId;
			urlSmall+='&width='+width;		
			urlSmall+='&height='+height;		
			if (nameParts[0]==imagePrefix && urlSrc!=url)
			{						
				mImg[i].src=url;
			}else
			if (nameParts[0]==imagePrefixSmall && urlSrc!=urlSmall)
			{						
				mImg[i].src=urlSmall;	
			}	
		}		
	}
}



function ShowImage(sImgPath, width, height)
{
	var scroll = 'no';
	var top=0, left=0;
	if(width > screen.width-10 || height > screen.height-28)
		scroll = 'yes';
	if(height < screen.height-28)
		top = Math.floor((screen.height - height)/2-14);
	if(width < screen.width-10)
		left = Math.floor((screen.width - width)/2);
	width = Math.min(width, screen.width-10);	
	height = Math.min(height, screen.height-28);
	width+=20;
	height+=25;	
	window.open(domain+'image.aspx?id='+sImgPath,'','scrollbars='+scroll+',resizable=no,width='+width+',height='+height+',left='+left+',top='+top);
} 

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function bookmark(){
    var title="СофтМагазин - Екатеринбург"
    var url=domain;

    if (window.sidebar) window.sidebar.addPanel(title, url,"");

    else if( window.opera && window.print )
    {
    	alert('Нажмите Ctrl-D чтобы добавить сайт в избранное');
    }
    else if( window.external ) window.external.AddFavorite( url, title);

}


function GetDescrByProductId(productId) {
									
	Anthem_InvokePageMethod(
	'GetDescr',[productId],function(result) {	
	var spanDescr = document.getElementById('spanDescr');
        if (result.value.length>0)	
		spanDescr.innerHTML=result.value;	
	}
	);		
}


function GetNewsCaptions() {									

Anthem_InvokeMasterPageMethod(
'GetNewsCaptions',null,function(result) {
	mas=result.value;
	for (var i=0;i<mas.length;i++)
	{			
		var newsParts=mas[i].split('|',2);
		var newsId=newsParts[0];
		var newsCaption=newsParts[1];
		name='spanCaption'+newsId;	
		var spanCaption = document.getElementById(name);	
		spanCaption.innerHTML=newsCaption;
	}
	}
	);
}

function GetDescrByCategoryId(categoryId) {										
	Anthem_InvokePageMethod(
	'GetDescr',[categoryId],function(result) {
	var spanDescr = document.getElementById('spanDescr');	
        if (result.value.length>0)
		spanDescr.innerHTML=result.value;	
	}
	);		
}

function GetDescrByProducerId(producerId) {										
	Anthem_InvokePageMethod(
	'GetDescr',[producerId],function(result) {
	var spanDescr = document.getElementById('spanDescr');	
        if (result.value.length>0)
		spanDescr.innerHTML=result.value;	
	}
	);		
}

function linkToSoftCatalog()
{
    window.location=domain+"/soft";
}








