﻿

         /**************************** SPACE ELIMINATION ************************/
		function strip_lspaces(element){
		    if (element != ""){
			    while('' + element.charAt(0) == ' '){
				    element = element.substring(1,element.length);
				}
			}
			return element;
		}
		
        // Email accepts with Colon			
		function multiemailchecke(email) {
            var x;
            var myTest = new Array();
            var myResult =new Array();			    
            var emailcount; 

            emailcount= 0;
            myTest = email.value;
            myResult = myTest.split(";");

            for(x=0; x<myResult.length; x++) {
                if (strip_lspaces(myResult[x]) != '') {
                    if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(strip_lspaces(myResult[x])) )
                    {
                        emailcount = emailcount + 1;
                    }
                }    
            }
            return emailcount;
		}
			
		function validate(field, type)
		{
		        		
			var  num = "0123456789" ;
			var valid = "";
			var rs = "" ;
			var c;
			if (type == "integer") { valid= valid + num}
			if (type == "name"){ valid = valid  + (rs = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ")}
			if (type == "money"){ valid = valid + num + (rs = ".,")}
			if (type == "phone"){ valid = valid + num + (rs = "- ")}
			if (type == "mobile"){ valid = valid + num + (rs = ") (-");}
			if (type == "date"){ valid = valid + num + (rs = "/"); }
			if (type == "zip"){ valid = valid + num + (rs = "() "); }
			if (type  == "password") {valid = valid + num +(rs= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()`~");}
			if (type == "userid"){ valid = valid  + (rs = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_");}
			if (type == "subject"){ valid = valid  + (rs = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ");}
			if (type == "alphanumeric"){ valid = valid  + (rs = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ()-.");}
			if (type == "vat"){ valid = valid  + (rs = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 -");}
			if (type == "statename"){ valid = valid  + (rs = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ -&");}
			if (type == "attribname"){ valid = valid  + (rs = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 %;-&");}
			if (type == "mailtemplate"){ valid = valid  + (rs = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 .^_;,@");}
			if (type == "sitemap"){ valid = valid  + (rs = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 &'");}
			if (type == "weight"){ valid = valid + num + (rs = " -");}
			if (rs != ""){rs = "and ' " + rs + " '"} 
			var msg = "and "+ valid
			var ok = "yes";
			var temp;
			
			if (type == "email"){ 
				if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(field.value)){
				    return " Invalid Email Address! please re-enter ";
				}else{
					return "Valid!!";
				}
			}
			
			
			
			if (type == "url"){ 
			if(!/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/)([a-z]{1,}[\w-.]{0,}).([a-z]{2,6})(\/{1}[\w_]{1}[\/\w-&?=_%]{0,}(.{1}[\/\w-&?=_%]{0,})*)*$/.test(field.value)){
//				if (!/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/)([a-z]{1,}[\w-.]{0,}).([a-z]{2,6})(\/{1}[\w_]{1}[\/\w-&?=_%]{0,}(.{1}[\/\w-&?=_%]{0,})*)*$/.test(field.value)){
				   	return " Invalid Website! Please use http(s)://www.xyz.com";
				}else{
					return "Valid!!";
				}
			}
				
			for (var i=0; i<field.value.length; i++) {
				temp = "" + field.value.substring(i, i+1);
				if (valid.indexOf(temp) == "-1") ok = "no";
			}
		    if (ok == "no")
		    {
		        if(type=="phone" || type=="zip" || type=="mobile")
		        {
		            return " Invalid entry! Only  Numbers are accepted ";
		        }
		        else if(type== "password")
		        {
		            return " Invalid entry! Only Numbers, Characters and '!@#$%^&*()' are accepted ";
		        }
		        else if(type=="userid")
		        {
		            return " Invalid entry! Only Numbers, Characters and _ are accepted ";
		        }
		        else if(type== "subject")
		        {
		            return " Invalid entry! Only Numbers, Characters are accepted ";
		        }
		        else if(type == "vat")
		        {
		            return " Invalid entry! Only Numbers Characters and -  are accepted ";
		        }
		        else if(type == "alphanumeric")
		        {
		            return " Invalid entry! Only Numbers, Characters,(,),.  are accepted ";
		        }
		        else if(type == "integer")
		        {
		            return "Invalid entry! Only Numbers are accepted";
		        }
		        else if(type == "money")
		        {
		            return "Invalid Pgo Price! Please Use 123/123.00 Pricing Format ";
		        }
		        else if(type == "weight")
		        {
		            return "Invalid Weight! Please Use 125/ 125 - 250 Format ";
		        }
		        else if(type == "attribname")
		        {
		            return " Invalid entry! Only Numbers, Characters and -%;& are accepted ";
		        }
		        else if(type == "mailtemplate")
		        {
		            return " Invalid entry! Only Numbers, Characters and ^ _ ; , @ are accepted For ";
		        }
		          else if(type == "sitemap")
		        {
		            return " Invalid entry! Only Numbers, Characters and & ' are accepted For ";
		        }
		        else
		        {
				    return " Invalid entry! Only Characters are accepted ";
				}
			}
			return "Valid!!";
		}
			
			
		//FUNCTION TO VALIDATE THE DATE FIELD
		function datecheck(field){
			var f_date = strip_lspaces(field.value);
			date_split = f_date.split("/") ;
			
			if (date_split.length < 3){
				field.select();
				return "Please enter correct date. Use mm/dd/yyyyy format.";
			}
			
			if (date_split[0].length < 0 || date_split[1].length < 0 || date_split[2] < 0){
				return "Please enter correct date. Use mm/dd/yyyyy format.";
			}
			
			if (date_split[0] < 1 || date_split[0] > 12) {
				return "Month value should be between 1 and 12.";
			}
			
			if (date_split[0] == 1 || date_split[0] == 3 || date_split[0] == 5 || date_split[0] == 7 || date_split[0] == 8 || date_split[0] == 10 || date_split[0] == 12){
				if (date_split[1] < 1 || date_split[1] > 31){
					return "Date value must be between 1 and 31";
				}
			}
			
			if (date_split[0] == 4 || date_split[0] == 6 || date_split[0] == 9 || date_split[0] == 11) { 
				if (date_split[1] < 1  || date_split[1] > 30){
					return "Date value must be between 1 and 30";
				}
			}
			
			if (date_split[2].length != 4) {
				return "Please specify a 4 year digit for year";
			}
			
			checkLeap = date_split[2] % 4 ;
			if (date_split[0] == 2 && checkLeap == 0){
				if (date_split[1] < 1 || date_split[1] > 29){
					return "Date for the month of February in a leap year must be between 1 and 29";
				}
			}
			
			if (date_split[0] == 2 && checkLeap != 0){
				if (date_split[1] < 1 || date_split[1] > 28){
					return "Date for the month of February must be between 1 and 28";
				}
			}
			return "Valid";
		}
		
		function validdate(field) {
			var valid = "0123456789/"
			var ok = "yes";
			var temp;
			for (var i=0; i<field.value.length; i++) {
				temp = "" + field.value.substring(i, i+1);
				if (valid.indexOf(temp) == "-1") ok = "no";
			}
			if (ok == "no") {
				return " Invalid Date! Use Only Numbers and / ";
			}
			return "Valid!!"
		}
			
			
			//***************function to control the textarea input.**********************
		function calcCharLeft(thisfield, x, y) 
		{
		    clipped = false
		    lenUSig = 0
		    maxLength = x
		    if (thisfield.value.length > maxLength) 
		    { 
			    thisfield.value = thisfield.value.substring(0, maxLength)
			    charleft = 0
			    clipped = true
		    }
		    else 
		    {
			    charleft = maxLength - thisfield.value.length
		    }
		    eval("document.form1.msgCL"+ y ).value = charleft
		    eval("document.form1.msg"+ y ).value   = "Chars Left"
		    return clipped
		}
				
		function textKey(thisfield, x, y) 
		{
			supportsKeys = true
			calcCharLeft(thisfield, x, y)
		}
		
		// Function for validating only int/Number
		function isempty_number(val,name)
		{
		    val=strip_lspaces(val);
		    if(val.length==0)
		        result = result + '\n'+ getI() + ' Enter ' + name ;
		    else if (isNaN(val) || val.indexOf('.')!=-1)
		        result = result + '\n'+ getI() + ' Invalid ' + name;
		}
		
		// Function for validating only Float/Decimal values for Pricing
		function isempty_float(val,name)
		{
		    val=strip_lspaces(val);		    
		    if(val.length==0)
		        result = result + '\n'+ getI() + ' Enter ' + name ;
		    else if (isNaN(val))
		        result = result + '\n'+getI() + ' Invalid ' + name;
		}


