scrigo.js.php 26.1 KB
Newer Older
1 2 3
<?php
	session_start();
	include('../../lib/config.inc.php');
4
    header('Content-Type: text/javascript; charset=utf-8'); // the config file sets the content type header so we have to override it here!
5
	require_once('../../lib/app.inc.php');
6 7
	$lang = (isset($_SESSION['s']['language']) && $_SESSION['s']['language'] != '')?$_SESSION['s']['language']:'en';
	include_once(ISPC_ROOT_PATH.'/web/strengthmeter/lib/lang/'.$lang.'_strengthmeter.lng');
8 9 10
	
	$app->uses('ini_parser,getconf');
	$server_config_array = $app->getconf->get_global_config();
11
?>
mcramer's avatar
mcramer committed
12 13 14 15 16
var pageFormChanged = false;
var tabChangeWarningTxt = '';
var tabChangeDiscardTxt = '';
var tabChangeWarning = false;
var tabChangeDiscard = false;
17 18 19 20
var requestsRunning = 0;
var indicatorPaddingH = -1;
var indicatorPaddingW = -1;
var indicatorCompleted = false;
21 22
redirect = '';

23 24 25 26 27 28 29 30
function reportError(request) {
	/* Error reporting is disabled by default as some browsers like safari 
	   sometimes throw errors when a ajax request is delayed even if the 
	   ajax request worked. */
	   
	/*alert(request);*/
}

31 32 33 34
function resetFormChanged() {
    pageFormChanged = false;
}

35
function showLoadIndicator() {
36 37
    document.body.style.cursor = 'wait';

38 39 40
<?php
if($server_config_array['misc']['use_loadindicator'] == 'y'){
?>
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    requestsRunning += 1;
    
    if(requestsRunning < 2) {
        var indicator = jQuery('#ajaxloader');
        if(indicator.length < 1) {
            indicator = jQuery('<div id="ajaxloader" style="display: none;"></div>');
            indicator.appendTo('body');
        }
        var parent = jQuery('#content');
        if(parent.length < 1) return;
        indicatorCompleted = false;
        
        var atx = parent.offset().left + 150; //((parent.outerWidth(true) - indicator.outerWidth(true)) / 2);
        var aty = parent.offset().top + 150;
        indicator.css( {'left': atx, 'top': aty } ).fadeIn('fast', function() {
            // check if loader should be hidden immediately
            indicatorCompleted = true;
            if(requestsRunning < 1) $(this).fadeOut('fast', function() { $(this).hide();});
        });
    }
61 62 63
<?php
}
?>
64 65 66
}

function hideLoadIndicator() {
67 68
    document.body.style.cursor = '';

69 70 71 72 73 74 75 76
    requestsRunning -= 1;
    if(requestsRunning < 1) {
        requestsRunning = 0; // just for the case...
        if(indicatorCompleted == true) jQuery('#ajaxloader').fadeOut('fast', function() { jQuery('#ajaxloader').hide(); } );
    }
}

function onAfterContentLoad() {
77 78 79
<?php
if($server_config_array['misc']['use_combobox'] == 'y'){
?>
80
    $('#pageContent').find("select").combobox();
81 82 83
<?php
}
?>
84 85
}

86 87 88
function loadContentRefresh(pagename) {
	
  if(document.getElementById('refreshinterval').value > 0) {
89
	var pageContentObject2 = jQuery.ajax({	type: "GET", 
90
											url: pagename,
91
											data: "refresh="+document.getElementById('refreshinterval').value,
92
											dataType: "html",
93 94 95
											beforeSend: function() {
												showLoadIndicator();
											},
96
											success: function(data, textStatus, jqXHR) {
97
                                                hideLoadIndicator();
98
												jQuery('#pageContent').html(jqXHR.responseText);
99
                                                onAfterContentLoad();
mcramer's avatar
mcramer committed
100
                                                pageFormChanged = false;
101 102
											},
											error: function() {
103
                                                hideLoadIndicator();
104
												reportError('Ajax Request was not successful.'+pagename);
cfoe's avatar
cfoe committed
105
											}
106
										});
107 108 109 110
  	setTimeout( "loadContentRefresh('"+pagename+"&refresh="+document.getElementById('refreshinterval').value+"')", document.getElementById('refreshinterval').value*1000 );
  }
}

