
function OnDescription( url, width, height )
{ 
	w = (width != null) ? width : 700;
	h = (height != null) ? height : 580;

	
	if (screen) {
		leftPos = screen.width/2-w/2
		topPos = screen.height/2-h/2
	}
	photoWin =  window.open( url, null, "width="+w+",height="+h+",top="+topPos+",left="+leftPos+",location=no,menubar=no,scrollbars=no,toolbar=no,resizable=yes", "true"); 
	photoWin.focus();
}


function OnExport(oSelID)
{
	oSel = document.getElementById(oSelID);	
	OnDescription("/Print/Export.aspx?ExportMode=" + oSel.options(oSel.selectedIndex).value);	
}

function OnMailWindow( url ){
  	window.open(url,"zoom_popup","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=1,width=350,height=600");
}

function OnShowWindow( url ){
  	window.open(url,"zoom_popup","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=1,width=350,height=600");
}

function OnComparePrint( lang, currency, params )
{
	OnDescription("/Print/Print.aspx?Page=CompareFeaturesPrint&PrintMode=1&L=" + lang + "&C=" + currency + "&Params=" + params);	
}

function OnCatalogPrint( lang, currency ) {
	OnDescription("/Print/Print.aspx?Page=CatalogPrint&L=" + lang + "&C=" + currency);
}

function OnItemPrint_v01( id ) {
	OnDescription("/Print/Print.aspx?Page=ItemPrint_v01&ID=" + id);
}
function OnItemPrint( id ) {
	OnDescription("/Print/Print.aspx?Page=ItemPrint&ID=" + id);
}



function OnItemGallery( lang, currency, accountCode, ID ) {
	OnDescription("/Print/Print.aspx?Page=ItemGallery&L=" + lang + "&C=" + currency + "&AccountCode=" + accountCode + "&ID=" + ID);
}


function OnReturnToBuy( defaultvalue ) {
	window.location.href = GetValue("url", defaultvalue ).replace("|", "=").replace("|", "=").replace("|", "=");	
}


function OnStepN( pagename ) 
{
	window.location.href = 'default.aspx?Page=' + pagename;
}

function OnStepN_Unload( nr ) {
	window.location.href = 'default.aspx?Page=CartUnload' + nr;
}

function OnCartPrint( lang, currency ) {
	OnDescription("/Print/Print.aspx?Page=CartPrint&PrintMode=1&L=" + lang + "&C=" + currency);
}

function OnCartPrint(lang, currency, cartType ) {
	OnDescription("/Print/Print.aspx?Page=" + cartType + "&PrintMode=1&L=" + lang + "&C=" + currency);
}

function OnListPrint( Page, lang, currency ) {
	OnDescription("/Print/Print.aspx?Page=" + Page + "&PrintMode=1&L=" + lang + "&C=" + currency);
}

function OnCart4Print( lang, currency ) {
	OnDescription("/Print/Print.aspx?Page=Cart4Print&PrintMode=1&L=" + lang + "&C=" + currency);
}

function OnCart4Print( lang, currency, cartType ) {
	OnDescription("/Print/Print.aspx?Page=" + cartType + "&PrintMode=1&L=" + lang + "&C=" + currency);
}

function OnCart5Print() {
	OnDescription("/Print/Print.aspx?Page=Cart5Print&PrintMode=1");
}



function OnAgreePrint( lang ) {
	OnDescription("/Print/Print.aspx?Page=AgreePrint&L=" + lang);
}

function OnPlus( quantity, toquantity )
 {  
    if(toquantity == 0)
        quantity.value++;
	else if (quantity.value <= toquantity-1)
	    quantity.value++;
	    
	quantity.select()
	
	$("." + quantity.id).val(quantity.value)
	//evaluateObjectResult( quantity )
}

function OnMinus( quantity, toquantity ) {
	if (quantity.value>1 && quantity.value > toquantity ) quantity.value--;
	quantity.select();
	
	$("." + quantity.id).val(quantity.value)
	//evaluateObjectResult( quantity )
	return false;
}

function OnQuantityChange( quantity ) {
	$("." + quantity.id).val(quantity.value)
	return false;
}

function OnCartCurrentPrint( orderID, lang, currency ) 
{
	OnDescription("/Print/Print.aspx?Page=CartCurrentPrint&PrintMode=1&OrderID=" + orderID + "&L=" + lang + "&C=" + currency);
}

