var Path2Main = '/website/languagexchange/template/';
var Path = '/';
var being_calculated = false;
j.fn.exists = function(){return j(this).length>0;}
function GenerateIndexError(error)
{
return '
![]('+Path2Main+'images/home_alert.gif) | '+error+' |
';
}
function LoadTargetLanguages()
{
ResetLabelsForSlider("SpeedWrapper", speedLabels);
var lng = j('#LangFrom').val();
JsHttpRequest.query(
Path + 'ecommerce/ajax.php',
{
'Action': "LoadTargetLanguages",
'OrigLangID': lng
},
function(result, errors)
{
if (!result) { jAlert('error', ""); return;}
if (result['Content'] && result['Content'].length > 0)
{
var style = j('#LangFrom').parent().attr("class");
j('#LangTo').unbind('click');
j('#TargetLangBlock').html(result['Content']).addClass(style);
j('#PleaseSelect').hide();
j('#LangTo').click(function(){CalculateQuote(true)}).sSelect();
}
else
{
j('#TargetLangBlock').removeClass("select_s").html("");
j('#PleaseSelect').show();
}
},
true
);
}
function LoadTargetLanguages1()
{
var lng = j('#LangFrom1').val();
JsHttpRequest.query(
Path + 'ecommerce/ajax.php',
{
'Action': "LoadTargetLanguages1",
'OrigLangID1': lng
},
function(result, errors)
{
if (!result) { jAlert('error', ""); return;}
if (result['Content'] && result['Content'].length > 0)
{
var style = j('#LangFrom1').parent().attr("class");
j('#LangTo1').unbind('click');
j('#TargetLangBlock1').html(result['Content']).addClass(style);
j('#PleaseSelect1').hide();
j('#LangTo1').sSelect();
}
else
{
j('#TargetLangBlock1').removeClass("select_s").html("");
j('#PleaseSelect1').show();
}
},
true
);
}
function CalculateQuote(resetSlider)
{
if (being_calculated) return;
being_calculated=true;
if (resetSlider) ResetLabelsForSlider("SpeedWrapper", speedLabels);
var currency = j('input[name="Currency"]:checked').val();
JsHttpRequest.query(
Path + 'ecommerce/ajax.php',
{
'Action': "CalculateQuoteForm",
'Form': document.getElementById('RequestForm')
},
function(result, errors)
{
being_calculated = false;
if (!result)
{
ResetLabelsForSlider("SpeedWrapper", speedLabels);
SetQuoteBlock();
HideLoading();
jAlert('error', "");
return;
}
if (result["TotalLines"])
{
j('#TotalLines').html(result["TotalLines"]);
j("#Sp1,#Sp2").show();
}
else
{
j("#Sp1,#Sp2").hide();
j('#TotalLines').html("");
}
if (result["Error"])
{
if (j('.note').not('#RequestForm .note').exists())
{
j('.note:first').html(''+result["Error"]+'
');
}
else if(j('.table_steps').exists())
{
j('.table_steps').after(''+result["Error"]+'
');
}
}
else
{
if (j('.note').not('#RequestForm .note').exists())
{
j('.note:first').not('#errorlist').remove();
}
}
if (result['Answer'] == 'Done' && !result["Error"])
{
var sp = j('#SpeedWrapper span.ui-slider-label');
try
{
if (result["DeliveryTime1"])
sp[0].innerHTML = result["DeliveryTime1"];
if (result["DeliveryTime2"])
sp[1].innerHTML = result["DeliveryTime2"];
if (result["DeliveryTime3"])
sp[2].innerHTML = result["DeliveryTime3"];
if (result["DeliveryTime4"])
sp[3].innerHTML = result["DeliveryTime4"];
}
catch(e)
{
ResetLabelsForSlider("SpeedWrapper", speedLabels);
}
if (result["TotalPrice"])
{
j('#TotalPrice').html(result["TotalPrice"] + " " + currency);
}
}
else
{
j('#DeliveryTime').html("");
if (result["Error"])
{
j("#ErrQuote").html(GenerateIndexError(result["Error"]));
}
else
{
j("#ErrQuote").html("");
}
j('#TotalPrice').html("");
ResetLabelsForSlider("SpeedWrapper", speedLabels);
}
HideLoading();
SetQuoteBlock();
},
true
);
}
function AddUploadedFile(fileName, sym, wd, ln)
{
ResetLabelsForSlider("SpeedWrapper", speedLabels);
var input = document.createElement("input");
input.type='hidden';
input.name='OrigFile[]';
input.value=fileName;
if(j("#Short").val())
fileName = AddSpaces(fileName, 30);
else
fileName = AddSpaces(fileName, 60);
AddRow(GetTranslation("file-prefix") + fileName, ln, input);
Recalculate();
}
function AddErrorFile(fileName, error)
{
AddRow(GetTranslation("file-prefix") + fileName+":: Error", error, '');
Recalculate();
}
function AddText(btn)
{
if (j("textarea[name='OrigTextArea']").data("busy") == 1)
{
HideLoading();
return;
}
j("textarea[name='OrigTextArea']").data("busy", 1);
var txt = btn.form.elements["OrigTextArea"].value;
if (txt.length == 0 || txt == def)
{
HideLoading();
j("textarea[name='OrigTextArea']").data("busy", 0);
jAlert(GetTranslation("error-enter-text"), "");
return;
}
ResetLabelsForSlider("SpeedWrapper", speedLabels);
var sid = j("#UniqID").val();
JsHttpRequest.query(
Path + 'ecommerce/ajax.php',
{
'Action': "UploadText",
'SID': sid,
'Text': txt
},
function(result, errors)
{
if (!result) { j("textarea[name='OrigTextArea']").data("busy", 0); jAlert('error', ""); return;}
if (result['Answer'])
{
btn.form.elements["OrigTextArea"].value = def;
j("textarea[name='OrigTextArea']").data("busy", 0);
var input = document.createElement("input");
input.type='hidden';
input.name='OrigText[]';
input.value=txt;
AddRow(GetTranslation("text-prefix") + txt.substr(0, 30)+"...", Math.ceil(txt.length/55), input);
Recalculate();
}
},
true
);
}
function RemoveRow(lnk)
{
ResetLabelsForSlider("SpeedWrapper", speedLabels);
var next = j(lnk).next("input");
var name = next.attr("name");
var sid = j("#UniqID").val();
var chunc = name.split("[");
var orderItemID = parseInt(chunc[1]);
if (name && name.substr(0, 8) == "OrigFile")
{
JsHttpRequest.query(
Path + 'ecommerce/ajax.php',
{
'Action': "RemoveFile",
'SID': sid,
'FileName': next.val(),
'OrderItemID': orderItemID
},
function(result, errors)
{
if (!result) { jAlert('error', ""); return; }
if (result['Answer'])
{
var row = lnk.parentNode.parentNode;
row.parentNode.removeChild(row);
Recalculate();
CalculateQuote(true);
}
},
true
);
}
else
{
JsHttpRequest.query(
Path + 'ecommerce/ajax.php',
{
'Action': "RemoveText",
'SID': sid,
'Text': next.val(),
'OrderItemID': orderItemID
},
function(result, errors)
{
if (!result) { jAlert('error', ""); return; }
if (result['Answer'])
{
var row = lnk.parentNode.parentNode;
row.parentNode.removeChild(row);
Recalculate();
CalculateQuote(true);
}
},
true
);
}
}
function AddRow(c1, c2, ch)
{
var table = document.getElementById("FormTable");
j('#OrderItemList').css("display", "block");
var clon = j("#EmptyRow").clone().show().removeAttr("id");
var kids = j(clon).children();
j(kids[1]).html(c1);
j(kids[2]).html(c2);
if (typeof ch == 'object')
{
j(kids[0]).append(ch);
}
j('#LastRow').before(j(clon));
if (!j("#Short").val())
{
j(clon).hover(
function() {
j(this).addClass('highlight');
},
function() {
j(this).removeClass('highlight');
});
}
CalculateQuote(true);
HideLoading();
}
function Recalculate()
{
var table = document.getElementById("FormTable");
var total = 0;
for (var i = 0; i < table.rows.length-1; i++)
{
if (Number(table.rows[i].cells[1].innerHTML))
{
total += Number(table.rows[i].cells[1].innerHTML);
}
}
j("#TotalLines").html(total);
}
function LoadCategoryGroup()
{
ResetLabelsForSlider("SpeedWrapper", speedLabels);
var selObj = j("#CategorySelect");
var cat = j(selObj).val();
JsHttpRequest.query(
Path + 'ecommerce/ajax.php',
{
'Action': "LoadGategoryItem",
'CategoryID': cat
},
function(result, errors)
{
if (!result) { jAlert('error', ""); return; }
if (result['Content'].length > 1)
{
var style = j(selObj).parent().attr("class");
j('#CategoryItems').html(result['Content']).addClass(style);
j('#CategoryItem').sSelect();
}
else
{
j('#CategoryItems').removeClass("select_big").html("");
}
},
true
);
}
function ResetLabelsForSlider(id, labels)
{
var spans = j('#'+id+' span.ui-slider-label');
if (spans.length > 0 && labels.length > 0)
{
for(i = 0; i < spans.length; i++)
{
try
{
j(spans[i]).html(labels[i]);
}
catch(e){j(spans[i]).html("")}
}
}
}
function ShowLoading()
{
SetButton(true);
j("#pre").show();
}
function HideLoading()
{
j("#pre").hide();
SetButton(false);
}
function ValidateForm()
{
if (j("#Order").attr("disabled"))
return false;
var text = j("#FormTable tbody tr");
if (text && text.length > 2)
{
var langFrom = j("#LangFrom").val();
if (langFrom)
{
var langTo = j("#LangTo").val();
if (langTo)
{
var subjectCategory = j("#CategorySelect").val();
if (subjectCategory)
{
var subject = j("#CategoryItem").val();
if(subject)
{
return true;
}
else
{
jAlert(GetTranslation("error-choose-subject"), "");
return false;
}
}
else
{
jAlert(GetTranslation("error-choose-subject-category"), "");
return false;
}
}
else
{
jAlert(GetTranslation("error-choose-targetlang"),"");
return false;
}
}
else
{
jAlert(GetTranslation("error-choose-sourcelang"), "");
return false;
}
}
else
{
jAlert(GetTranslation("error-enter-text"), "");
return false;
}
}
function AddSpaces(name, symbols)
{
var total = name.length;
if (total > symbols)
{
var arr = new Array();
for (var i = 0; i < total; i=i+symbols)
{
if (total >= i+symbols)
{
tmp = name.substr(i, symbols);
arr.push(tmp);
}
else break;
}
if (total >= i)
{
tmp = name.substring(i, total);
arr.push(tmp);
}
if (arr.length > 0)
name = arr.join(" ");
}
return name;
}
function SetQuoteBlock()
{
JsHttpRequest.query(
Path + 'ecommerce/ajax.php',
{
'Action': "SetQuoteForm",
'Form': document.getElementById('RequestForm')
},
function(result, errors)
{
if (!result)
{
jAlert('error', "");
return;
}
if (result['Content'])
{
j('#QuoteBlock').html(result['Content']);
}
},
true
);
}
function SetButton(hidebutton)
{
if (hidebutton)
{
j("#TotalPrice").html('
');
j("#Order").attr("disabled", true).animate({ opacity: "0.5" }, 400);
}
else
{
j("#Order").animate({ opacity: "1" }, 400);
j("#TotalPrice img").remove();
setTimeout(function(){j("#Order").attr("disabled", false)}, 1000);
}
}