111
function capp(module, redirect) {
112 113
	var submitFormObj = jQuery.ajax({		type: "GET", 
											url: "capp.php", 
114
											data: "mod="+module+((redirect != undefined) ? '&redirect='+redirect : ''),
115
											dataType: "html",
116 117 118
											beforeSend: function() {
												showLoadIndicator();
											},
119 120 121 122 123
											success: function(data, textStatus, jqXHR) {
												if(jqXHR.responseText != '') {
													if(jqXHR.responseText.indexOf('HEADER_REDIRECT:') > -1) {
														var parts = jqXHR.responseText.split(':');
														loadContent(parts[1]);
124 125 126
													} else if (jqXHR.responseText.indexOf('URL_REDIRECT:') > -1) {
														var newUrl= jqXHR.responseText.substr(jqXHR.responseText.indexOf('URL_REDIRECT:') + "URL_REDIRECT:".length);
														document.location.href = newUrl;
127
													} else {
128
														//alert(jqXHR.responseText);
129 130 131
													}
												}
												loadMenus();
132
                                                hideLoadIndicator();
133 134
											},
											error: function() {
135
                                                hideLoadIndicator();
136
												reportError('Ajax Request was not successful.'+module);
cfoe's avatar
cfoe committed
137
											}
138
									});
139 140 141 142 143 144 145 146 147 148 149 150 151 152
}

function submitLoginForm(formname) {
    //* Validate form. TODO: username and password with strip();
    var frm = document.getElementById(formname);
    var userNameObj = frm.username;
    if(userNameObj.value == ''){
        userNameObj.focus();
        return;
    }
    var passwordObj = frm.passwort;
    if(passwordObj.value == ''){
        passwordObj.focus();
        return;
153 154 155 156 157 158
    }
	
	$('#dummy_username').val(userNameObj.value);
	$('#dummy_passwort').val(passwordObj.value);
	$('#dummy_login_form').submit();

159 160 161
	var submitFormObj = jQuery.ajax({		type: "POST", 
											url: "content.php",
											data: jQuery('#'+formname).serialize(),
162
											dataType: "html",
163 164 165
											beforeSend: function() {
												showLoadIndicator();
											},
166 167 168 169 170 171 172 173 174 175 176
											success: function(data, textStatus, jqXHR) {
												if(jqXHR.responseText.indexOf('HEADER_REDIRECT:') > -1) {
													var parts = jqXHR.responseText.split(':');
													//alert(parts[1]);
													loadContent(parts[1]);
													//redirect = parts[1];
													//window.setTimeout('loadContent(redirect)', 1000);
												} else if (jqXHR.responseText.indexOf('LOGIN_REDIRECT:') > -1) {
													// Go to the login page
													document.location.href = 'index.php';
												} else {
177
													jQuery('#pageContent').html(jqXHR.responseText);
178
                                                    onAfterContentLoad();
mcramer's avatar
mcramer committed
179
                                                    pageFormChanged = false;
180 181
												}
												loadMenus();
182
                                                hideLoadIndicator();
183 184
											},
											error: function() {
185
                                                hideLoadIndicator();
186
												reportError('Ajax Request was not successful.110');
cfoe's avatar
cfoe committed
187
											}
188
									});
189 190 191 192 193
	/*
	if(redirect != '') {
		loadContent(redirect);
		redirect = '';
	}
194
	document.getElementById('footer').innerHTML = 'Powered by <a href="http://www.ispconfig.org" target="_blank">ISPConfig</a>';
195
	*/
196
	
197 198
}