function OnInvoiceCurrentPrint( orderID ) 
{
	OnDescription("/Print/Print.aspx?Page=InvoiceCurrentPrint&PrintMode=1&ID=" + orderID);
}

function OnCartCurrentPrint( orderID, lang, currency, cartType ) 
{
	OnDescription("/Print/Print.aspx?Page=Cart" + cartType + "CurrentPrint&PrintMode=1&OrderID=" + orderID + "&Lang=" + lang + "&Cur=" + currency);
}

function OnInvoicePrint( orderID, lang, currency, cartType ) 
{
	OnDescription("/Print/Print.aspx?Page=InvoicePrint&PrintMode=1&OrderID=" + orderID + "&Lang=" + lang + "&Cur=" + currency);
}

function OnWaybillPrint( orderID, lang, currency, cartType ) 
{
	OnDescription("/Print/Print.aspx?Page=WaybillPrint&PrintMode=1&OrderID=" + orderID + "&Lang=" + lang + "&Cur=" + currency);
}

function OnOrderDetailedView( orderID, lang )
{
	OnDescription("/Print/Print.aspx?Page=OrderDetailedViewPrint&PrintMode=1&OrderID=" + orderID + "&Lang=" + lang);
}

function OnProviderOrderPrint( orderID, lang, currency, VendorName, VendorEmail, VendorLang ) {
	OnDescription("/Print/Print.aspx?Page=ProviderOrderPrint&PrintMode=1&OrderID=" + orderID + "&Lang=" + lang + "&Cur=" + currency + "&VendorName=" + VendorName + "&VendorEmail=" + VendorEmail + "&VendorLang=" + VendorLang );
}

//-----------------------------------------------------------------------------------------

function NameDefined(ckie,nme)
{
   var splitValues
   var i
   for (i=0;i<ckie.length;++i)
   {
      splitValues=ckie[i].split("=")
      if (splitValues[0]==nme) return true
   }
   return false
}
function DelBlanks( strng )
{
   var result=""
   var i
   var chrn
   for (i=0;i<strng.length;++i) {
      chrn=strng.charAt(i)
      if (chrn!=" ") result += chrn
   }
   return result
}

function GetValue( cname, defaultvalue ) {  
   var cookie = document.cookie           
   var chkdCookie = DelBlanks(cookie)  
   var nvpair = chkdCookie.split(";")
   if(NameDefined(nvpair,cname))       
   {   
      tvalue = GetCookieValue(nvpair,cname) 
      return tvalue;	  
   }
   else return defaultvalue;
}

function GetCookieValue( ckie, nme )
{
   var splitValues
   var i
   for(i=0;i<ckie.length;++i) {
      splitValues=ckie[i].split("=")
      if(splitValues[0]==nme) return splitValues[1]
   }
   return ""
}

function SetCookie( cname, cvalue ) {
      var futdate = new Date()		
      var expdate = futdate.getTime() 
      expdate += 24*3600*1000  //expires in 24 hour(milliseconds)
      futdate.setTime(expdate)
      var newCookie= cname + "=" + cvalue + "; path=/;"	//Set the new cookie values up
      newCookie += " expires=" + futdate.toGMTString()
      window.document.cookie = newCookie 
      
}

//-----------------------------------------------------------------------------------------

function OnPrint(){	
	OnDescription("/Print/Print.aspx?Page=CatalogPrint");
}

function OnPriceChange( code, isDiscount ) { 
	window.open( "/Pub/PriceChange.aspx?itemcode=" + code + "&isDiscount=" + isDiscount, null, "width=780,height=400,location=no,menubar=no,scrollbars=no,toolbar=no", "true"); 
}

function OnGlossaryWord( gid ) {	
	OnDescription( "/Print/Print.aspx?Page=GlossaryInner&gid=" + gid, 400, 320);
}


function OnRepairPrint() {
	OnDescription("/Print/Print.aspx?Page=RepairPrint");
}

function OnGlossaryPrint( gid ) {	
	OnDescription( "/Print/Print.aspx?Page=GlossaryPrint&char=" + gid);	
}

function OnCalcPrint() {
	OnDescription("/Print/Print.aspx?Page=CalculatorPrint");
}

function OnCart3Print() {
	OnDescription("/Print/Print.aspx?Page=Cart3Print&PrintMode=1");
}


function OnBuy() {
	window.location.href = '/Pub/?Page=Cart';
}

