scrigo.js.php 25.4 KB
Newer Older
1 2 3
<?php
	session_start();
	include('../../lib/config.inc.php');
4 5
	$lang = (isset($_SESSION['s']['language']) && $_SESSION['s']['language'] != '')?$_SESSION['s']['language']:'en';
	include_once(ISPC_ROOT_PATH.'/web/strengthmeter/lib/lang/'.$lang.'_strengthmeter.lng');
6
?>
mcramer's avatar
mcramer committed
7 8 9 10 11
var pageFormChanged = false;
var tabChangeWarningTxt = '';
var tabChangeDiscardTxt = '';
var tabChangeWarning = false;
var tabChangeDiscard = false;
12 13 14 15
var requestsRunning = 0;
var indicatorPaddingH = -1;
var indicatorPaddingW = -1;
var indicatorCompleted = false;
16 17
redirect = '';

18 19 20 21 22 23 24 25
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);*/
}

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
function showLoadIndicator() {
    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();});
        });
    }
}

function hideLoadIndicator() {
    requestsRunning -= 1;
    if(requestsRunning < 1) {
        requestsRunning = 0; // just for the case...
        if(indicatorCompleted == true) jQuery('#ajaxloader').fadeOut('fast', function() { jQuery('#ajaxloader').hide(); } );
    }
}

function onAfterContentLoad() {
    $('#pageContent').find("select").combobox();
}

61 62 63
function loadContentRefresh(pagename) {
	
  if(document.getElementById('refreshinterval').value > 0) {
64
	var pageContentObject2 = jQuery.ajax({	type: "GET", 
65
											url: pagename,
66
											data: "refresh="+document.getElementById('refreshinterval').value,
67
											dataType: "html",
68 69 70
											beforeSend: function() {
												showLoadIndicator();
											},
71
											success: function(data, textStatus, jqXHR) {
72
                                                hideLoadIndicator();
73
												jQuery('#pageContent').html(jqXHR.responseText);
74
                                                onAfterContentLoad();
mcramer's avatar
mcramer committed
75
                                                pageFormChanged = false;
76 77
											},
											error: function() {
78
                                                hideLoadIndicator();
79
												reportError('Ajax Request was not successful.'+pagename);
cfoe's avatar
cfoe committed
80
											}
81
										});
82 83 84 85
  	setTimeout( "loadContentRefresh('"+pagename+"&refresh="+document.getElementById('refreshinterval').value+"')", document.getElementById('refreshinterval').value*1000 );
  }
}

86
function capp(module, redirect) {
87 88
	var submitFormObj = jQuery.ajax({		type: "GET", 
											url: "capp.php", 
89
											data: "mod="+module+((redirect != undefined) ? '&redirect='+redirect : ''),
90
											dataType: "html",
91 92 93
											beforeSend: function() {
												showLoadIndicator();
											},
94 95 96 97 98
											success: function(data, textStatus, jqXHR) {
												if(jqXHR.responseText != '') {
													if(jqXHR.responseText.indexOf('HEADER_REDIRECT:') > -1) {
														var parts = jqXHR.responseText.split(':');
														loadContent(parts[1]);
99 100 101
													} 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;
102
													} else {
103
														//alert(jqXHR.responseText);
104 105 106
													}
												}
												loadMenus();
107
                                                hideLoadIndicator();
108 109
											},
											error: function() {
110
                                                hideLoadIndicator();
111
												reportError('Ajax Request was not successful.'+module);
cfoe's avatar
cfoe committed
112
											}
113
									});
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
}

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;
    }   
129 130 131
	var submitFormObj = jQuery.ajax({		type: "POST", 
											url: "content.php",
											data: jQuery('#'+formname).serialize(),
132
											dataType: "html",
133 134 135
											beforeSend: function() {
												showLoadIndicator();
											},
136 137 138 139 140 141 142 143 144 145 146
											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 {
147
													jQuery('#pageContent').html(jqXHR.responseText);
148
                                                    onAfterContentLoad();
mcramer's avatar
mcramer committed
149
                                                    pageFormChanged = false;
150 151
												}
												loadMenus();
152
                                                hideLoadIndicator();
153 154
											},
											error: function() {
155
                                                hideLoadIndicator();
156
												reportError('Ajax Request was not successful.110');
cfoe's avatar
cfoe committed
157
											}
158
									});