199
function submitForm(formname,target) {
200 201 202
	var submitFormObj = jQuery.ajax({		type: "POST", 
											url: target,
											data: jQuery('#'+formname).serialize(),
203
											dataType: "html",
204 205 206
											beforeSend: function() {
												showLoadIndicator();
											},
207 208 209 210 211 212 213 214
											success: function(data, textStatus, jqXHR) {
												if(jqXHR.responseText.indexOf('HEADER_REDIRECT:') > -1) {
													var parts = jqXHR.responseText.split(':');
													//alert(parts[1]);
													loadContent(parts[1]);
													//redirect = parts[1];
													//window.setTimeout('loadContent(redirect)', 1000);
												} else {
215
													jQuery('#pageContent').html(jqXHR.responseText);
216
                                                    onAfterContentLoad();
mcramer's avatar
mcramer committed
217
                                                    pageFormChanged = false;
218
												}
219
                                                hideLoadIndicator();
220 221
											},
											error: function(jqXHR, textStatus, errorThrown) {
222
                                                hideLoadIndicator();
223 224
												var parts = jqXHR.responseText.split(':');
												reportError('Ajax Request was not successful. 111');
cfoe's avatar
cfoe committed
225
											}
226
									});
227 228 229 230 231 232 233 234
	/*
	if(redirect != '') {
		loadContent(redirect);
		redirect = '';
	}
	*/
}

235
function submitFormConfirm(formname,target,confirmation) {
236
	var successMessage = arguments[3];
237 238 239 240 241
	if(window.confirm(confirmation)) {
		var submitFormObj = jQuery.ajax({	type: "POST", 
											url: target,
											data: jQuery('#'+formname).serialize(),
											dataType: "html",
242 243 244
											beforeSend: function() {
												showLoadIndicator();
											},
245
											success: function(data, textStatus, jqXHR) {
246
												if(successMessage) alert(successMessage);
247 248 249 250 251 252 253 254
												if(jqXHR.responseText.indexOf('HEADER_REDIRECT:') > -1) {
													var parts = jqXHR.responseText.split(':');
													//alert(parts[1]);
													loadContent(parts[1]);
													//redirect = parts[1];
													//window.setTimeout('loadContent(redirect)', 1000);
												} else {
													jQuery('#pageContent').html(jqXHR.responseText);
255
                                                    onAfterContentLoad();
mcramer's avatar
mcramer committed
256
                                                    pageFormChanged = false;
257
												}
258
                                                hideLoadIndicator();
259 260
											},
											error: function(jqXHR, textStatus, errorThrown) {
261
                                                hideLoadIndicator();
262 263
												var parts = jqXHR.responseText.split(':');
												reportError('Ajax Request was not successful. 111');
cfoe's avatar
cfoe committed
264
											}
265 266 267 268
									});
	}
}

269
function submitUploadForm(formname,target) {		
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
	var handleResponse = function(loadedFrame) {
		var response, responseStr = loadedFrame.contentWindow.document.body.innerHTML;
		
		try {
			response = JSON.parse(responseStr);
		} catch(e) {
			response = responseStr;
		}
		var msg = '';
		var okmsg = jQuery('#OKMsg',response).html();
		if(okmsg){
			msg = '<div id="OKMsg">'+okmsg+'</div>';
		}
		var errormsg = jQuery('#errorMsg',response).html();
		if(errormsg){
			msg = msg+'<div id="errorMsg">'+errormsg+'</div>';
		}
		return msg;
		
    };
	
	var frame_id = 'ajaxUploader-iframe-' + Math.round(new Date().getTime() / 1000);
	jQuery('body').after('<iframe width="0" height="0" style="display:none;" name="'+frame_id+'" id="'+frame_id+'"/>');
293
	jQuery('input[type="file"]').closest("form").attr({target: frame_id, action: target}).submit();
294 295 296 297 298
	jQuery('#'+frame_id).load(function() {
        var msg = handleResponse(this);
		jQuery('#errorMsg').remove();
		jQuery('#OKMsg').remove();
		jQuery('input[name="id"]').before(msg);
299
		jQuery(this).remove();
300 301
      });

302 303 304 305 306 307 308 309 310
	/*
	if(redirect != '') {
		loadContent(redirect);
		redirect = '';
	}
	*/
}