function OnNewPrint(ID) {
	OnDescription("/Print/Print.aspx?Page=NewsPrint&ID=" + ID);	
}

function AddToCart(id, cartType, orderID, userProviderID, isCentral, discount){
       $.jmsajax({
                type: "POST",
                url: "default.aspx",
                method: "AddCartItem",
                data: {ID:id, Quantity:$("input#Q" + id).val(), CartType:cartType, OrderID:orderID, UserProviderID:userProviderID, IsCentral:isCentral, Discount:discount},
                success: function(data) {
                    $("#" + cartType + "Content").fadeOut("fast",function() {$(this).html(String(data))}).fadeIn("fast");                    
                    $("#SquareCell_" + id).addClass("itemActive");
                }
       });
       ChangeImg("cartImg_" + id,"/Images/design/inCartIcon.gif");
}



function ChangeImg(elementID,image){
        $('#'+elementID).fadeOut("fast").attr({src : image}).fadeIn("fast");  
}

function RemoveItem(id){
        /*$.jmsajax({
            type: "POST",
            url: "default.aspx",
            method: "RemoveCartItem",
            data: {ID:id},
            success: function(data) {
                $("#CatalogStoreContent").fadeIn("fast",function() {$(this).html(String(data))});
            }
        });*/
      }
      
function RefreshCart(){
        $.jmsajax({
            type: "POST",
            url: "default.aspx",
            method: "RefreshCart",
            data: {},
            success: function(data) {
                $("#CatalogStoreContent").fadeIn("fast",function() {$(this).html(String(data))});
            }
        });
      }
      
function AddToCatalogue(id, itemID, cataloqueID, changeImageIn, changeImageOff){
       $.jmsajax({
                type: "POST",
                url: "default.aspx",
                method: "AddCatalogueItem",
                data: {ID:id, ItemID:itemID, CatalogueID:cataloqueID, Quantity:$("input#Q" + id).val(), IsInCatalogueImageUrl:changeImageIn, IsNotInCatalogueImageUrl:changeImageOff},
                success: function(data) {
                    $("#" + "catImgLink_" + id).fadeOut("fast",function() {$(this).html(String(data))}).fadeIn("fast");
                }
       });
       /*ChangeImg("catImg_" + id, changeImage);*/
    }
    
    function AddRemoveCartCompareItem(ID, itemID, itemName){
       $.jmsajax({
                type: "POST",
                url: "default.aspx",
                method: "AddRemoveCartCompareItem",
                data: {ID:ID, ItemID:itemID, ItemName:itemName},
                success: function(data) {
                    $("#CompareContent").fadeIn("fast",function() {$(this).html(String(data))});
                }
       });
}

function OnShowClientForm( url, id) {
 //OnDescription("/Print/Print.aspx?Page=ItemPrint_v01&ID=" + id);
// var link = "/Print/Print.aspx?Page=ItemPrint_v01&ID=" + id;
var left = parseInt((screen.availWidth/2) - (700/2));
var top = parseInt((screen.availHeight/2) - (580/2));
var link = url + "?ID="+ id + "&Quantity=" + $("input#Q" + id).val();
  var result =   window.open(link,"zoom_popup","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=0,width=700px,height=580px,left=" + left + ",top=" + top+",screenX=" + left + ",screenY=" + top);
// var result = window.showModalDialog( link, window, "status:no; center:yes; help:no; minimize:no; maximize:no; scroll:no; border:thin; statusbar:no; dialogWidth:700px; dialogHeight:580px");
// document.location.reload();
 
}

function OnShowClientFormOnEdit( url, id, edit,nr, q) {
 //OnDescription("/Print/Print.aspx?Page=ItemPrint_v01&ID=" + id);
// var link = "/Print/Print.aspx?Page=ItemPrint_v01&ID=" + id;
var left = parseInt((screen.availWidth/2) - (700/2));
var top = parseInt((screen.availHeight/2) - (580/2));
var link = url + "?ID="+ id+ "&Quantity="+ q + "&Edit=" + edit + "&FormNr=" + nr;
  var result =   window.open(link,"zoom_popup","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=0,width=700px,height=580px,left=" + left + ",top=" + top+",screenX=" + left + ",screenY=" + top);
 //var result = window.showModalDialog( link, window, "status:no; center:yes; help:no; minimize:no; maximize:no; scroll:no; border:thin; statusbar:no; dialogWidth:700px; dialogHeight:580px");
 //document.location.reload();
 
}