159 160 161 162 163
	/*
	if(redirect != '') {
		loadContent(redirect);
		redirect = '';
	}
164
	document.getElementById('footer').innerHTML = 'Powered by <a href="http://www.ispconfig.org" target="_blank">ISPConfig</a>';
165
	*/
166
	
167 168
}

169
function submitForm(formname,target) {
170 171 172
	var submitFormObj = jQuery.ajax({		type: "POST", 
											url: target,
											data: jQuery('#'+formname).serialize(),
173
											dataType: "html",
174 175 176
											beforeSend: function() {
												showLoadIndicator();
											},
177 178 179 180 181 182 183 184
											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 {
185
													jQuery('#pageContent').html(jqXHR.responseText);
186
                                                    onAfterContentLoad();
mcramer's avatar
mcramer committed
187
                                                    pageFormChanged = false;
188
												}
189
                                                hideLoadIndicator();
190 191
											},
											error: function(jqXHR, textStatus, errorThrown) {
192
                                                hideLoadIndicator();
193 194
												var parts = jqXHR.responseText.split(':');
												reportError('Ajax Request was not successful. 111');
cfoe's avatar
cfoe committed
195
											}
196
									});
197 198 199 200 201 202 203 204
	/*
	if(redirect != '') {
		loadContent(redirect);
		redirect = '';
	}
	*/
}

205
function submitFormConfirm(formname,target,confirmation) {
206
	var successMessage = arguments[3];
207 208 209 210 211
	if(window.confirm(confirmation)) {
		var submitFormObj = jQuery.ajax({	type: "POST", 
											url: target,
											data: jQuery('#'+formname).serialize(),
											dataType: "html",
212 213 214
											beforeSend: function() {
												showLoadIndicator();
											},
215
											success: function(data, textStatus, jqXHR) {
216
												if(successMessage) alert(successMessage);
217 218 219 220 221 222 223 224
												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);
225
                                                    onAfterContentLoad();
mcramer's avatar
mcramer committed
226
                                                    pageFormChanged = false;
227
												}
228
                                                hideLoadIndicator();
229 230
											},
											error: function(jqXHR, textStatus, errorThrown) {
231
                                                hideLoadIndicator();
232 233
												var parts = jqXHR.responseText.split(':');
												reportError('Ajax Request was not successful. 111');
cfoe's avatar
cfoe committed
234
											}
235 236 237 238
									});
	}
}

239
function submitUploadForm(formname,target) {		
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
	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+'"/>');
263
	jQuery('input[type="file"]').closest("form").attr({target: frame_id, action: target}).submit();
264 265 266 267 268
	jQuery('#'+frame_id).load(function() {
        var msg = handleResponse(this);
		jQuery('#errorMsg').remove();
		jQuery('#OKMsg').remove();
		jQuery('input[name="id"]').before(msg);
269
		jQuery(this).remove();
270 271
      });

272 273 274 275 276 277 278 279 280
	/*
	if(redirect != '') {
		loadContent(redirect);
		redirect = '';
	}
	*/
}

function loadContent(pagename) {
mcramer's avatar
mcramer committed
281
  var params = arguments[1];
282 283
  var pageContentObject2 = jQuery.ajax({	type: "GET", 
											url: pagename,
mcramer's avatar
mcramer committed
284
                                            data: (params ? params : null),
285
											dataType: "html",
286
											beforeSend: function() {
287
												showLoadIndicator();
288
											},
289 290 291 292 293 294 295 296
											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 {
297 298 299 300
													//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); } );
301
													
302
													jQuery('#pageContent').html(jqXHR.responseText);
303
                                                    onAfterContentLoad();
mcramer's avatar
mcramer committed
304
                                                    pageFormChanged = false;
305
												}
306
                                                hideLoadIndicator();
307 308
											},
											error: function() {
309
                                                hideLoadIndicator();
310
												reportError('Ajax Request was not successful. 113');
cfoe's avatar
cfoe committed
311
											}
312
									});