function loadContent(pagename) {
mcramer's avatar
mcramer committed
311
  var params = arguments[1];
312 313
  var pageContentObject2 = jQuery.ajax({	type: "GET", 
											url: pagename,
mcramer's avatar
mcramer committed
314
                                            data: (params ? params : null),
315
											dataType: "html",
316
											beforeSend: function() {
317
												showLoadIndicator();
318
											},
319 320 321 322 323 324 325 326
											success: function(data, textStatus, jqXHR) {
												if(jqXHR.responseText.indexOf('HEADER_REDIRECT:') > -1) {
													var parts = jqXHR.responseText.split(':');
													loadContent(parts[1]);
												} else if (jqXHR.responseText.indexOf('URL_REDIRECT:') > -1) {
													var newUrl= jqXHR.responseText.substr(jqXHR.responseText.indexOf('URL_REDIRECT:') + "URL_REDIRECT:".length);
													document.location.href = newUrl;
												} else {
327 328 329 330
													//document.getElementById('pageContent').innerHTML = jqXHR.responseText;
													//var reponse = jQuery(jqXHR.responseText);
													//var reponseScript = reponse.filter("script");
													//jQuery.each(reponseScript, function(idx, val) { eval(val.text); } );
331
													
332
													jQuery('#pageContent').html(jqXHR.responseText);
333
                                                    onAfterContentLoad();
mcramer's avatar
mcramer committed
334
                                                    pageFormChanged = false;
335
												}
336
                                                hideLoadIndicator();
337 338
											},
											error: function() {
339
                                                hideLoadIndicator();
340
												reportError('Ajax Request was not successful. 113');
cfoe's avatar
cfoe committed
341
											}
342
									});
343 344 345 346
}


function loadInitContent() {
347 348 349
	var pageContentObject = jQuery.ajax({	type: "GET", 
											url: "content.php",
											data: "s_mod=login&s_pg=index",
350
											dataType: "html",
351 352 353
											beforeSend: function() {
												showLoadIndicator();
											},
354 355 356 357 358
											success: function(data, textStatus, jqXHR) {
												if(jqXHR.responseText.indexOf('HEADER_REDIRECT:') > -1) {
													var parts = jqXHR.responseText.split(":");
													loadContent(parts[1]);
												} else {
359
													jQuery('#pageContent').html(jqXHR.responseText);
360
                                                    onAfterContentLoad();
mcramer's avatar
mcramer committed
361
                                                    pageFormChanged = false;
362
												}
363
                                                hideLoadIndicator();
364 365
											},
											error: function() {
366
                                                hideLoadIndicator();
367
												reportError('Ajax Request was not successful. 114');
cfoe's avatar
cfoe committed
368
											}
369
										});
370 371 372 373 374 375 376 377
  
  loadMenus();
  keepalive();
  setTimeout("setFocus()",1000);

}

function setFocus() {
378
	try {
379
		jQuery('form#pageForm').find('input[name="username"]').focus();
380 381
	} catch (e) {
	}
382 383 384 385
}


function loadMenus() {
386 387 388
  var sideNavObject = jQuery.ajax({			type: "GET", 
											url: "nav.php",
											data: "nav=side",
389
											dataType: "html",
390 391 392
											beforeSend: function() {
												showLoadIndicator();
											},
393
											success: function(data, textStatus, jqXHR) {
394
                                                hideLoadIndicator();
395
												jQuery('#sideNav').html(jqXHR.responseText);
396 397
											},
											error: function() {
398
                                                hideLoadIndicator();
399
												reportError('Ajax Request was not successful. 115');
cfoe's avatar
cfoe committed
400
											}
401
									});
402
	
403 404 405
  var topNavObject = jQuery.ajax({			type: "GET", 
											url: "nav.php",
											data: "nav=top",
406
											dataType: "html",
407 408 409
											beforeSend: function() {
												showLoadIndicator();
											},
410
											success: function(data, textStatus, jqXHR) {
411
                                                hideLoadIndicator();
412
												jQuery('#topNav').html(jqXHR.responseText);
413 414
											},
											error: function(o) {
415
                                                hideLoadIndicator();
416
												reportError('Ajax Request was not successful. 116');
cfoe's avatar
cfoe committed
417
											}
418
								});
419 420 421

}

