561 lines
18 KiB
JavaScript
Executable File
561 lines
18 KiB
JavaScript
Executable File
<!--
|
|
///////////////////////////////////////////////////////////////////
|
|
// Javascript Codebank //
|
|
///////////////////////////////////////////////////////////////////
|
|
function formSubmit10(action,removetype,removeid){
|
|
form=document.forms["form1"];
|
|
form.action.value=action;
|
|
form.removetype.value=removetype;
|
|
form.removeid.value=removeid;
|
|
|
|
if (action=="submit"){
|
|
if (checkrequired()==false){
|
|
alert("Please fill in all mandatory fields");
|
|
}else if (form.agree.checked==false){
|
|
alert("Please accept term & condition before submitting the page");
|
|
}else{
|
|
form.submit();
|
|
}
|
|
}else{
|
|
form.submit();
|
|
}
|
|
}
|
|
|
|
function MM_preloadImages() { //v3.0
|
|
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
|
|
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
|
|
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
|
|
}
|
|
|
|
function MM_swapImgRestore() { //v3.0
|
|
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
|
|
}
|
|
|
|
function MM_findObj(n, d) { //v4.01
|
|
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
|
|
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
|
|
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
|
|
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
|
|
if(!x && d.getElementById) x=d.getElementById(n); return x;
|
|
}
|
|
|
|
function MM_swapImage() { //v3.0
|
|
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
|
|
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
|
|
}
|
|
function MM_setTextOfLayer(objName,x,newText) { //v4.01
|
|
if ((obj=MM_findObj(objName))!=null) with (obj)
|
|
if (document.layers) {document.write(unescape(newText)); document.close();}
|
|
else innerHTML = unescape(newText);
|
|
};
|
|
function MM_openBrWindow(theURL,winName,features) { //v2.0
|
|
window.open(theURL,winName,features);
|
|
};
|
|
function isValidLength(string, min, max) {
|
|
if (string.length < min || string.length > max) return false;
|
|
else return true;
|
|
};
|
|
function isValidEmail(address) {
|
|
if (address != '' && address.search) {
|
|
if (address.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) return true;
|
|
else return false;
|
|
}
|
|
else return true;
|
|
};
|
|
function isValidEmailStrict(address) {
|
|
if (isValidEmail(address) == false) return false;
|
|
var domain = address.substring(address.indexOf('@') + 1);
|
|
if (domain.indexOf('.') == -1) return false;
|
|
if (domain.indexOf('.') == 0 || domain.indexOf('.') == domain.length - 1) return false;
|
|
return true;
|
|
};
|
|
function isAlphanumeric(string, ignoreWhiteSpace) {
|
|
if (string.search) {
|
|
if ((ignoreWhiteSpace && string.search(/[^\w\s]/) != -1) || (!ignoreWhiteSpace && string.search(/\W/) != -1)) return false;
|
|
}
|
|
return true;
|
|
};
|
|
function isAlphabetic(string, ignoreWhiteSpace) {
|
|
if (string.search) {
|
|
if ((ignoreWhiteSpace && string.search(/[^a-zA-Z\s]/) != -1) || (!ignoreWhiteSpace && string.search(/[^a-zA-Z]/) != -1)) return false;
|
|
}
|
|
return true;
|
|
};
|
|
function isNumeric(string, ignoreWhiteSpace) {
|
|
if (string.search) {
|
|
if ((ignoreWhiteSpace && string.search(/[^\d\s]/) != -1) || (!ignoreWhiteSpace && string.search(/\D/) != -1)) return false;
|
|
}
|
|
return true;
|
|
};
|
|
function removeBadCharacters(string) {
|
|
if (string.replace) {
|
|
string.replace(/[<>"\'%;\)\(&\+]/, '');
|
|
}
|
|
return string;
|
|
};
|
|
function removeSpaces(string) {
|
|
var newString = '';
|
|
for (var i = 0; i < string.length; i++) {
|
|
if (string.charAt(i) != ' ') newString += string.charAt(i);
|
|
}
|
|
return newString;
|
|
};
|
|
function trimWhitespace(string) {
|
|
var newString = '';
|
|
var substring = '';
|
|
beginningFound = false;
|
|
for (var i = 0; i < string.length; i++) {
|
|
if (string.charAt(i) != ' ' && string.charCodeAt(i) != 9) {
|
|
if (substring != '') {
|
|
newString += substring;
|
|
substring = '';
|
|
}
|
|
newString += string.charAt(i);
|
|
if (beginningFound == false) beginningFound = true;
|
|
}
|
|
else if (beginningFound == true) substring += string.charAt(i);
|
|
}
|
|
return newString;
|
|
};
|
|
function msgConfirm() {
|
|
msg = msgConfirm.arguments[0];
|
|
if(!msg || msg == ""){msg="Are You Sure?";}
|
|
if(confirm(msg)){
|
|
return true;
|
|
}
|
|
else{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function MM_reloadPage(init) { //reloads the window if Nav4 resized
|
|
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
|
|
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
|
|
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
|
|
}
|
|
function centrepop(url,sx,sy)
|
|
{
|
|
var winl = (screen.width-sx)/2;
|
|
var wint = (screen.height-sy)/2;
|
|
popupwin=window.open(url,"popup","toolbar=no,location=no,resizable=yes,directories=no,status=no,statusbar=no,menubar=no,scrollbars=yes,top="+wint+",left="+winl+",width="+sx+",height="+sy+"");
|
|
|
|
}
|
|
|
|
function popup (title,img,sx,sy,num,rnd) {
|
|
var winl = (screen.width-sx)/2;
|
|
var wint = (screen.height-sy)/2;
|
|
image = "<img src='"+img+"&"+rnd+"' border='1'>";
|
|
popupwin=window.open("","photo"+num,"toolbar=no,location=no,resizable=no,directories=no,status=no,statusbar=no,menubar=no,top="+wint+",left="+winl+",width="+sx+",height="+sy+"");
|
|
popupwin.document.write("<HTML><HEAD><title>" + title + "</title></HEAD><BODY BGCOLOR='#FFFFFF' link='#CC0000' vlink='#CC0000' alink='#CC0000'><CENTER><font face='verdana, arial, helvetica' size='1'><br>" + image + "<p>[ <a href='javascript:self.close()'>Close</a> ]</p></font></CENTER></BODY></HTML>");
|
|
popupwin.document.close();
|
|
}
|
|
// load iframe call using loadIframe([string, URL],[string, frame ID]);
|
|
function loadIframe(theURL,theFRM) {
|
|
document.getElementById(theFRM).src = theURL;
|
|
}
|
|
var checkflag = "false";
|
|
function check_all(field) {
|
|
if (checkflag == "false") {
|
|
for (i = 0; i < document.forms[0].elements['_selected[]'].length; i++) {
|
|
document.forms[0].elements['_selected[]'][i].checked = true;
|
|
}
|
|
checkflag = "true";
|
|
return "Uncheck All";
|
|
} else {
|
|
for (i = 0; i < document.forms[0].elements['_selected[]'].length; i++) {
|
|
document.forms[0].elements['_selected[]'][i].checked = false;
|
|
}
|
|
checkflag = "false";
|
|
return "Check All";
|
|
}
|
|
}
|
|
function Validator(frmname)
|
|
{
|
|
this.formobj=document.forms[frmname];
|
|
if(!this.formobj)
|
|
{
|
|
alert("BUG: couldnot get Form object "+frmname);
|
|
return;
|
|
}
|
|
if(this.formobj.onsubmit)
|
|
{
|
|
this.formobj.old_onsubmit = this.formobj.onsubmit;
|
|
this.formobj.onsubmit=null;
|
|
}
|
|
else
|
|
{
|
|
this.formobj.old_onsubmit = null;
|
|
}
|
|
this.formobj.onsubmit=form_submit_handler;
|
|
this.addValidation = add_validation;
|
|
this.setAddnlValidationFunction=set_addnl_vfunction;
|
|
this.clearAllValidations = clear_all_validations;
|
|
}
|
|
function set_addnl_vfunction(functionname)
|
|
{
|
|
this.formobj.addnlvalidation = functionname;
|
|
}
|
|
function clear_all_validations()
|
|
{
|
|
for(var itr=0;itr < this.formobj.elements.length;itr++)
|
|
{
|
|
this.formobj.elements[itr].validationset = null;
|
|
}
|
|
}
|
|
function form_submit_handler()
|
|
{
|
|
for(var itr=0;itr < this.elements.length;itr++)
|
|
{
|
|
if(this.elements[itr].validationset &&
|
|
!this.elements[itr].validationset.validate())
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
if(this.addnlvalidation)
|
|
{
|
|
str =" var ret = "+this.addnlvalidation+"()";
|
|
eval(str);
|
|
if(!ret) return ret;
|
|
}
|
|
return true;
|
|
}
|
|
function add_validation(itemname,descriptor,errstr)
|
|
{
|
|
if(!this.formobj)
|
|
{
|
|
alert("BUG: the form object is not set properly");
|
|
return;
|
|
}//if
|
|
var itemobj = this.formobj[itemname];
|
|
if(!itemobj)
|
|
{
|
|
alert("BUG: Couldnot get the input object named: "+itemname);
|
|
return;
|
|
}
|
|
if(!itemobj.validationset)
|
|
{
|
|
itemobj.validationset = new ValidationSet(itemobj);
|
|
}
|
|
itemobj.validationset.add(descriptor,errstr);
|
|
}
|
|
function ValidationDesc(inputitem,desc,error)
|
|
{
|
|
this.desc=desc;
|
|
this.error=error;
|
|
this.itemobj = inputitem;
|
|
this.validate=vdesc_validate;
|
|
}
|
|
function vdesc_validate()
|
|
{
|
|
if(!V2validateData(this.desc,this.itemobj,this.error))
|
|
{
|
|
this.itemobj.focus();
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
function ValidationSet(inputitem)
|
|
{
|
|
this.vSet=new Array();
|
|
this.add= add_validationdesc;
|
|
this.validate= vset_validate;
|
|
this.itemobj = inputitem;
|
|
}
|
|
function add_validationdesc(desc,error)
|
|
{
|
|
this.vSet[this.vSet.length]=
|
|
new ValidationDesc(this.itemobj,desc,error);
|
|
}
|
|
function vset_validate()
|
|
{
|
|
for(var itr=0;itr<this.vSet.length;itr++)
|
|
{
|
|
if(!this.vSet[itr].validate())
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
function validateEmailv2(email)
|
|
{
|
|
// a very simple email validation checking.
|
|
// you can add more complex email checking if it helps
|
|
if(email.length <= 0)
|
|
{
|
|
return true;
|
|
}
|
|
var splitted = email.match("^(.+)@(.+)$");
|
|
if(splitted == null) return false;
|
|
if(splitted[1] != null )
|
|
{
|
|
var regexp_user=/^\"?[\w-_\.]*\"?$/;
|
|
if(splitted[1].match(regexp_user) == null) return false;
|
|
}
|
|
if(splitted[2] != null)
|
|
{
|
|
var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
|
|
if(splitted[2].match(regexp_domain) == null)
|
|
{
|
|
var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
|
|
if(splitted[2].match(regexp_ip) == null) return false;
|
|
}// if
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
function V2validateData(strValidateStr,objValue,strError)
|
|
{
|
|
var epos = strValidateStr.search("=");
|
|
var command = "";
|
|
var cmdvalue = "";
|
|
if(epos >= 0)
|
|
{
|
|
command = strValidateStr.substring(0,epos);
|
|
cmdvalue = strValidateStr.substr(epos+1);
|
|
}
|
|
else
|
|
{
|
|
command = strValidateStr;
|
|
}
|
|
switch(command)
|
|
{
|
|
case "req":
|
|
case "required":
|
|
{
|
|
if(eval(objValue.value.length) == 0)
|
|
{
|
|
if(!strError || strError.length ==0)
|
|
{
|
|
strError = objValue.name + " : Required Field";
|
|
}//if
|
|
alert(strError);
|
|
return false;
|
|
}//if
|
|
break;
|
|
}//case required
|
|
case "maxlength":
|
|
case "maxlen":
|
|
{
|
|
if(eval(objValue.value.length) > eval(cmdvalue))
|
|
{
|
|
if(!strError || strError.length ==0)
|
|
{
|
|
strError = objValue.name + " : "+cmdvalue+" characters maximum ";
|
|
}//if
|
|
alert(strError + "\n[Current length = " + objValue.value.length + " ]");
|
|
return false;
|
|
}//if
|
|
break;
|
|
}//case maxlen
|
|
case "minlength":
|
|
case "minlen":
|
|
{
|
|
if(eval(objValue.value.length) < eval(cmdvalue))
|
|
{
|
|
if(!strError || strError.length ==0)
|
|
{
|
|
strError = objValue.name + " : " + cmdvalue + " characters minimum ";
|
|
}//if
|
|
alert(strError + "\n[Current length = " + objValue.value.length + " ]");
|
|
return false;
|
|
}//if
|
|
break;
|
|
}//case minlen
|
|
case "alnum":
|
|
case "alphanumeric":
|
|
{
|
|
var charpos = objValue.value.search("[^A-Za-z0-9]");
|
|
if(objValue.value.length > 0 && charpos >= 0)
|
|
{
|
|
if(!strError || strError.length ==0)
|
|
{
|
|
strError = objValue.name+": Only alpha-numeric characters allowed ";
|
|
}//if
|
|
alert(strError + "\n [Error character position " + eval(charpos+1)+"]");
|
|
return false;
|
|
}//if
|
|
break;
|
|
}//case alphanumeric
|
|
case "num":
|
|
case "numeric":
|
|
{
|
|
var charpos = objValue.value.search("[^0-9]");
|
|
if(objValue.value.length > 0 && charpos >= 0)
|
|
{
|
|
if(!strError || strError.length ==0)
|
|
{
|
|
strError = objValue.name+": Only digits allowed ";
|
|
}//if
|
|
alert(strError + "\n [Error character position " + eval(charpos+1)+"]");
|
|
return false;
|
|
}//if
|
|
break;
|
|
}//numeric
|
|
case "alphabetic":
|
|
case "alpha":
|
|
{
|
|
var charpos = objValue.value.search("[^A-Za-z]");
|
|
if(objValue.value.length > 0 && charpos >= 0)
|
|
{
|
|
if(!strError || strError.length ==0)
|
|
{
|
|
strError = objValue.name+": Only alphabetic characters allowed ";
|
|
}//if
|
|
alert(strError + "\n [Error character position " + eval(charpos+1)+"]");
|
|
return false;
|
|
}//if
|
|
break;
|
|
}//alpha
|
|
case "alnumhyphen":
|
|
{
|
|
var charpos = objValue.value.search("[^A-Za-z0-9\-_]");
|
|
if(objValue.value.length > 0 && charpos >= 0)
|
|
{
|
|
if(!strError || strError.length ==0)
|
|
{
|
|
strError = objValue.name+": characters allowed are A-Z,a-z,0-9,- and _";
|
|
}//if
|
|
alert(strError + "\n [Error character position " + eval(charpos+1)+"]");
|
|
return false;
|
|
}//if
|
|
break;
|
|
}
|
|
case "email":
|
|
{
|
|
if(!validateEmailv2(objValue.value))
|
|
{
|
|
if(!strError || strError.length ==0)
|
|
{
|
|
strError = objValue.name+": Enter a valid Email address ";
|
|
}//if
|
|
alert(strError);
|
|
return false;
|
|
}//if
|
|
break;
|
|
}//case email
|
|
case "lt":
|
|
case "lessthan":
|
|
{
|
|
if(isNaN(objValue.value))
|
|
{
|
|
alert(objValue.name+": Should be a number ");
|
|
return false;
|
|
}//if
|
|
if(eval(objValue.value) >= eval(cmdvalue))
|
|
{
|
|
if(!strError || strError.length ==0)
|
|
{
|
|
strError = objValue.name + " : value should be less than "+ cmdvalue;
|
|
}//if
|
|
alert(strError);
|
|
return false;
|
|
}//if
|
|
break;
|
|
}//case lessthan
|
|
case "gt":
|
|
case "greaterthan":
|
|
{
|
|
if(isNaN(objValue.value))
|
|
{
|
|
alert(objValue.name+": Should be a number ");
|
|
return false;
|
|
}//if
|
|
if(eval(objValue.value) <= eval(cmdvalue))
|
|
{
|
|
if(!strError || strError.length ==0)
|
|
{
|
|
strError = objValue.name + " : value should be greater than "+ cmdvalue;
|
|
}//if
|
|
alert(strError);
|
|
return false;
|
|
}//if
|
|
break;
|
|
}//case greaterthan
|
|
case "regexp":
|
|
{
|
|
if(objValue.value.length > 0)
|
|
{
|
|
if(!objValue.value.match(cmdvalue))
|
|
{
|
|
if(!strError || strError.length ==0)
|
|
{
|
|
strError = objValue.name+": Invalid characters found ";
|
|
}//if
|
|
alert(strError);
|
|
return false;
|
|
}//if
|
|
}
|
|
break;
|
|
}//case regexp
|
|
case "dontselect":
|
|
{
|
|
if(objValue.selectedIndex == null)
|
|
{
|
|
alert("BUG: dontselect command for non-select Item");
|
|
return false;
|
|
}
|
|
if(objValue.selectedIndex == eval(cmdvalue))
|
|
{
|
|
if(!strError || strError.length ==0)
|
|
{
|
|
strError = objValue.name+": Please Select one option ";
|
|
}//if
|
|
alert(strError);
|
|
return false;
|
|
}
|
|
break;
|
|
}//case dontselect
|
|
}//switch
|
|
return true;
|
|
}
|
|
MM_reloadPage(true);
|
|
|
|
|
|
//-->
|
|
|
|
function createXMLHttpRequest() {
|
|
var ua;
|
|
if(window.XMLHttpRequest) {
|
|
try {
|
|
ua = new XMLHttpRequest();
|
|
} catch(e) {
|
|
ua = false;
|
|
}
|
|
}else if(window.ActiveXObject) {
|
|
try {
|
|
ua = new ActiveXObject("Microsoft.XMLHTTP");
|
|
} catch(e) {
|
|
ua = false;
|
|
}
|
|
}
|
|
return ua;
|
|
}
|
|
|
|
function randomString() {
|
|
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
|
|
var string_length = 8;
|
|
var randomstring = '';
|
|
for (var i=0; i<string_length; i++) {
|
|
var rnum = Math.floor(Math.random() * chars.length);
|
|
randomstring += chars.substring(rnum,rnum+1);
|
|
}
|
|
return randomstring;
|
|
}
|
|
|
|
function brandselect(svalue){
|
|
if (svalue>0){
|
|
var rannum=randomString();
|
|
var req=createXMLHttpRequest();
|
|
req.open('get', 'modules/main/cmd.php?cmd=brandselect'+'&svalue='+svalue+'&rannum='+rannum);
|
|
req.onreadystatechange = function(){
|
|
if(req.readyState == 4 && req.status == 200){
|
|
var response = req.responseText;
|
|
document.getElementById("modeldiv").innerHTML = response;
|
|
}else{
|
|
}
|
|
}
|
|
req.send(null);
|
|
}
|
|
} |