313 314 315 316
}


function loadInitContent() {
317 318 319
	var pageContentObject = jQuery.ajax({	type: "GET", 
											url: "content.php",
											data: "s_mod=login&s_pg=index",
320
											dataType: "html",
321 322 323
											beforeSend: function() {
												showLoadIndicator();
											},
324 325 326 327 328
											success: function(data, textStatus, jqXHR) {
												if(jqXHR.responseText.indexOf('HEADER_REDIRECT:') > -1) {
													var parts = jqXHR.responseText.split(":");
													loadContent(parts[1]);
												} else {
329
													jQuery('#pageContent').html(jqXHR.responseText);
330
                                                    onAfterContentLoad();
mcramer's avatar
mcramer committed
331
                                                    pageFormChanged = false;
332
												}
333
                                                hideLoadIndicator();
334 335
											},
											error: function() {
336
                                                hideLoadIndicator();
337
												reportError('Ajax Request was not successful. 114');
cfoe's avatar
cfoe committed
338
											}
339
										});
340 341 342 343 344 345 346 347
  
  loadMenus();
  keepalive();
  setTimeout("setFocus()",1000);

}

function setFocus() {
348
	try {
349
		jQuery('form#pageForm').find('input[name="username"]').focus();
350 351
	} catch (e) {
	}
352 353 354 355
}


function loadMenus() {
356 357 358
  var sideNavObject = jQuery.ajax({			type: "GET", 
											url: "nav.php",
											data: "nav=side",
359
											dataType: "html",
360 361 362
											beforeSend: function() {
												showLoadIndicator();
											},
363
											success: function(data, textStatus, jqXHR) {
364
                                                hideLoadIndicator();
365
												jQuery('#sideNav').html(jqXHR.responseText);
366 367
											},
											error: function() {
368
                                                hideLoadIndicator();
369
												reportError('Ajax Request was not successful. 115');
cfoe's avatar
cfoe committed
370
											}
371
									});
372
	
373 374 375
  var topNavObject = jQuery.ajax({			type: "GET", 
											url: "nav.php",
											data: "nav=top",
376
											dataType: "html",
377 378 379
											beforeSend: function() {
												showLoadIndicator();
											},
380
											success: function(data, textStatus, jqXHR) {
381
                                                hideLoadIndicator();
382
												jQuery('#topNav').html(jqXHR.responseText);
383 384
											},
											error: function(o) {
385
                                                hideLoadIndicator();
386
												reportError('Ajax Request was not successful. 116');
cfoe's avatar
cfoe committed
387
											}
388
								});
389 390 391

}

392
function changeTab(tab,target,force) {
393 394
	//document.forms[0].next_tab.value = tab;
	document.pageForm.next_tab.value = tab;
mcramer's avatar
mcramer committed
395
    
396 397 398
    var idel = jQuery('form#pageForm').find('[name="id"]');
    var id = null;
    if(idel.length > 0) id = idel.val();
399
    if(tabChangeDiscard == 'y' && !force) {
400
        if((idel.length < 1 || id) && (pageFormChanged == false || window.confirm(tabChangeDiscardTxt))) {
mcramer's avatar
mcramer committed
401
            var next_tab = tab;
402 403
            if(id) loadContent(target, {'next_tab': next_tab, 'id': id});
            else loadContent(target, {'next_tab': next_tab});
mcramer's avatar
mcramer committed
404 405 406 407 408 409 410 411 412
        } else {
            return false;
        }
    } else {
        if(id && tabChangeWarning == 'y' && pageFormChanged == true) {
            if(window.confirm(tabChangeWarningTxt)) {
                submitForm('pageForm', target);
            } else {
                var next_tab = tab;
413 414
                if(id) loadContent(target, {'next_tab': next_tab, 'id': id});
                else loadContent(target, {'next_tab': next_tab});
mcramer's avatar
mcramer committed
415 416 417 418 419
            }
        } else {
            submitForm('pageForm',target);
        }
    }
420 421 422 423 424 425 426 427
}
	