422
function changeTab(tab,target,force) {
423 424
	//document.forms[0].next_tab.value = tab;
	document.pageForm.next_tab.value = tab;
mcramer's avatar
mcramer committed
425
    
426 427 428
    var idel = jQuery('form#pageForm').find('[name="id"]');
    var id = null;
    if(idel.length > 0) id = idel.val();
429
    if(tabChangeDiscard == 'y' && !force) {
430
        if((idel.length < 1 || id) && (pageFormChanged == false || window.confirm(tabChangeDiscardTxt))) {
mcramer's avatar
mcramer committed
431
            var next_tab = tab;
432 433
            if(id) loadContent(target, {'next_tab': next_tab, 'id': id});
            else loadContent(target, {'next_tab': next_tab});
mcramer's avatar
mcramer committed
434 435 436 437 438 439 440 441 442
        } else {
            return false;
        }
    } else {
        if(id && tabChangeWarning == 'y' && pageFormChanged == true) {
            if(window.confirm(tabChangeWarningTxt)) {
                submitForm('pageForm', target);
            } else {
                var next_tab = tab;
443 444
                if(id) loadContent(target, {'next_tab': next_tab, 'id': id});
                else loadContent(target, {'next_tab': next_tab});
mcramer's avatar
mcramer committed
445 446 447 448 449
            }
        } else {
            submitForm('pageForm',target);
        }
    }
450 451 452 453 454 455 456 457
}
	
function del_record(link,confirmation) {
  if(window.confirm(confirmation)) {
          loadContent(link);
  }
}

458 459 460 461 462 463
function confirm_action(link,confirmation) {
  if(window.confirm(confirmation)) {
          loadContent(link);
  }
}

464
function loadContentInto(elementid,pagename) {
465 466
  var pageContentObject2 = jQuery.ajax({	type: "GET", 
											url: pagename,
467
											dataType: "html",
468 469 470
											beforeSend: function() {
//												showLoadIndicator();
											},
471
											success: function(data, textStatus, jqXHR) {
472
//                                                hideLoadIndicator();
473
												jQuery('#'+elementid).html(jqXHR.responseText);
474 475
											},
											error: function() {
476
//                                                hideLoadIndicator();
477
												reportError('Ajax Request was not successful. 118');
cfoe's avatar
cfoe committed
478
											}
479
										});
480 481
}

482
function loadOptionInto(elementid,pagename) {
483 484
	var pageContentObject2 = jQuery.ajax({	type: "GET", 
											url: pagename,
485
											dataType: "html",
486 487 488
											beforeSend: function() {
//												showLoadIndicator();
											},
489
											success: function(data, textStatus, jqXHR) {
490
//                                                hideLoadIndicator();
491 492 493 494 495 496 497 498 499 500 501 502 503
												var teste = jqXHR.responseText;
												var elemente = teste.split('#');
												el=document.getElementById(elementid);
												el.innerHTML='';
												for (var i = 0; i < elemente.length; ++i){

													var foo2 = document.createElement("option");
													foo2.appendChild(document.createTextNode(elemente[i]));
													foo2.value=elemente[i];
													el.appendChild(foo2);
												}
											},
											error: function() {
504
//                                                hideLoadIndicator();
505
												reportError('Ajax Request was not successful. 119');
cfoe's avatar
cfoe committed
506
											}
507
										});
508 509
}

510
function keepalive() {
511 512
	var pageContentObject3 = jQuery.ajax({	type: "GET", 
											url: "keepalive.php",
513
											dataType: "html",
514 515 516 517 518
											success: function(data, textStatus, jqXHR) {
												setTimeout( keepalive, 1000000 );
											},
											error: function() {
												reportError('Session expired. Please login again.');
cfoe's avatar
cfoe committed
519
											}
520
										});
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
  	//setTimeout( keepalive, 1000000 );
}



var pass_minimum_length = 5;
var pass_messages = new Array();

var pass_message = new Array();
pass_message['text'] = "<?php echo $wb['password_strength_0_txt']?>";
pass_message['color'] = "#d0d0d0";
pass_messages[0] = pass_message;

var pass_message = new Array();
pass_message['text'] = "<?php echo $wb['password_strength_1_txt']?>";
pass_message['color'] = "red";
pass_messages[1] = pass_message;

var pass_message = new Array();
pass_message['text'] = "<?php echo $wb['password_strength_2_txt']?>";
pass_message['color'] = "yellow";
pass_messages[2] = pass_message;

var pass_message = new Array();
pass_message['text'] = "<?php echo $wb['password_strength_3_txt']?>";
pass_message['color'] = "#00ff00";
pass_messages[3] = pass_message;

var pass_message = new Array();
pass_message['text'] = "<?php echo $wb['password_strength_4_txt']?>";
pass_message['color'] = "green";
pass_messages[4] = pass_message;

