// Refresh Rate is how often you want to refresh the page
// based off the user inactivity.
var refresh_rate = 300; //<-- In seconds, change to your needs
var last_user_action = 0;
var has_focus = false;
var lost_focus_count = 0;
// If the user loses focus on the browser to many times
// we want to refresh anyway even if they are typing.
// This is so we don't get the browser locked into
// a state where the refresh never happens.
var focus_margin = 10;
var focus_field = '';
// Reset the Timer on users last action
function reset() {
last_user_action = 0;
console.log("Reset");
}
function saveFocusField(field_name)
{
if(focus_field != field_name)
{
focus_field = field_name;
}
}
function setGeneratorFocusField()
{
if(focus_field != '' && focus_field != null)
{
document.getElementById(focus_field).focus();
if(focus_field.includes("item"))
{
document.getElementById(focus_field).select();
}
}
}
function windowLostFocus() {
has_focus = false;
lost_focus_count++;
console.log(lost_focus_count + " <~ Lost Focus");
}
// MOBILE ONLY
// This function is called when the screen is tapped outside the vertical menu
// the tap action will close the menu
function collapseMenu()
{
document.getElementById('islbtoggle').checked = '';
}
// The code that checks if the window needs to reload
function refreshCheck() {
var focus = window.onfocus;
if ((last_user_action >= refresh_rate && !has_focus && document.readyState == "complete") || lost_focus_count > focus_margin) {
document.activeElement.blur();
window.location.reload(); // If this is called no reset is needed
reset(); // We want to reset just to make sure the location reload is not called.
}
}
function setDashboardSite(str2, element_id)
{
var UrlString = window.location.search.substring(1);
var UrlArray = UrlString.split('&');
var ssn = '';
var user_id = '';
var app_code = '';
if(UrlArray.length > 0)
{
for(var u = 0; u< UrlArray.length; u++)
{
var KVPair = UrlArray[u].split('=');
if(KVPair[0] == "ssn"){
ssn = KVPair[1];
if(ssn == "")
{
ssn = '';
}
}
if(KVPair[0] == "tok"){
user_id = KVPair[1];
if(user_id == "")
{
user_id = 0;
}
}
if(KVPair[0] == "app_code"){
app_code = KVPair[1];
if(app_code == "")
{
app_code = 0;
}
}
}
}
active_response(ssn, "", str2, "url", element_id, "");
}
function setTitle(){
var domain = window.location.hostname.replace(/^www\./,'');
//window.location.host is subdomain.domain.biz
var pieces = domain.split('.')
var subdomain = pieces[0];
var site_name = pieces[0];
// WELLS - I have to figure out how to get this to be more dynamic so as to not hard code the subdomain check
// if ever the main website for the dashboard system changes, this will be a problem.
if(subdomain == "bluenarwhal")
{
//check if this is a non-sub package
var url_chunks = location.pathname.split('/');
if(url_chunks[1].indexOf('.') > 0)
{
//this is a page...
page = location.pathname.split('/').map(function(v) {return v.replace(/\.(html|php|asp)/, '').replace(/^\w/, function(a) { return a.toUpperCase(); });}).join('');
}
else
{
//this is the subdomain
subdomain = url_chunks[1];
if(typeof url_chunks[2] === 'undefined')
{
page = "index";
}
else
{
lc_page = url_chunks[2].substring(0, url_chunks[2].indexOf('.'));
page = lc_page.charAt(0).toUpperCase()+lc_page.slice(1);
}
}
}
else
{
page = location.pathname.split('/').map(function(v) {return v.replace(/\.(html|php|asp)/, '').replace(/^\w/, function(a) { return a.toUpperCase(); });}).join('');
}
if(page != "Index")
{
document.title = "Blue Narwhal | "+subdomain.replace(/^\w/, function(a) { return a.toUpperCase(); })+ " Portal";
}
else
{
document.title = subdomain.replace(/^\w/, function(a) { return a.toUpperCase(); });
}
}
function executeImagePaste() {
var items = (window.event.clipboardData || window.event.originalEvent.clipboardData || window.event.clipboardData).items;
// find pasted image among pasted items
var blob = null;
for (var i = 0; i < items.length; i++) {
if (items[i].type.indexOf("image") === 0) {
blob = items[i].getAsFile();
}
}
// load image if there is a pasted image
if (blob !== null) {
var reader = new FileReader();
reader.onload = function(event) {
var image_url = event.target.result;
document.getElementById("pastedImage").src = event.target.result;
document.getElementById("pastedImage").setAttribute('style', 'width:200px;');
//store url data to hidden input
var image_array = (event.target.result).match(/.{1,900000}/g);
for(var x=0; x <= image_array.length; x++)
{
document.getElementById("pasted_image"+x).value = image_array[x];
}
};
reader.readAsDataURL(blob);
}
}
function setPageContent(){
var SearchString = window.location.search.substring(1);
var VariableArray = SearchString.split('&');
var pgid="1";
var editing="";
var draft="";
var doc_type="";
var contact="";
var build_page="";
var ssn = '';
var prevpg = '';
//setDraggable();
if(VariableArray.length > 0)
{
show_modal = "";
alert = "";
added = "";
current_site = "";
stsearch = "";
stid = "";
width = window.screen.width;
for(var i = 0; i < VariableArray.length; i++){
var KeyValuePair = VariableArray[i].split('=');
if(KeyValuePair[0] == "tok"){
user_id = KeyValuePair[1];
if(user_id == "")
{
user_id = 0;
}
}
if(KeyValuePair[0] == "app_code"){
app_code = KeyValuePair[1];
if(app_code == "")
{
app_code = 0;
}
}
if(KeyValuePair[0] == "pgid"){
pgid = KeyValuePair[1];
if(pgid == ""){
pgid = '1';
}
}
if(KeyValuePair[0] == "prevpg"){
prevpg = KeyValuePair[1];
}
if(KeyValuePair[0] == "edit"){
editing = "&edit="+KeyValuePair[1];
}
if(KeyValuePair[0] == "doc_type"){
doc_type = "&doc_type="+KeyValuePair[1];
}
if(KeyValuePair[0] == "contact"){
contact = "&contact="+KeyValuePair[1];
}
if(KeyValuePair[0] == "build_page"){
if(build_page == ""){
build_page = "&build_page="+KeyValuePair[1];
}
}
if(KeyValuePair[0] == "ssn"){
ssn = KeyValuePair[1];
if(ssn == "")
{
ssn = '';
}
}
if(KeyValuePair[0] == "show_modal"){
show_modal = "&show_modal="+KeyValuePair[1];
}
if(KeyValuePair[0] == "alert"){
alert = "&alert="+KeyValuePair[1];
}
if(KeyValuePair[0] == "added"){
added = "&added="+KeyValuePair[1];
}
if(KeyValuePair[0] == "current_site"){
current_site = "¤t_site="+KeyValuePair[1];
}
if(KeyValuePair[0] == "stsearch"){
stsearch = "&stsearch="+KeyValuePair[1];
}
if(KeyValuePair[0] == "stid"){
stid = "&stid="+KeyValuePair[1];
}
}
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
var xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
if(xmlhttp.responseText.trim().indexOf("redirect:is:local:") > -1)
{
str = xmlhttp.responseText.trim();
redirect_string = str.split(':is:local:')[1];
window.location.assign(redirect_string);
}
else
{
document.body.innerHTML=xmlhttp.responseText;
}
}
}
page = page.replace(/^\w/, function(a) { return a.toLowerCase(); });
xmlhttp.open("GET","create_page.php?width="+width+"&page="+page+"&pgid="+pgid+"&prevpg="+prevpg+"&tok="+user_id+"&ssn="+ssn+"&app_code="+app_code+show_modal+editing+draft+doc_type+contact+alert+added+current_site+stsearch+stid+build_page,true);
xmlhttp.send();
}
function submitByEnterKey(event, button_to_action) {
var code = (event.keyCode ? event.keyCode : event.which);
if (code == 13) {
document.getElementById(button_to_action).click();
}
return;
}
function changeSubcatList(tok, ssn, app_code, category)
{
if (window.XMLHttpRequest)
{
//IE7+, Firefox, Chrome, Opera, Safari
var xmlhttp_subcat_list=new XMLHttpRequest();
}
else
{
//IE6, IE5
var xmlhttp_subcat_list=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp_subcat_list.open("POST","create_page.php", true);
//Send the proper header information along with the request
xmlhttp_subcat_list.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xmlhttp_subcat_list.onreadystatechange=function() {
if (xmlhttp_subcat_list.readyState==4 && xmlhttp_subcat_list.status==200) {
document.getElementById("subcategory_list").innerHTML=xmlhttp_subcat_list.responseText;
}
}
xmlhttp_subcat_list.send("page=index&tok="+tok+"&ssn="+ssn+"&app_code="+app_code+"&func=subcat_change&type="+category);
}
function cancel(pid) {
if (pid=="") {
return;
}
global_date = 0;
global_start_time = 0;
global_end_time = 0;
global_time_unit = 1;
global_unit_type = "per_block";
global_gran = 15;
global_pid = 0;
global_primary = 0;
global_button_clicked = '';
document.getElementById(pid).innerHTML="";
document.getElementById("SD_"+pid).innerHTML="";
return;
}
function calculateDeposit(dest_element, total, percentage)
{
document.getElementById(dest_element).value = (total*(percentage/100)).toFixed(2);
}
var timer;
var loading_closed = 0;
function loading(add_delay) {
loading_closed = 0;
if(add_delay)
{
timer = setTimeout(function()
{
document.getElementById("loading_overlay").style.display = "block";
document.getElementById("loading").style.display = "block";
$("#loading_img").show().each(function() {
this.offsetHeight;
}).prop('src', '//bluenarwhal.com/common/style/loading.gif');
$("#loading_overlay").delay(10000).fadeOut();
$("#loading").delay(10000).fadeOut();
}, 1000);
}
else
{
document.getElementById("loading_overlay").style.display = "block";
document.getElementById("loading").style.display = "block";
$("#loading_img").show().each(function() {
this.offsetHeight;
}).prop('src', '//bluenarwhal.com/common/style/loading.gif');
$("#loading_overlay").delay(10000).fadeOut();
$("#loading").delay(10000).fadeOut();
}
}
function closeLoading() {
document.getElementById("loading_overlay").style.display = "none";
document.getElementById("loading").style.display = "none";
loading_closed = 1;
}
function closeLoginModal(reload,clear_contents)
{
if(clear_contents)
{
document.getElementById("login_modal").innerHTML="";
}
document.getElementById("login_overlay").style.visibility = "hidden";
document.getElementById("login_modal").style.visibility = "hidden";
if(reload)
{
current_href = window.location.href;
current_href = current_href.replace("&alert=true","");
current_href = current_href.replace("&alert=stale","");
current_href = current_href.trim();
window.location.assign(current_href);
}
}
function closeLargeModal(reload,clear_contents)
{
if(clear_contents)
{
document.getElementById("table_modal").innerHTML="";
}
document.getElementById("system_overlay").style.visibility = "hidden";
document.getElementById("table_modal").style.visibility = "hidden";
if(reload)
{
window.location.reload();
}
}
function closeModal(reload,clear_contents)
{
if(clear_contents)
{
document.getElementById("system_modal").innerHTML="";
}
document.getElementById("system_overlay").style.visibility = "hidden";
document.getElementById("system_modal").style.visibility = "hidden";
if(reload)
{
current_href = window.location.href;
current_href = current_href.replace("&alert=true","");
current_href = current_href.replace("&alert=stale","");
current_href = current_href.trim();
window.location.assign(current_href);
}
}
function openModal(content)
{
document.getElementById("system_modal").innerHTML=content;
document.getElementById("system_overlay").style.visibility = "visible";
document.getElementById("system_modal").style.visibility = "visible";
}
var pdfViewer;
function openViewer(url, is_label, tok, ssn, app_code)
{
console.log(url);
key = Math.floor((Math.random()*1000000) +1);
add_authenticators = key;
if(is_label)
{
add_authenticators = "tok="+tok+"&ssn="+ssn+"&app_code="+app_code;
}
if (typeof(pdfViewer) == 'undefined' || pdfViewer.closed) {
//create new, since none is open
pdfViewer = window.open(url+"?"+add_authenticators,'fullsize','left=0,top=0,width=900,height=600,directories=no, titlebar=no, status=no, menubar=no, scrollbars=yes, resizable=yes,toolbar=no');
if (pdfViewer == null || typeof(pdfViewer)=='undefined') {
document.getElementById("system_overlay").style.visibility = "visible";
document.getElementById("system_modal").style.visibility = "visible";
document.getElementById("system_modal").style.height = "190px";
document.getElementById("system_modal").innerHTML= "
Cannot display the document.
Try disabling your pop-up blocker.
Don't have a PDF reader?
Get the Adobe Reader here
";
document.getElementById('system_modal').style.top = (((screen.height - $(system_modal).outerHeight()) / 2) + $(window).scrollTop() + "px");
}
}
else {
pdfViewer.close();
pdfViewer = window.open(url+"?"+add_authenticators,'fullsize','left=0,top=0,width=900,height=600,directories=no, titlebar=no, status=no, menubar=no, scrollbars=yes, resizable=yes,toolbar=no');
if (pdfViewer == null || typeof(pdfViewer)=='undefined') {
document.getElementById("system_overlay").style.visibility = "visible";
document.getElementById("system_modal").style.visibility = "visible";
document.getElementById("system_modal").style.height = "190px";
document.getElementById("system_modal").innerHTML= "
Cannot display the document.
Try disabling your pop-up blocker.
Don't have a PDF reader?
Get the Adobe Reader here
";
document.getElementById('system_modal').style.top = (((screen.height - $(system_modal).outerHeight()) / 2) + $(window).scrollTop() + "px");
}
}
}
function active_response(ssn, str1, str2, type, element_id, package_id)
{
str1 = str1.replace(new RegExp("#", "g"), '!');
str1 = str1.replace(/\+/g, '!');
if(type == "pwd")
{
document.getElementById("confirm_pwd").value = "";
document.getElementById("pwd_verify").innerHTML = " * ";
}
if (window.XMLHttpRequest)
{
//IE7+, Firefox, Chrome, Opera, Safari
var xmlhttp2=new XMLHttpRequest();
}
else
{
//IE6, IE5
var xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp2.open("POST","create_page.php", true);
//Send the proper header information along with the request
xmlhttp2.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xmlhttp2.onreadystatechange=function() {
if (xmlhttp2.readyState==4 && xmlhttp2.status==200) {
if(element_id != '')
{
if(type == "url")
{
document.getElementById(element_id).src=xmlhttp2.responseText;
}
else
{
document.getElementById(element_id).innerHTML=xmlhttp2.responseText;
}
}
}
}
xmlhttp2.send("page="+page+"&tok="+user_id+"&app_code="+app_code+"&ssn="+ssn+"&func=active_response&str1="+str1+"&str2="+str2+"&type="+type+"&pkid="+package_id+"&element_id="+element_id);
}
function showDescription(element_id)
{
current_visibility = document.getElementById(element_id).style.visibility;
if(current_visibility == "hidden")
{
document.getElementById(element_id+'_tag').innerHTML = "HIDE DETAILS";
document.getElementById(element_id).style.visibility = "visible";
document.getElementById(element_id).style.height = "auto";
}
else
{
document.getElementById(element_id+'_tag').innerHTML = "SHOW DETAILS";
document.getElementById(element_id).style.visibility = "hidden";
document.getElementById(element_id).style.height = "5px";
}
return;
}
function toggleButton(identifier)
{
current_display = document.getElementById(identifier).style.display;
if(current_display == 'none')
{
document.getElementById(identifier).style.display="block";
document.getElementById(identifier).style.height="100%";
document.getElementById("button_"+identifier).className = "toggle_button_minus";
}
else
{
document.getElementById(identifier).style.display="none";
document.getElementById(identifier).style.height="0";
document.getElementById("button_"+identifier).className = "toggle_button_plus";
}
}
function replaceDangerChars(data)
{
if(typeof data == 'string')
{
data = data.replace(/\@/g,'%40');
data = data.replace(/\#/g,'%23');
data = data.replace(/\$/g,'%24');
data = data.replace(/\^/g,'%5E');
data = data.replace(/\&/g,'%26');
data = data.replace(/\=/g,'%3D');
data = data.replace(/\+/g,'%2B');
data = data.replace(/\"/g,'');
data = data.replace(/\{/g,'');
data = data.replace(/\}/g,'');
data = data.replace(/\;/g,':');
}
return data;
}
function dynamic_details(ssn, action_name, sub_id, data1, data2, data3, data4, data5, data6, data7, data8, data9, data10, data11, data12)
{
// data1 = replaceDangerChars(data1);
// data2 = replaceDangerChars(data2);
// data3 = replaceDangerChars(data3);
// data4 = replaceDangerChars(data4);
// data5 = replaceDangerChars(data5);
// data6 = replaceDangerChars(data6);
// data7 = replaceDangerChars(data7);
// data8 = replaceDangerChars(data8);
// data9 = replaceDangerChars(data9);
// data10 = replaceDangerChars(data10);
// data11 = replaceDangerChars(data11);
// data12 = replaceDangerChars(data12);
// console.log(ssn+", "+action_name+", "+sub_id+", "+data1+", "+data2+", "+data3+", "+data4+", "+data5+", "+data6+", "+data7+", "+data8+", "+data9+", "+data10+", "+data11+", "+data12);
if(data2 == 'notes' || data2 == 'EMAIL CUSTOMER DOC' || data4 == 'notes' || data4 == 'design_notes' )
{
data3 = data3.replace(new RegExp("[+]", "g"), 'plsvar');
}
switch(action_name)
{
case "page_jump":
{
//jump to page id
if(data3=='store')
{
window.location.assign("store_builder.php?tok="+user_id+"&app_code="+app_code+"&ssn="+ssn+"&pgid="+data1+"&prevpg="+data2);
}
break;
}
case "date_chosen":
{
loading(1);
if (data4=="") {
document.getElementById("SD_"+pid).innerHTML="";
return;
}
global_pid = data1;
global_date = data4;
global_start_time = data5;
global_end_time = data6;
global_time_unit = data7;
global_unit_type = data8;
global_gran = data9;
global_primary = data10;
break;
}
case "prov_state_list":
case "prov_state_chosen":
case "res_data":
case "choose_customer":
case "customer":
case "add_item":
case "edit_tn":
case "add_design":
case "add_res_email":
case "add_design_image":
case "update_tax":
case "update_info":
case "web_requests":
case "refresh_todo_list":
case "update_todo_item":
case "update_job_status":
case "save_product_field":
case "save_inventory_field":
case "display_calendar":
break;
case "generate_quote":
break;
case "view_pdf":
case "print_data":
{
loading(0);
break;
}
default:
loading(1);
break;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
var xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("POST","create_page.php",true);
//Send the proper header information along with the request
xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
if(xmlhttp.responseText.trim() == "logout")
{
window.location.reload();
}
else
{
switch(action_name)
{
case "view_box":
case "doc_search":
{
document.getElementById("view_box").innerHTML=xmlhttp.responseText;
$('html, body').animate({scrollTop: 10}, 500);
break;
}
case "bus_verification":
case "bus_renewal":
case "bus_upgrade":
case "user_profile":
{
document.getElementById("myaccount-content-div").innerHTML=xmlhttp.responseText;
break;
}
case "validate_pilot_code":
case "regen_cart":
{
window.location.reload();
break;
}
case "registration_form":
case "confirm_view":
{
if(xmlhttp.responseText.trim() == "ppbyp")
{
window.location.assign("welcome.php?tok="+user_id+"&app_code="+app_code+"&ssn="+ssn);
}
else
{
document.getElementById("registration_form").style.display = "block";
document.getElementById("registration_overlay").style.display = "block";
if(action_name == "registration_form")
{
packages = document.getElementsByClassName("join-cell");
var i;
for(i=0; i= 7)
{
old_add =parseInt(data1) - 1;
//this is an error
//shouldn't have a + sign to begin with
document.getElementById("add_button"+param2+"_"+old_add).style.visibility = "hidden";
break;
}
var param2 ="";
if(data2 != '')
{
param2 = "_"+data2;
}
old_add = parseInt(data1)-1;
document.getElementById("time"+sub_id).style.visibility = "visible";
document.getElementById("active"+sub_id).value=1;
document.getElementById("add_button"+param2+"_"+old_add).style.visibility = "hidden";
document.getElementById("add_button"+param2+"_"+old_add).setAttribute("disabled","disabled");
if(parseInt(data1) < 7)
{
prev_add = parseInt(data1)-1;
next_add = parseInt(data1)+1;
if(document.getElementById("time"+param2+"_"+next_add).style.visibility == "hidden")
{
document.getElementById("add_button"+param2+"_"+data1).style.visibility = "visible";
document.getElementById("add_button"+param2+"_"+data1).removeAttribute("disabled");
}
}
break;
case "remove_time":
if(parseInt(data1) <= 1)
{
//this is an error
break;
}
var param2 ="";
if(data2 != '')
{
param2 = "_"+data2;
}
old_add = parseInt(data1)-1;
next_add = parseInt(data1)+1;
document.getElementById("time"+sub_id).style.visibility = "hidden";
document.getElementById("active"+sub_id).value=0;
if(next_add <8)
{
if(document.getElementById("time"+param2+"_"+next_add).style.visibility == "hidden")
{
var hidden = 1;
while(hidden)
{
if(document.getElementById("time"+param2+"_"+old_add).style.visibility == "hidden")
{
old_add --;
if(old_add <=1)
{
//kick out
hidden = 0;
document.getElementById("add_button"+param2+"_1").style.visibility = "visible";
document.getElementById("add_button"+param2+"_1").removeAttribute("disabled");
}
}
else
{
document.getElementById("add_button"+param2+"_"+old_add).style.visibility = "visible";
document.getElementById("add_button"+param2+"_"+old_add).removeAttribute("disabled");
hidden = 0;
}
}
}
else
{
//check if the previous add is hidden
var hidden = 1;
while(hidden)
{
if(document.getElementById("time"+param2+"_"+old_add).style.visibility == "hidden")
{
old_add --;
if(old_add <=1)
{
//kick out
hidden = 0;
document.getElementById("add_button"+param2+"_1").style.visibility = "visible";
document.getElementById("add_button"+param2+"_1").removeAttribute("disabled");
}
}
else
{
//unhide it
document.getElementById("add_button"+param2+"_"+old_add).style.visibility = "visible";
document.getElementById("add_button"+param2+"_"+old_add).removeAttribute("disabled");
hidden = 0;
}
}
}
}
else
{
var hidden = 1;
while(hidden)
{
//find the next unhidden time
if(document.getElementById("time"+param2+"_"+old_add).style.visibility != "hidden")
{
document.getElementById("add_button"+param2+"_"+old_add).style.visibility = "visible";
document.getElementById("add_button"+param2+"_"+old_add).removeAttribute("disabled");
hidden = 0;
}
else
{
old_add --;
if(old_add <=1)
{
//kick out
hidden = 0;
document.getElementById("add_button"+param2+"_1").style.visibility = "visible";
document.getElementById("add_button"+param2+"_1").removeAttribute("disabled");
}
}
}
}
document.getElementById("add_button"+param2+"_"+data1).style.visibility = "hidden";
break;
default:
{
document.getElementById(action_name+sub_id).innerHTML=xmlhttp.responseText;
break;
}
}
if(action_name.includes("_listing"))
{
$('html, body').animate({scrollTop: $("#"+action_name+sub_id).offset().top - 60}, 500);
}
}
clearTimeout(timer);
closeLoading();
}
}
if(((typeof data3 != "undefined") && (typeof data3.valueOf() == "string")) && (data3.length > 0))
{
data3 = encodeChars(data3);
}
if(((typeof data4 != "undefined") && (typeof data4.valueOf() == "string")) && (data4.length > 0))
{
data4 = encodeChars(data4);
}
if(((typeof data6 != "undefined") && (typeof data6.valueOf() == "string")) && (data6.length > 0))
{
data6 = encodeChars(data6);
}
xmlhttp.send("page="+page+"&tok="+user_id+"&ssn="+ssn+"&func=dynamic_details&name="+action_name+"&sub="+sub_id+"&d1="+data1+"&d2="+data2+"&d3="+encodeURIComponent(data3)+"&d4="+data4+"&d5="+data5+"&d6="+data6+"&d7="+data7+"&d8="+data8+"&d9="+data9+"&d10="+data10+"&d11="+data11+"&d12="+data12);
}
function downloadCSV(csv, filename) {
var csvFile;
var downloadLink;
// CSV file
csvFile = new Blob([csv], {type: "text/csv"});
// Download link
downloadLink = document.createElement("a");
// File name
downloadLink.download = filename;
// Create a link to the file
downloadLink.href = window.URL.createObjectURL(csvFile);
// Hide download link
downloadLink.style.display = "none";
// Add the link to DOM
document.body.appendChild(downloadLink);
// Click download link
downloadLink.click();
}
function exportTableToCSV(filename, table_name) {
var csv = [];
var rows = document.querySelectorAll("table."+table_name+" tr");
for (var i = 0; i < rows.length; i++) {
var row = [], cols = rows[i].querySelectorAll("td, th");
for (var j = 0; j < cols.length; j++)
row.push('"'+cols[j].innerText+'"');
csv.push(row.join(","));
}
// Download CSV file
downloadCSV(csv.join("\n"), filename);
}
function encodeChars(text) {
var map = {
'&': 'mnbamp',
'<': 'mnbpb',
'>': 'mnbgb',
'"': 'dblqu',
"'": 'sglqu'
};
return text.replace(/[&<>"']/g, function(m) { return map[m]; });
}
function previewFile(img_id, event)
{
var image = document.getElementById(img_id);
image.src = URL.createObjectURL(event.target.files[0]);
return;
}
function frameOn(page_content){
builder_frame.document.designMode = 'On';
window.frames['builder_frame'].document.body.innerHTML = page_content;
var cssLink = document.createElement("link")
cssLink.href = "style/style.php";
cssLink .rel = "stylesheet";
cssLink .type = "text/css";
builder_frame.document.body.appendChild(cssLink);
builder_frame.document.body.style.backgroundColor = "#ffffff";
}
var bold_active = 0;
function addBold(){
builder_frame.document.execCommand('bold',false,null);
builder_frame.focus();
}
function addUnderline(){
builder_frame.document.execCommand('underline',false,null);
builder_frame.focus();
}
function addItalic(){
builder_frame.document.execCommand('italic',false,null);
builder_frame.focus();
}
function addHeading(){
builder_frame.document.execCommand("insertHTML", false, ""+ builder_frame.document.getSelection()+"");
builder_frame.focus();
}
function addSubheading(){
builder_frame.document.execCommand("insertHTML", false, ""+ builder_frame.document.getSelection()+"");
builder_frame.focus();
}
function addContent(){
builder_frame.document.execCommand("insertHTML", false, ""+ builder_frame.document.getSelection()+"");
builder_frame.focus();
}
function justifyCenter(){
builder_frame.document.execCommand("justifyCenter",false,null);
builder_frame.focus();
}
function justifyLeft(){
builder_frame.document.execCommand("justifyLeft",false,null);
builder_frame.focus();
}
function justifyRight(){
builder_frame.document.execCommand("justifyRight",false,null);
builder_frame.focus();
}
function setAccentColour(accent){
builder_frame.document.execCommand('ForeColor',false,accent);
builder_frame.focus();
}
function iHorizontalRule(){
builder_frame.document.execCommand('inserthorizontalrule',false,null);
builder_frame.focus();
}
function iOrderedList(){
builder_frame.document.execCommand("InsertOrderedList", false,"newOL");
$("#builder_frame").contents().find("ol").attr("style", "padding-left:50px;");
$("#builder_frame").contents().find("ol").attr("align", "left");
builder_frame.focus();
}
function iUnorderedList(){
builder_frame.document.execCommand("InsertUnorderedList", false,"newUL");
$("#builder_frame").contents().find("ul").attr("style", "padding-left:50px;");
$("#builder_frame").contents().find("ul").attr("align", "left");
builder_frame.focus();
}
function iLink(){
var linkURL = prompt("Enter the URL for this link:", "//");
builder_frame.document.execCommand("CreateLink", false, linkURL);
builder_frame.focus();
}
function iUnLink(){
builder_frame.document.execCommand("Unlink", false, null);
builder_frame.focus();
}
var wysiwyg_font_size = 2;
function iPlusSize()
{
wysiwyg_font_size++;
if(wysiwyg_font_size > 7){wysiwig_font_size=7;}
builder_frame.document.execCommand("fontSize", false, wysiwyg_font_size);
var all_font_elements = builder_frame.document.getElementsByTagName("font");
for (var i = 0, len = all_font_elements.length; i < len; ++i) {
switch(all_font_elements[i].size)
{
case "1":
all_font_elements[i].removeAttribute("size");
all_font_elements[i].style.fontSize = "10px";
break;
case "2":
all_font_elements[i].removeAttribute("size");
all_font_elements[i].style.fontSize = "12px";
break;
case "3":
all_font_elements[i].removeAttribute("size");
all_font_elements[i].style.fontSize = "18px";
break;
case "4":
all_font_elements[i].removeAttribute("size");
all_font_elements[i].style.fontSize = "22px";
break;
case "5":
all_font_elements[i].removeAttribute("size");
all_font_elements[i].style.fontSize = "30px";
break;
case "6":
all_font_elements[i].removeAttribute("size");
all_font_elements[i].style.fontSize = "35px";
break;
case "7":
all_font_elements[i].removeAttribute("size");
all_font_elements[i].style.fontSize = "40px";
break;
}
}
builder_frame.focus();
}
function iMinusSize()
{
wysiwyg_font_size--;
if(wysiwyg_font_size < 1){wysiwig_font_size=1;}
builder_frame.document.execCommand("fontSize", false, wysiwyg_font_size);
var all_font_elements = builder_frame.document.getElementsByTagName("font");
for (var i = 0, len = all_font_elements.length; i < len; ++i) {
switch(all_font_elements[i].size)
{
case "7":
all_font_elements[i].removeAttribute("size");
all_font_elements[i].style.fontSize = "40px";
break;
case "6":
all_font_elements[i].removeAttribute("size");
all_font_elements[i].style.fontSize = "35px";
break;
case "5":
all_font_elements[i].removeAttribute("size");
all_font_elements[i].style.fontSize = "30px";
break;
case "4":
all_font_elements[i].removeAttribute("size");
all_font_elements[i].style.fontSize = "22px";
break;
case "3":
all_font_elements[i].removeAttribute("size");
all_font_elements[i].style.fontSize = "18px";
break;
case "2":
all_font_elements[i].removeAttribute("size");
all_font_elements[i].style.fontSize = "12px";
break;
case "1":
all_font_elements[i].removeAttribute("size");
all_font_elements[i].style.fontSize = "10px";
break;
}
}
builder_frame.focus();
}
function iImage(){
var imgSrc = prompt('Enter image location', '');
if(imgSrc != null){
builder_frame.document.execCommand('insertimage', false, imgSrc);
$("#builder_frame").contents().find("img").attr("width", "95%");
}
builder_frame.focus();
}
// DRAGGABLE MODAL WINDOW
function setDraggable()
{
var x, y, target = null;
document.addEventListener('mousedown', function(e) {
var clickedDragger = false;
for(var i = 0; e.path[i] !== document.body; i++) {
if (e.path[i].classList.contains('dragger')) {
clickedDragger = true;
}
else if (clickedDragger && e.path[i].classList.contains('modal')) {
target = e.path[i];
target.classList.add('dragging');
x = e.clientX - target.style.left.slice(0, -2);
y = e.clientY - target.style.top.slice(0, -2);
return;
}
}
});
document.addEventListener('mouseup', function() {
if (target !== null) target.classList.remove('dragging');
target = null;
});
document.addEventListener('mousemove', function(e) {
if (target === null) return;
target.style.left = e.clientX - x + 'px';
target.style.top = e.clientY - y + 'px';
var pRect = target.parentElement.getBoundingClientRect();
var tgtRect = target.getBoundingClientRect();
if (tgtRect.left < pRect.left) target.style.left = 0;
if (tgtRect.top < pRect.top) target.style.top = 0;
if (tgtRect.right > pRect.right) target.style.left = pRect.width - tgtRect.width + 'px';
if (tgtRect.bottom > pRect.bottom) target.style.top = pRect.height - tgtRect.height + 'px';
});
}
// END DRAGGABLE MODAL WINDOW
// JavaScript Document