function del_record(link,confirmation) {
  if(window.confirm(confirmation)) {
          loadContent(link);
  }
}

428 429 430 431 432 433
function confirm_action(link,confirmation) {
  if(window.confirm(confirmation)) {
          loadContent(link);
  }
}

434
function loadContentInto(elementid,pagename) {
435 436
  var pageContentObject2 = jQuery.ajax({	type: "GET", 
											url: pagename,
437
											dataType: "html",
438 439 440
											beforeSend: function() {
//												showLoadIndicator();
											},
441
											success: function(data, textStatus, jqXHR) {
442
//                                                hideLoadIndicator();
443
												jQuery('#'+elementid).html(jqXHR.responseText);
444 445
											},
											error: function() {
446
//                                                hideLoadIndicator();
447
												reportError('Ajax Request was not successful. 118');
cfoe's avatar
cfoe committed
448
											}
449
										});
450 451
}

452
function loadOptionInto(elementid,pagename) {
453 454
	var pageContentObject2 = jQuery.ajax({	type: "GET", 
											url: pagename,
455
											dataType: "html",
456 457 458
											beforeSend: function() {
//												showLoadIndicator();
											},
459
											success: function(data, textStatus, jqXHR) {
460
//                                                hideLoadIndicator();
461 462 463 464 465 466 467 468 469 470 471 472 473
												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() {
474
//                                                hideLoadIndicator();
475
												reportError('Ajax Request was not successful. 119');
cfoe's avatar
cfoe committed
476
											}
477
										});
478 479
}

480
function keepalive() {
481 482
	var pageContentObject3 = jQuery.ajax({	type: "GET", 
											url: "keepalive.php",
483
											dataType: "html",
484 485 486 487 488
											success: function(data, textStatus, jqXHR) {
												setTimeout( keepalive, 1000000 );
											},
											error: function() {
												reportError('Session expired. Please login again.');
cfoe's avatar
cfoe committed
489
											}
490
										});
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 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
  	//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;
617
	
618 619 620 621
	  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];
622
	if(addTplId > 0) {
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654
	  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');
  }
  
}
655 656 657 658 659 660 661 662 663 664 665

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;
}
666

667
function password(minLength, special){
668 669 670
	var iteration = 0;
	var password = "";
	var randomNumber;
671 672 673
	minLength = minLength || 10;
	var maxLength = minLength + 5;
	var length = getRandomInt(minLength, maxLength);
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690
	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
691
function generatePassword(passwordFieldID, repeatPasswordFieldID){
692 693 694 695
	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
696 697 698
	var pword = password(10, false);
	jQuery('#'+repeatPasswordFieldID).val(pword);
	newPWField.attr('id', passwordFieldID).val(pword).trigger('keyup');
699
}
700

701 702
var funcDisableClick = function(e) { e.preventDefault(); return false; };

703 704 705 706 707 708 709
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');
710 711 712 713 714 715
        jQuery('.tabbox_tabs ul li a').each(function() {
            var $this = $(this);
            $this.data('saved_onclick', $this.attr('onclick'));
            $this.removeAttr('onclick');
            $this.click(funcDisableClick);
        });
716 717 718 719 720
        return false;
    } else {
		jQuery('#confirmpasswordError').hide();
        jQuery('#confirmpasswordOK').show();
		jQuery('button.positive').removeAttr('disabled');
721 722 723 724 725
		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'));
        });
726 727 728
    }
}

729 730 731 732
function getRandomInt(min, max){
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

733 734 735 736 737
jQuery('.addPlaceholder').live("click", function(){
	var placeholderText = jQuery(this).text();
	var template = jQuery(this).siblings(':input');
	template.insertAtCaret(placeholderText);
});
738 739 740 741 742 743

jQuery('.addPlaceholderContent').live("click", function(){
	var placeholderContentText = jQuery(this).find('.addPlaceholderContent').text();
	var template2 = jQuery(this).siblings(':input');
	template2.insertAtCaret(placeholderContentText);
});
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771
		
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();
			}
		})
	}
});