var pass_message = new Array();
pass_message['text'] = "<?php echo $wb['password_strength_5_txt']?>";
pass_message['color'] = "green";
pass_messages[5] = pass_message;

function pass_check(password) {
	var length = password.length;
	var points = 0;
	if (length < pass_minimum_length) {
		pass_result(0);
		return;
	}
	
	if (length < 5) {
		pass_result(1);
		return;
	}
	
	if (pass_contains(password, "ABCDEFGHIJKLNMOPQRSTUVWXYZ")) {
		points += 1;
	}
	
	if (pass_contains(password, "0123456789")) {
		points += 1;
	}
	
	if (pass_contains(password, "`~!@#$%^&*()_+|\=-[]}{';:/?.>,<\" ")) {
		points += 1;
	}
	
	if (points == 0) {
		if (length >= 5 && length <=6) {
			pass_result(1);
		} else if (length >= 7 && length <=8) {
			pass_result(2);
		} else {
			pass_result(3);
		}
	} else if (points == 1) {
		if (length >= 5 && length <=6) {
			pass_result(2);
		} else if (length >= 7 && length <=10) {
			pass_result(3);
		} else {
			pass_result(4);
		}
	} else if (points == 2) {
		if (length >= 5 && length <=8) {
			pass_result(3);
		} else if (length >= 9 && length <=10) {
			pass_result(4);
		} else {
			pass_result(5);
		}
	} else if (points == 3) {
		if (length >= 5 && length <=6) {
			pass_result(3);
		} else if (length >= 7 && length <=8) {
			pass_result(4);
		} else {
			pass_result(5);
		}
	} else if (points >= 4) {
		if (length >= 5 && length <=6) {
			pass_result(4);
		} else {
			pass_result(5);
		}
	}
}



function pass_result(points, message) {
	if (points == 0) {
		width = 10;
	} else {
		width = points*20;
	}
	document.getElementById("passBar").innerHTML = '<div style="float:left; height: 10px; padding:0px; background-color: ' + pass_messages[points]['color'] + '; width: ' + width + 'px;" />';
	document.getElementById("passText").innerHTML = pass_messages[points]['text'];
}
function pass_contains(pass, check) {
	for (i = 0; i < pass.length; i++) {
		if (check.indexOf(pass.charAt(i)) > -1) {
			return true;
		}
	}
	return false;
}

function addAdditionalTemplate(){
	var tpl_add = document.getElementById('template_additional').value;
647
	
648 649 650 651
	  var tpl_list = document.getElementById('template_additional_list').innerHTML;
	  var addTemplate = document.getElementById('tpl_add_select').value.split('|',2);
	  var addTplId = addTemplate[0];
	  var addTplText = addTemplate[1];
652
	if(addTplId > 0) {
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684
	  var newVal = tpl_add + '/' + addTplId + '/';
	  newVal = newVal.replace('//', '/');
	  var newList = tpl_list + '<br>' + addTplText;
	  newList = newList.replace('<br><br>', '<br>');
	  document.getElementById('template_additional').value = newVal;
	  document.getElementById('template_additional_list').innerHTML = newList;
	  alert('additional template ' + addTplText + ' added to customer');
	} else {
	  alert('no additional template selcted');
	}
}

function delAdditionalTemplate(){
	var tpl_add = document.getElementById('template_additional').value;
	if(tpl_add != '') {
		var tpl_list = document.getElementById('template_additional_list').innerHTML;
		var addTemplate = document.getElementById('tpl_add_select').value.split('|',2);
		var addTplId = addTemplate[0];
		var addTplText = addTemplate[1];
		var newVal = tpl_add;
		newVal = newVal.replace(addTplId, '');
		newVal = newVal.replace('//', '/');
		var newList = tpl_list.replace(addTplText, '');
		newList = newList.replace('<br><br>', '<br>');
		document.getElementById('template_additional').value = newVal;
		document.getElementById('template_additional_list').innerHTML = newList;
		alert('additional template ' + addTplText + ' deleted from customer');
  } else {
  	alert('no additional template selcted');
  }
  
}
685 686 687 688 689 690 691 692 693 694 695

function getInternetExplorerVersion() {
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}
696

697
function password(minLength, special){
698 699 700
	var iteration = 0;
	var password = "";
	var randomNumber;
701 702 703
	minLength = minLength || 10;
	var maxLength = minLength + 5;
	var length = getRandomInt(minLength, maxLength);
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720
	if(special == undefined){
		var special = false;
	}
	while(iteration < length){
		randomNumber = (Math.floor((Math.random() * 100)) % 94) + 33;
		if(!special){
			if ((randomNumber >=33) && (randomNumber <=47)) { continue; }
			if ((randomNumber >=58) && (randomNumber <=64)) { continue; }
			if ((randomNumber >=91) && (randomNumber <=96)) { continue; }
			if ((randomNumber >=123) && (randomNumber <=126)) { continue; }
		}
		iteration++;
		password += String.fromCharCode(randomNumber);
	}
	return password;
}

Falko Timme's avatar
Falko Timme committed
721
function generatePassword(passwordFieldID, repeatPasswordFieldID){
722 723 724 725
	var oldPWField = jQuery('#'+passwordFieldID);
	var newPWField = oldPWField.clone();
	newPWField.attr('type', 'text').attr('id', 'tmp'+passwordFieldID).insertBefore(oldPWField);
	oldPWField.remove();
Falko Timme's avatar
Falko Timme committed
726 727 728
	var pword = password(10, false);
	jQuery('#'+repeatPasswordFieldID).val(pword);
	newPWField.attr('id', passwordFieldID).val(pword).trigger('keyup');
729
}
730

731 732
var funcDisableClick = function(e) { e.preventDefault(); return false; };

733 734 735 736 737 738 739
function checkPassMatch(pwField1,pwField2){
    var rpass = jQuery('#'+pwField2).val();
    var npass = jQuery('#'+pwField1).val();
    if(npass!= rpass) {
		jQuery('#confirmpasswordOK').hide();
        jQuery('#confirmpasswordError').show();
		jQuery('button.positive').attr('disabled','disabled');
740 741 742 743 744 745
        jQuery('.tabbox_tabs ul li a').each(function() {
            var $this = $(this);
            $this.data('saved_onclick', $this.attr('onclick'));
            $this.removeAttr('onclick');
            $this.click(funcDisableClick);
        });
746 747 748 749 750
        return false;
    } else {
		jQuery('#confirmpasswordError').hide();
        jQuery('#confirmpasswordOK').show();
		jQuery('button.positive').removeAttr('disabled');
751 752 753 754 755
		jQuery('.tabbox_tabs ul li a').each(function() {
            var $this = $(this);
            $this.unbind('click', funcDisableClick);
            if($this.data('saved_onclick') && !$this.attr('onclick')) $this.attr('onclick', $this.data('saved_onclick'));
        });
756 757 758
    }
}

759 760 761 762
function getRandomInt(min, max){
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

763 764 765 766 767
jQuery('.addPlaceholder').live("click", function(){
	var placeholderText = jQuery(this).text();
	var template = jQuery(this).siblings(':input');
	template.insertAtCaret(placeholderText);
});
768 769 770 771 772 773

jQuery('.addPlaceholderContent').live("click", function(){
	var placeholderContentText = jQuery(this).find('.addPlaceholderContent').text();
	var template2 = jQuery(this).siblings(':input');
	template2.insertAtCaret(placeholderContentText);
});
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801
		
jQuery.fn.extend({
	insertAtCaret: function(myValue){
		return this.each(function(i) {
			if (document.selection) {
				//For browsers like Internet Explorer
				this.focus();
				sel = document.selection.createRange();
				sel.text = myValue;
				this.focus();
			} else if (this.selectionStart || this.selectionStart == '0') {
				//For browsers like Firefox and Webkit based
				var startPos = this.selectionStart;
				var endPos = this.selectionEnd;
				var scrollTop = this.scrollTop;
				this.value = this.value.substring(0, startPos)+myValue+this.value.substring(endPos,this.value.length);
				this.focus();
				this.selectionStart = startPos + myValue.length;
				this.selectionEnd = startPos + myValue.length;
				this.scrollTop = scrollTop;
			} else {
				this.value += myValue;
				this.focus();
			}
		})
	}
});