Thursday, December 10, 2015

MySQL Vs MongoDb

MySQL MongoDb
Tables Collections
Rows Documents
Columns Fields
SHOW TABLES db.getCollectionNames()
SELECT * FROM users db.users.find()
SELECT name, weight FROM users db.users.find({}, {name: 1, weight: 1, _id: 0})
Note: By default _id will be included in the result
SELECT COUNT(*) FROM users db.users.count()
SELECT COUNT(*) FROM users where weight > 50 db.users.count({weight: {$gt: 50}})
SELECT * FROM users order by name ASC db.users.find().sort({name: 1})
SELECT * FROM users order by name DESC db.users.find().sort({name: -1})
INSERT INTO users (username, name, gender, weight, job) values('aurora1001', 'Aurora', 'F', 45, 'Teaching') db.users.insert({username: 'aurora1001', name: 'Aurora', gender: 'F', weight: 45, 'job' : 'Teaching'})
SELECT * FROM users WHERE gender = 'M' AND weight > 70 db.users.find({gender: 'M', weight: {$gt: 70}})
SELECT * FROM users WHERE gender != 'F' AND weight >= 70 db.users.find({gender: {$ne: 'F'}, weight: {$gte: 70}})
SELECT * FROM users WHERE job IN ('Teaching', 'Sales') db.users.find({job: {$in:['Teaching','Sales']}})
SELECT * FROM users WHERE gender = 'F' AND (job = 'Teaching' OR weight <= 50) db.users.find({gender: 'F', $or: [{job: 'Teaching'}, {weight: {$lte: 50}}]})
UPDATE users SET status = 'ACTIVE' db.users.update({}, {$set: {status: 'ACTIVE' }}, {multi: true });
UPDATE users SET weight=50 WHERE name='Aurora' db.users.update({name: 'Aurora'}, {$set: {weight: 50}}, {multi: true })
UPDATE users SET weight = weight + 5 WHERE name='Aurora' db.users.update({name: 'Aurora'}, {$inc: {weight: 5}}, {multi: true })
UPDATE users SET weight = weight - 5 WHERE name='Aurora' db.users.update({name: 'Aurora'}, {$inc: {weight: -5}}, {multi: true })
INSERT INTO users(username, weight) VALUES("aurora1001", 50) ON DUPLICATE KEY UPDATE weight = 60
Note: username has UNIQUE index
db.users.update({"username": 'aurora1001'}, {$set: {weight: 60}}, {upsert: true })

Tuesday, November 29, 2011

SVG Edit : Saving files to server


SVG-edit is a fast, web-based, Javascript-driven SVG editor that works in any modern browser. To learn more about SVG-edit, click here . By default, while clicking on the save link given in the menu, the image is opening in new window and user has to manually save the image to user's machine. SVG-edit (version 2.5.1) has given an extension to download the files to user's machine.

To download the file

Open svg-editor.js

In curConfig object, to the extensions array add 'ext-server_opensave.js' to the end. Make sure that ext-server_opensave.js , fileopen.php and filesave.php exist in the svg/extensions directory

To save the file to server

Do the above steps.

Open the extensions/filesave.php and comment out below code

header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=" . $file);
header("Content-Type: " . $mime);
header("Content-Transfer-Encoding: binary");
echo $contents;

And add the following code at the end

define('DIR_PATH', 'path to the directory with trailing slash');
$fp = fopen(DIR_PATH . $file, 'w+');
fwrite($fp, $contents);
fclose($fp);


Give proper directory path to DIR_PATH constant and give necessary permission to the folder

Friday, November 10, 2006

Common Javascript validation functions

function func_popup_close()
{
    if(opener!=null)
    {
        opener.focus();
    }
    window.close();
}
function func_is_longer_than_max_length(param_text,param_num)
{
    var i_length;
    var str_text=new String(func_trim(param_text));
    i_length=func_len(str_text);
    if (i_length>param_num)
    {
        return true;
    }
    else
    {
        return false;
    }
}
function func_is_shorter_than_min_length(param_text,param_num)
{
    var i_length;
    var str_text=new String(param_text);
    i_length = func_len(str_text);
    if (i_length < param_num)
    {
        return true;
    }
    else
    {
        return false;
    }
}

function func_trim(param_text)
{
    var str_text=new String(param_text);
    var str_return_text;
    str_return_text="";
    b_non_blank_started=false;
    b_non_blank_ended=false;
    str_intermediate_blank_chunk="";
    var i_loop;
    for(i_loop=0;i_loop    {
        if(str_text.charCodeAt(i_loop)!=32)
        {
        if(!b_non_blank_started)
        {
                b_non_blank_started=true;
            }
        if(b_non_blank_started && !b_non_blank_ended)
            {
                str_return_text+=str_text.charAt(i_loop);
            }
            if(b_non_blank_ended)
            {
                str_return_text+=(str_intermediate_blank_chunk+str_text.charAt(i_loop));
                b_non_blank_ended=false;
                str_intermediate_blank_chunk="";
            }
        }
        else
        {
            if(b_non_blank_started)
            {
                b_non_blank_ended=true;
                str_intermediate_blank_chunk+=" ";
            }
        }
    }
    return str_return_text;
}

function func_is_max_length(param_text,param_num)
{
    var i_length;
    var str_text=new String(func_trim(param_text));
    i_length=func_len(str_text);
    if (i_length>param_num)
    {
        return false;
    }
    else
    {
        return true;
    }
}

function func_len(param_text)
{
    var str_text=new String(func_trim(param_text));
    return str_text.length;
}

function func_is_numeric(param_text)
{
    if(!isNaN(param_text))
    {
        return true;
    }
    else
    {
        return false;
    }
}

function func_is_positive_integer(param_text)
{
var b_is_positive_integer=true;
var str_text=new String(func_trim(param_text));
var i_loop;
for(i_loop=0;i_loop    {
if(!(str_text.charAt(i_loop)>="0" && str_text.charAt(i_loop)<="9"))
{
b_is_positive_integer=false;
break;
}
}
if(b_is_positive_integer)
    {
var i_integer=new Number(str_text);
if(i_integer.valueOf()<=0)
{
b_is_positive_integer=false;
}
    }
return b_is_positive_integer;
}

function func_is_non_negative_integer(param_text)
{
var i_length;
var b_is_non_negative_integer=true;
var str_text=new String(func_trim(param_text));
var i_loop;
for(i_loop=0;i_loop    {
if(!(str_text.charAt(i_loop)>="0" && str_text.charAt(i_loop)<="9"))
{
b_is_non_negative_integer=false;
break;
}
    }
if(b_is_non_negative_integer)
    {
var i_integer=new Number(param_text);
if(i_integer.valueOf()<0)
{
b_is_non_negative_integer=false;
}
    }
return b_is_non_negative_integer;
}

function func_is_integer(param_text)
{
var i_length;
var b_is_integer=true;
var str_text=new String(func_trim(param_text));
var i_loop;
for(i_loop=0;i_loop    {
if(!(str_text.charAt(i_loop)>="0" && str_text.charAt(i_loop)<="9"))
{
b_is_integer=false;
break;
}
    }
return b_is_integer;
}

function func_is_real_number(param_text)
{
var i_length;
var b_is_real_number=true;
var str_text=new String(func_trim(param_text));
var i_loop;
for(i_loop=0;i_loop    {
if(!((str_text.charAt(i_loop)>="0" && str_text.charAt(i_loop)<="9") || (str_text.charAt(i_loop)==".") || (str_text.charAt(i_loop)=="+") || (str_text.charAt(i_loop)=="-") || (str_text.charAt(i_loop)=="e") || (str_text.charAt(i_loop)=="E")))
{
b_is_real_number=false;
break;
}
    }
return b_is_real_number;
}

function func_is_positive_real_number(param_text)
{
var i_length;
var b_is_positive_real_number=true;
var str_text=new String(func_trim(param_text));
var i_loop;
for(i_loop=0;i_loop    {
if(!((str_text.charAt(i_loop)>="0" && str_text.charAt(i_loop)<="9") || (str_text.charAt(i_loop)==".") || (str_text.charAt(i_loop)=="+") || (str_text.charAt(i_loop)=="-") || (str_text.charAt(i_loop)=="e") || (str_text.charAt(i_loop)=="E")))
{
b_is_positive_real_number=false;
break;
}
    }
if(b_is_positive_real_number)
    {
var i_real_number=new Number(str_text);
if(i_real_number.valueOf()<=0.0)
{
b_is_positive_real_number=false;
}
    }
return b_is_positive_real_number;
}

function func_is_non_negative_real_number(param_text)
{
var i_length;
var b_is_non_negative_real_number=true;
var str_text=new String(func_trim(param_text));
var i_loop;
for(i_loop=0;i_loop    {
if(!((str_text.charAt(i_loop)>="0" && str_text.charAt(i_loop)<="9") || (str_text.charAt(i_loop)==".") || (str_text.charAt(i_loop)=="+") || (str_text.charAt(i_loop)=="-") || (str_text.charAt(i_loop)=="e") || (str_text.charAt(i_loop)=="E")))
{
b_is_non_negative_real_number=false;
break;
}
    }
if(b_is_non_negative_real_number)
    {
var i_real_number=new Number(str_text);
if(i_real_number.valueOf()<0.0)
{
b_is_non_negative_real_number=false;
}
    }
return b_is_non_negative_real_number;
}

function func_is_email(param_email)
{
var str_current_character;
var b_valid_email,b_period_present;
var i_last_position_of_period,b_correct_length_extension;
var i_num_at_symbol=0;
var i_pos_at_symbol;
var i_length_of_server_name=1;
var i_pos_consecutive_dots;
var str_email=new String(func_trim(param_email));
i_length=str_email.length;
b_period_present=1;
b_correct_length_extension=1;
i_last_position_of_period=0;

if(i_length==0)
    {
return true;
    }

for(i_loop=0; i_loop {
if(!((str_email.charCodeAt(i_loop)>=65 && str_email.charCodeAt(i_loop)<=90)
|| (str_email.charCodeAt(i_loop)>=97 && str_email.charCodeAt(i_loop)<=122)
|| (str_email.charCodeAt(i_loop)>=48 && str_email.charCodeAt(i_loop)<=57)
|| (str_email.charAt(i_loop)=="@")
|| (str_email.charAt(i_loop)=="_")
|| (str_email.charAt(i_loop)=="-")
|| (str_email.charAt(i_loop)==".")))
{
return false;
}
    }

i_pos_consecutive_dots=str_email.indexOf('..');
if(i_pos_consecutive_dots!=-1)
    {
return false;
    }

var i_pos_space;
i_pos_space = str_email.indexOf(' ');
if(i_pos_space!=-1)
    {
return false;
    }

i_last_position_of_period = str_email.lastIndexOf('.');
if(i_last_position_of_period<=0)
    {
b_period_present=0;
    }
if(((i_length-i_last_position_of_period)>5) || ((i_length-i_last_position_of_period)<3))
    {
b_correct_length_extension=0;
    }

for(i_loop=0;i_loop<=i_length;i_loop++)
    {
str_current_character=str_email.charAt(i_loop);
if (str_current_character=='@')
{
i_num_at_symbol=i_num_at_symbol + 1;
}
    }

if(i_num_at_symbol!=1)
    {
return false;
    }

i_pos_at_symbol = str_email.indexOf('@');
if(str_email.charAt(i_pos_at_symbol+1) == '.')
    {
i_length_of_server_name=0;
    }

if((i_num_at_symbol==1) && (b_period_present==1) && (b_correct_length_extension==1) && (i_length_of_server_name==1))
    {
b_valid_email=1;
    }
else
    {
b_valid_email=0;
    }

if(b_valid_email==0)
    {
return false;
    }
else
    {
return true;
    }
}

function func_is_min_length(param_text,param_num)
{
var i_length;
var str_text=new String(param_text);
i_length = func_len(str_text);
if (i_length    {
return false;
    }
else
    {
return true;
    }
}

//isTelephoneNumber -returns true if it is valid Telephone or Fax Number.allowing +-.()
function func_is_telephone_number(param_text)
{
var b_is_telephone_number=true;
if(func_trim(param_text)!="")
    {
var str_text=new String(func_trim(param_text));
var i_length=func_len(str_text);
var i_loop;
for (i_loop=0;i_loop {
if (!((str_text.charCodeAt(i_loop) >= 48 && str_text.charCodeAt(i_loop) <= 57) || (str_text.charAt(i_loop) == "-")|| (str_text.charAt(i_loop) == "(")|| (str_text.charAt(i_loop) == ")") || (str_text.charAt(i_loop) == "+") || (str_text.charCodeAt(i_loop) ==32) || (str_text.charAt(i_loop) == ".")))
{
b_is_telephone_number=false;
}
}
    }
return b_is_telephone_number;
}

function func_is_us_phone(phonenumber)
{
if((phonenumber.match(/^[ ]*[(]{0,1}[ ]*[0-9]{3,3}[ ]*[)]{0,1}[-]{0,1}[ ]*[0-9]{3,3}[ ]*[-]{0,1}[ ]*[0-9]{4,4}[ ]*$/)==null) && (phonenumber.match(/^[ ]*[0-9]{3,3}[ ]*[-]{0,1}[ ]*[0-9]{4,4}[ ]*$/)==null)) return false;
else
return true;
}


function func_is_fax_number(param_text)
{
var b_is_fax_number=true;
if(func_trim(param_text)!="")
    {
var str_text=new String(func_trim(param_text));
var i_length=func_len(str_text);
var i_loop;
for (i_loop=0; i_loop {
if (!((str_text.charCodeAt(i_loop)>=48 && str_text.charCodeAt(i_loop)<=57) || (str_text.charAt(i_loop)=="-") || (str_text.charAt(i_loop)=="(") || (str_text.charAt(i_loop)==")") || (str_text.charAt(i_loop)=="+") || (str_text.charCodeAt(i_loop)==32) || (str_text.charAt(i_loop)==".")))
{
b_is_fax_number=false;
}
}
    }
return b_is_fax_number;
}

function func_is_zip(field)
{
var valid = "0123456789-";
var hyphencount = 0;
var b_correct = true;
if (field.length!=5 && field.length!=10)
    {
b_correct = false;
    }
if(b_correct)
    {
for (var i=0; i < field.length; i++)
{
temp = "" + field.substring(i, i+1);
if (temp == "-") hyphencount++;
if (valid.indexOf(temp) == "-1")
{
b_correct = false;
}
if(b_correct)
{
if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-"))
{
b_correct = false;
}
}
}
    }
return b_correct;
}


function func_is_zip2(param_text)
{
var b_is_zip=true;
if(func_trim(param_text)!="")
    {
var str_text=new String(func_trim(param_text));
var i_length=func_len(str_text);
var i_loop;
if(i_length <5)
b_is_zip=false;
else
{
for (i_loop=0; i_loop {
if (!((str_text.charCodeAt(i_loop)>=48 && str_text.charCodeAt(i_loop)<=57) || (str_text.charAt(i_loop)=="-") || (str_text.charAt(i_loop)=="(") || (str_text.charAt(i_loop)==")") || (str_text.charCodeAt(i_loop)==32)))
{
b_is_zip=false;
}
}
}
    }
return b_is_zip;
}

function func_is_alpha_numeric(param_text)
{
var str_text=new String(func_trim(param_text));
var i_loop;
var b_is_alpha_numeric=true;
for (i_loop=0;i_loop    {
if (!((str_text.charCodeAt(i_loop)>=65 && str_text.charCodeAt(i_loop)<=90) || (str_text.charCodeAt(i_loop)>=97 && str_text.charCodeAt(i_loop)<=122) || (str_text.charCodeAt(i_loop)>=48 && str_text.charCodeAt(i_loop)<=57)))
{
b_is_alpha_numeric=false;
}
}
return b_is_alpha_numeric;
}

function func_is_alphabet(param_text)
{
var str_text=new String(func_trim(param_text));
var i_loop;
var b_is_alphabet=true;
for(i_loop=0;i_loop    {
if (!((str_text.charCodeAt(i_loop)>=65 && str_text.charCodeAt(i_loop)<=90) || (str_text.charCodeAt(i_loop)>=97 && str_text.charCodeAt(i_loop)<=122)))
{
b_is_alphabet=false;
}
    }
return b_is_alphabet;
}

function func_is_date(i_date,i_month,i_year)
{
var b_correct_date;
var dt_date=new Array(3);
b_correct_date=4;
dt_date[0]=i_date;
dt_date[1]=i_month;
dt_date[2]=i_year;
if(b_correct_date==4 && (dt_date[0]>31 || dt_date[0]<1))
    {
b_correct_date=1;
alert("Illegal value for date" );
    }
if(b_correct_date==4 && (dt_date[1]>12 || dt_date[1]<1))
    {
b_correct_date=2;
alert('Illegal value for month');
    }
if(b_correct_date==4 && dt_date[2]<=0)
    {
b_correct_date=3;
alert('Illegal value for year');
    }
if(b_correct_date==4 && ((dt_date[1]==1 || dt_date[1]==3 || dt_date[1]==5 || dt_date[1]==7 || dt_date[1]==8 || dt_date[1]==10 ||dt_date[1]==12) && (dt_date[0]>31 || dt_date[0]<1)))
    {
b_correct_date=1;
alert('Illegal value for date.MonthName and date mismatch');
    }
if(b_correct_date==4 && ((dt_date[1]==4 || dt_date[1]==6 || dt_date[1]==9 || dt_date[1]==11) && (dt_date[0]>30 || dt_date[0]<1)))
    {
b_correct_date=1;
alert('Illegal value for date.Monthname and date mismatch');
    }
var i_year;
i_year=dt_date[2];
if((i_year % 400)>0)
    {
if((i_year % 100)>0 && (i_year % 4)==0) //leap year
{
if(b_correct_date==4 && dt_date[1]==2 && dt_date[0]>29)
{
b_correct_date=1;
alert('Illegal value for date.In that year, February cannot have that day.');
}
}
else
{
if(b_correct_date==4 && dt_date[1]==2 && dt_date[0]>28)
{
b_correct_date=1;
alert('Illegal value for date.In that year, February cannot have that day.');
}
}
    }
else
    {
if(b_correct_date==4 && dt_date[1]==2 && dt_date[0]>29)
{
b_correct_date=1;
alert('Illegal value for date.In that year, February cannot have that day.');
}
    }
return b_correct_date;
}

function func_is_url(param_url)
{
var str_url=new String(func_trim(param_url));
b_correct_length_extension=1;
var i_length=str_url.length;
var str_prefix=str_url.slice(7);
b_period_present=1;
b_correct_length_extension=1;
var i_loop;
if(str_prefix.toLowerCase()=="http://" && str_url.length==7)
    {
return false;
    }

for(i_loop=0; i_loop    {
if(!((str_url.charCodeAt(i_loop)>=65 && str_url.charCodeAt(i_loop)<=90)
|| (str_url.charCodeAt(i_loop)>=97 && str_url.charCodeAt(i_loop)<=122)
|| (str_url.charCodeAt(i_loop)>=48 && str_url.charCodeAt(i_loop)<=57)
|| (str_url.charAt(i_loop)=="/")
|| (str_url.charAt(i_loop)==":")
|| (str_url.charAt(i_loop)=="_")
|| (str_url.charAt(i_loop)=="-")
|| (str_url.charAt(i_loop)==".")))
{
return false;
}
    }

var i_pos_consecutive_dots=str_url.indexOf('..');
if(i_pos_consecutive_dots!=-1)
    {
return false;
    }

var i_pos_space;
i_pos_space = str_url.indexOf(' ');
if(i_pos_space!=-1)
    {
return false;
    }

var i_last_position_of_period = str_url.lastIndexOf('.');
if(i_last_position_of_period<=0)
    {
b_period_present=0;
    }

if(((i_length-i_last_position_of_period)>4) || ((i_length-i_last_position_of_period)<3))
    {
b_correct_length_extension=0;
    }

if((b_period_present==0) || (b_correct_length_extension==0))
    {
return false;
    }

return true;
}

function func_is_combo_selected(obj_combo)
{
var i_loop;
if(obj_combo.selectedIndex>0 && obj_combo.options[obj_combo.selectedIndex].value!="")
    {
return true;
    }
else
    {
return false;
    }
}

function func_is_option_selected(obj_radio)
{
var i_loop;
for (i_loop=0; i_loop    {
if ((obj_radio[i_loop].checked) && (obj_radio[i_loop].value != ""))
{
return true;
}
    }
return false;
}

function func_start()
{

}

//select All checkboxes starting with..
function func_select_all_checkboxes(str_form_name,str_search_chars,str_select_all)
{
var obj_form=eval("document." + str_form_name);
for(var i=0; i    {
if(obj_form.elements[i].type == "checkbox")
{
var str_checkbox_name = new String(obj_form.elements[i].name);
if(str_checkbox_name.indexOf(str_search_chars) != -1)
{
var obj_checkbox = eval("document." + str_form_name + "." + str_checkbox_name);
if(eval("document." + str_form_name + "." + str_select_all + ".checked")==true)
obj_checkbox.checked = true;
else
obj_checkbox.checked = false;
}
}
    }
}

//unselect the checkbox named "ALL" when any one of the other checkboxe(s) unselected.
function func_unselect_checkbox(str_form_name,str_search_chars,str_select_all)
{
var b_correct=true;
var obj_form=eval("document." + str_form_name);
for(var i=0; i    {
if(obj_form.elements[i].type == "checkbox")
{
var str_checkbox_name = new String(obj_form.elements[i].name);
if(str_checkbox_name.indexOf(str_search_chars) != -1)
{
var obj_checkbox = eval("document." + str_form_name + "." + str_checkbox_name);
if(obj_checkbox.checked==false)
b_correct=false;
}
}
    }
var obj_checkbox_all=eval("document." + str_form_name + "." + str_select_all);
if (obj_checkbox_all != null)
    {
if(b_correct)
obj_checkbox_all.checked=true;
else
obj_checkbox_all.checked=false;
    }
}

//selected checkbox values are stored in the hidden field with "," as delimiter
function func_store_selected_checkboxes(str_form_name,str_hidden_name,str_search_chars)
{
var obj_form=eval("document." + str_form_name);
var obj_hidden=eval("document." + str_form_name + "." + str_hidden_name);
var i_length=str_search_chars.length;
eval("document." + str_form_name + "." + str_hidden_name).value="";
for(var iLoop=0;iLoop    {
if(obj_form.elements[iLoop].type=="checkbox")
{
var str_checkbox_name=new String(obj_form.elements[iLoop].name);
if(str_checkbox_name.slice(0,i_length)==str_search_chars)
{
if(obj_form.elements[iLoop].checked==true)
{
obj_hidden.value+=(obj_hidden.value=="") ? str_checkbox_name.slice(i_length) : ("," + str_checkbox_name.slice(i_length));
}
}
}
    }
//alert(obj_hidden.value);
}

function func_is_checkbox_selected(obj_form,str_checkbox_prefix)
{
var b_correct=false;
for(var i=0; i    {
var str_name=obj_form.elements[i].name;
var str_type=obj_form.elements[i].type;
if((str_type=="checkbox") && (str_name.indexOf(str_checkbox_prefix)!=-1))
{
var b_checked=obj_form.elements[i].checked;
if(b_checked==true)
{
b_correct = true;
break;
}
}
    }
return b_correct;
}

function invalidemail(y)
{
var len = y.length;
if (len < 1)
    {
return true;
    }
var i = 0;
for (i=0; i    {
if (!((y.charCodeAt(i) >= 65 && y.charCodeAt(i) <= 90)
|| (y.charCodeAt(i) >= 97 && y.charCodeAt(i) <= 122)
|| (y.charCodeAt(i) >= 48 && y.charCodeAt(i) <= 57)
|| (y.charAt(i) == "@")
|| (y.charAt(i) == "_")
|| (y.charAt(i) == ".")))
{
return true;
}
    }
var at = y.indexOf("@");
if (at < 0)
    {
return true;
    }
i = 0;
var dot;
dot = y.indexOf(".", at);
if (!(dot > 1))
    {
return true;
    }
return false;
}

function isValidURL(strText)
{
var bcorrect=true;
if(bcorrect && isNull(strText))
    {
return true;
    }
if(bcorrect && strText.indexOf("/")!=-1)
    {
strText=strText.substring(0,strText.indexOf("/"));
    }

var len = strText.length;

//validate the characters allowed
if(bcorrect)
    {
var i = 0;
for (i=0; i {
if (!((strText.charCodeAt(i) >= 65 && strText.charCodeAt(i) <= 90)
|| (strText.charCodeAt(i) >= 97 && strText.charCodeAt(i) <= 122)
|| (strText.charCodeAt(i) >= 48 && strText.charCodeAt(i) <= 57)
|| (strText.charAt(i) == "-")
|| (strText.charAt(i) == "_")
|| (strText.charAt(i) == ".")))
{
bcorrect=false;
}
}
    }

if(bcorrect && strText.indexOf("..")!=-1)
bcorrect=false;
if(bcorrect && strText.indexOf("-")==0)
bcorrect=false;
if(bcorrect && strText.indexOf("_")==0)
bcorrect=false;
if(bcorrect && strText.indexOf(".")==0)
bcorrect=false;
if(bcorrect && strText.indexOf(".")==-1)
bcorrect=false;

//validate last index of '.' and number of chars next to that
if(bcorrect)
    {
var iLastPos=strText.lastIndexOf('.');
var iMinChar=len - iLastPos;
if(iMinChar<3 || iMinChar>5)
bcorrect=false;
    }

//validate extension
if(bcorrect)
    {
var strExtension=strText.substring(strText.lastIndexOf('.')+1);
if(!isAlphaNumeric(strExtension))
bcorrect=false;
    }
return bcorrect;
}

function isNotNumeric(n)
{
if (n == "")
    {
return true;
    }
var len = n.length;
var i = 0;
for (i=0; i    {
if (!((n.charCodeAt(i) >= 48) && (n.charCodeAt(i) <= 57)))
{
return true;
}
    }
return false;
}

function containsBlank(s)
{
var len = s.length;
for (i=0; i    {
if (s.charAt(i) == " ")
{
return true;
}
    }
return false;
}

function isBlank(StrText)
{
if (StrText.length < 0)
    {
return true;
    }
for (var i=0; i    {
if (StrText.charAt(i) != " ")
{
return false;
}
    }
return true;
}

function getSelectedOption(OItem)
{
var optionValue = "";
for (var i=0; i    {
if (OItem.options[i].selected == true)
{
optionValue = OItem.options[i].value;
return optionValue;
}
    }
}

function optionSelected(OItem)
{
for (var i=0; i    {
if ((OItem.options[i].selected == true) && (OItem.options[i].value != ""))
{
return true;
}
    }
return false;
}

function isValidDate(iYear, iMonth, iDay)
{
if (isNaN(iYear) || isNaN(iMonth) || isNaN(iDay))
    {
return false;
    }
var dtNewDate = new Date(iYear, (iMonth-1), iDay);
if ((parseInt(dtNewDate.getFullYear()) == iYear)
&& (parseInt(dtNewDate.getMonth()) == (iMonth-1))
&& (parseInt(dtNewDate.getDate()) == iDay))
{
return true;
}
return false;
}

//Returns true if "text" is alphanumeric
function isAlphaNumeric(text)
{
var str = new String(text);
for (var i=0;i    {
if (!((str.charCodeAt(i)>=65 && str.charCodeAt(i)<=90) || (str.charCodeAt(i)>=97 && str.charCodeAt(i)<=122) || (str.charCodeAt(i)>=48 && str.charCodeAt(i)<=57)))
{
return false;
}
}
return true;
}

// returns true if the given text is Null
function isNull(text)
{
if((trim(text) == "") || (text == null))
    {
//alert("Must not be Null Sring");
return true;
    }
else
    {
return false;
    }
}

// returns true if length of the text is greater than given num.
function isMaxLength(text,num)
{
var strlen;
var text=new String(text);
strlen = len(text);
if (strlen > num)
    {
//alert(" Must not be greater than maximum " + num + " characters ");
return true;
    }
else
    {
return false;
    }
}

// returns true if length of the text is less than given value.
function isMinLength(text,num)
{
var strlen;
var text=new String(text);
strlen = len(text);
if (strlen < num)
    {
//alert(" Must not be Less than minimum " + num + " characters ");
return true;
    }
else
    {
return false;
    }
}

// returns true if the text is Number and false if it is not a number.
function isNumber(text)
{
var ilen;
var bflagNum=true;
var text=new String(text);
if (isNaN(text))
    {
return false;
    }
else
    {
return true;
    }
}

// returns true if valid Email.
function isEmail(emailval)
{
var tempStr,icount;
var blnmail,blnperiod;
var lastoccofperiod,maxthree;
var ampicount=0;
var amppos;
var servername = 1;
var dots;
icount=emailval.length;
blnperiod = 1;
maxthree = 1;
specialchar = 0
lastoccofperiod = 0;
if (icount==0)
    {
return true;
    }
for(i=0;i    {
tempStr = emailval.charAt(i);
if ((tempStr >='a')&&(tempStr <='z'))
{
specialchar=specialchar+1;
}
else
    {
if ((tempStr >='A')&&(tempStr <='Z'))
{
specialchar=specialchar+1;
}
else
{
if ((tempStr >= 0)&&(tempStr<=9))
{
specialchar=specialchar+1;
}
else
{
if ((tempStr=='_')||(tempStr=='-')||(tempStr=='.')||(tempStr=='@'))
{
specialchar=specialchar+1;
}
else
{
return false;
}
}
}
}
    }
dots = emailval.indexOf('..');
if (dots != -1)
    {
return false;
    }
espace = emailval.indexOf(' ');
if (espace != -1)
    {
return false;
    }
lastoccofperiod = emailval.lastIndexOf('.');
if (lastoccofperiod <= 0)
    {
blnperiod = 0;
    }
if (((icount - lastoccofperiod) > 4)||((icount - lastoccofperiod) < 3))
    {
maxthree = 0;
    }
for(i=0;i<=icount;i++)
    {
tempStr = emailval.charAt(i)
if (tempStr=='@')
ampicount=ampicount + 1;
    }
amppos = emailval.indexOf('@');
if (emailval.charAt(amppos+1) == '.')
servername = 0;
if(icount - emailval.charAt(amppos)< 5)
servername = 0;
if ((ampicount==1)&&(blnperiod==1)&&(maxthree==1)&&(servername==1))
    {
blnmail=1;
    }
else
    {
blnmail=0;
    }
//return blnmail;
if (blnmail==0)
    {
//alert('Please enter a valid email address');
return false;
    }
else
    {
return true;
    }
}

//returns true if the text carries only alphabets.
function isAlphabetic(textval)
{
var text=new String(textval);
var ilen;
var bflag=true;
for(ilen=0;ilen<=text.length;ilen++)
    {
if(text.charCodeAt(ilen) < 65 || text.charCodeAt(ilen) > 90 && text.charCodeAt(ilen) < 97 || text.charCodeAt(ilen) > 122)
{
bflag=false;
}
    }
return bflag;
}

function isCurrency(text)
{
var bflag=true;
if(text != "")
    {
var k = len(text);
var i;
for (i=0; i {
if (!((text.charCodeAt(i) >= 48 && text.charCodeAt(i) <= 57) || (text.charAt(i) == ".")))
{
bflag=false;
}
}
    }
return bflag;
}
//isTelephoneNumber -returns true if it is valid Telephone or Fax Number.allowing +-.()
function isTelephoneNumber(text)
{
var bflag=true;
if(text != "")
    {
var k = len(text);
var i;
for (i=0; i {
if (!((text.charCodeAt(i) >= 48 && text.charCodeAt(i) <= 57) || (text.charAt(i) == "-")|| (text.charAt(i) == "(")|| (text.charAt(i) == ")") || (text.charAt(i) == "+") || (text.charAt(i) == ".")|| (text.charAt(i) == " ")))
{
bflag=false;
}
}
    }
return bflag;
}

//returns true if it is valid date.
function isDate(date,month,year)
{
var bflag=true;
if (isNaN(year) || isNaN(month) || isNaN(date))
    {
bflag=false;
    }
if(bflag)
    {
var dtnew = new Date(year,month-1,date);
if ((parseInt(dtnew.getFullYear()) == year) && (parseInt(dtnew.getMonth()) == (month-1)) && (parseInt(dtnew.getDate()) == date))
{
bflag=true;
}
else
{
bflag=false;
}
    }
return bflag;
}

//returns string by removing whitespaces from both the ends.
function trim(text)
{
var stext = new String(text);
var sresult = "";
//Remove leading spaces
for (var i=0; i    {
if (stext.charAt(i) != " ")
{
sresult = stext.substr(i, (stext.length - i));
break;
}
    }
stext = sresult;
//Remove trailing spaces
for (var j=(stext.length - 1); j>=0; j--)
    {
if (stext.charAt(j) != " ")
{
sresult = stext.substr(0, (j + 1));
break;
}
    }
return sresult;
}

// returns length of the text
function len(text)
{
var strText=new String(text);
return strText.length;
}

// selecting & focusing on the element that holds incorrect value
function selectFocus(element)
{
element.select();
element.focus();
return true;
}

//returns true if a radio button is checked
function IsRadioChecked(objForm,strName)
{
var bcorrect;
bcorrect=false;
for(i=0; i    {
var name=objForm.elements[i].name;
var type=objForm.elements[i].type;
if((type=="radio") && (name.indexOf(strName)!=-1))
{
var val=objForm.elements[i].checked;
if(val==true)
{
bcorrect=true;
break;
}
}
    }
return bcorrect;
}

//returns true if atleast one check box is selected
function IsCheckboxSelected(objForm,strName)
{
var bcorrect=false;
for(var i=0; i    {
var name=objForm.elements[i].name;
var type=objForm.elements[i].type;
if((type=="checkbox") && (name.indexOf(strName)!=-1))
{
var val=objForm.elements[i].checked;
if(val==true)
{
bcorrect = true;
break;
}
}
    }
return bcorrect;
}

/* Validation functions ends here. */






/* HTML Element Validation functions starts here..... */

//HTML Element "Text box" validations (includes text area also.)
function ValidateTextBox(strName,obj,bZeroLength,iMaxChars,bAlphabet,bNumeric,bAlphanumeric,bEmail,bTelNumber,bURL,bFile,strFileType,bCurrency)
{
var bCorrect=true;

//Zerolength validation is optional, if bZeroLength is true then textbox value is checked for zerolength.
if(bCorrect && bZeroLength)
    {
if(isNull(obj.value))
{
bCorrect=false;
alert("Please enter the " + strName);
selectFocus(obj);
}
    }

//MaxLength is not optional
if(bCorrect)
    {
if(isMaxLength(obj.value,iMaxChars))
{
bCorrect=false;
alert(strName + " is greater than " + iMaxChars + " characters.");
selectFocus(obj);
}
    }

//Alphabet validation is optional, if bAlphabet is true then textbox value is checked for Alphabets.
if(bCorrect && bAlphabet)
    {
if(!isAlphabetic(obj.value))
{
bCorrect=false;
alert(strName + " must have only alphabets.");
selectFocus(obj);
}
    }

//Numeric validation is optional, if bNumeric is true then textbox value is checked for Numeric.
if(bCorrect && bNumeric)
    {
if(!isNumber(obj.value))
{
bCorrect=false;
alert(strName + " must have only numbers.");
selectFocus(obj);
}
    }

//Alphanumeric validation is optional, if bAlphanumeric is true then textbox value is checked for Alphanumeric.
if(bCorrect && bAlphanumeric)
    {
if(!isAlphaNumeric(obj.value))
{
bCorrect=false;
alert(strName + " must have only alphanumeric characters.");
selectFocus(obj);
}
    }

//Email validation is optional, if bEmail is true then textbox value is checked for Email.
if(bCorrect && bEmail)
    {
if(!isEmail(obj.value))
{
bCorrect=false;
alert(strName + " entered is not a valid email address.");
selectFocus(obj);
}
    }

//TelNumber validation is optional, if bTelNumber is true then textbox value is checked for TelNumber.
if(bCorrect && bTelNumber)
    {
if(!isTelephoneNumber(obj.value))
{
bCorrect=false;
alert(strName + " is not a valid telephone/fax number.");
selectFocus(obj);
}
    }

//URL validation is optional, if bURL is true then textbox value is checked for URL.
if(bCorrect && bURL)
    {
if(!isValidURL(obj.value))
{
bCorrect=false;
alert(strName + " is not a valid URL.");
selectFocus(obj);
}
    }
if(bCorrect && bFile)
    {
if(!isFile(obj.value,strFileType))
{
bCorrect=false;
alert(strName + " is not a valid File Type.");
selectFocus(obj);
}
    }
if(bCorrect && bCurrency)
    {
if(!isCurrency(obj.value))
{
bCorrect=false;
alert(strName + " is not a valid number.");
selectFocus(obj);
}
    }
return bCorrect;
}


//HTML Element "Drop-down list" validations
function ValidateDropdownList(strName,obj,bSelect,iMaxChars)
{
var bCorrect=true;

//Select validation is optional, if bSelect is true then textbox value is checked for Selection.
if(bCorrect && bSelect)
    {
if(getSelectedOption(obj)=="")
{
bCorrect=false;
alert(strName + " is not selected.");
obj.focus();
}
    }

//MaxLength is not optional
if(bCorrect)
    {
if(isMaxLength(getSelectedOption(obj),iMaxChars))
{
bCorrect=false;
alert(strName + " is greater than " + iMaxChars + " characters.");
obj.focus();
}
    }

return bCorrect;
}

//HTML Element "Radio button" validations
function ValidateRadioButton(strLabel,strRadioName,objForm,bChecked)
{
var bCorrect=true;

//Radio button validation is optional, if bChecked is true then it is checked for Selection.
if(bCorrect && bChecked)
    {
if(!IsRadioChecked(objForm,strRadioName))
{
bCorrect=false;
alert(strLabel + " is not selected.");
}
    }
return bCorrect;
}

//HTML Element "Check box" validations
function ValidateCheckBox(strLabel,strCheckBoxName,objForm,bChecked)
{
var bCorrect=true;

//Check box validation is optional, if bChecked is true then it is checked for Selection.
if(bCorrect && bChecked)
    {
if(!IsCheckboxSelected(objForm,strCheckBoxName))
{
bCorrect=false;
alert(strLabel + " is not selected.");
}
    }
return bCorrect;
}

// validate date box.
function ValidateDateBox(strLabel,obj,iMonth,iDay,iYear,bSelected,bFutureDate,bPastDate)
{
var bcorrect=true;
if(bSelected)
    {
if(bcorrect && !isDate(iDay,iMonth,iYear))
{
bcorrect=false;
alert("Please select a valid " + strLabel + ".");
obj.focus();
}
    }
if(iDay!="" && iMonth!="" && iYear!="")
    {
if(bcorrect && !isDate(iDay,iMonth,iYear))
{
bcorrect=false;
alert("Please select a valid " + strLabel + ".");
obj.focus();
}
    }
if (bFutureDate)
    {
if(bcorrect)
{
var dtnew = new Date(iYear,iMonth-1,iDay);
var dtnow = new Date();
if(dtnew {
bcorrect=false;
alert("Please select a valid future date.");
obj.focus();
}
}
    }
if(bPastDate)
    {
if(bcorrect)
{
var dtnew = new Date(iYear,iMonth-1,iDay);
var dtnow = new Date();
if(dtnew>dtnow)
{
bcorrect=false;
alert("Please select a valid past date.");
obj.focus();
}
}
    }
return bcorrect;
}


//select All checkboxes starting with..
function SelectAllCheckBoxes(strFormName,strSearchChars,strSelectAll)
{
var objForm=eval("document." + strFormName);
for(var i=0; i    {
if(objForm.elements[i].type == "checkbox")
{
var strCheckBoxName = new String(objForm.elements[i].name);
if(strCheckBoxName.indexOf(strSearchChars) != -1)
{
var objCheckBox = eval("document." + strFormName + "." + strCheckBoxName);
if(eval("document." + strFormName + "." + strSelectAll + ".checked")==true)
objCheckBox.checked = true;
else
objCheckBox.checked = false;
}
}
    }
}

//unselect the checkbox named "ALL" when any one of the other checkboxe(s) unselected.
function UnSelectCheckBox(strFormName,strSearchChars,strSelectAll)
{
var bcheckbox=true;
var objForm=eval("document." + strFormName);
for(var i=0; i    {
if(objForm.elements[i].type == "checkbox")
{
var strCheckBoxName = new String(objForm.elements[i].name);
if(strCheckBoxName.indexOf(strSearchChars) != -1)
{
var objCheckBox = eval("document." + strFormName + "." + strCheckBoxName);
if(objCheckBox.checked==false)
bcheckbox=false;
}
}
    }
var objCheckBoxAll=eval("document." + strFormName + "." + strSelectAll);
if (objCheckBoxAll != null)
    {
if(bcheckbox)
objCheckBoxAll.checked=true;
else
objCheckBoxAll.checked=false;
    }
}

//selected checkbox values are stored in the hidden field with "," as delimiter
function StoreSelectedCheckBoxes(strFormName,strHiddenName,strSearchChars)
{
var objForm=eval("document." + strFormName);
var objHidden=eval("document." + strFormName + "." + strHiddenName);
var iLen=strSearchChars.length;
eval("document." + strFormName + "." + strHiddenName).value="";
for(var iLoop=0;iLoop {
if(objForm.elements[iLoop].type=="checkbox")
{
var strCheckBoxName=new String(objForm.elements[iLoop].name);
if(strCheckBoxName.slice(0,iLen)==strSearchChars)
{
if(objForm.elements[iLoop].checked==true)
{
objHidden.value+=(objHidden.value=="") ? strCheckBoxName.slice(iLen) : ("," + strCheckBoxName.slice(iLen));
}
}
}
    }
//alert(objHidden.value);
}

//Checks whether file type is ends with specified extension or not

function isFile(strValue,strFileType)
{
var bCorrect=false;
strImage=new String(strValue);
var bHtml=false;
var bAll=false;
var bImage=false;
if(strValue.length==0)
    {
return true;
    }
if(strFileType.toLowerCase()=="htm" || strFileType.toLowerCase()=="html")
    {
bHtml=true;
    }
if(strFileType.toLowerCase()=="all")
    {
bAll=true;
    }
if(strFileType.toLowerCase()=="img")
    {
bImage=true;
    }
if(strImage.indexOf(".")!=-1)
    {
iIndex=strImage.indexOf(".");
if(bAll==true)
{
strFile=strImage.substring(iIndex+1);
if(strFile.length>=2)
{
bCorrect=true;
return bCorrect;

}
else
{
bCorrect=false;
return bCorrect;

}
}
else if(bImage==true)
{
if((strImage.substring(iIndex+1)).toLowerCase()=="gif" || (strImage.substring(iIndex+1)).toLowerCase()=="jpg" || (strImage.substring(iIndex+1)).toLowerCase()=="jpeg" || (strImage.substring(iIndex+1)).toLowerCase()=="bmp")
{
bCorrect=true;
return bCorrect;

}
else
{
bCorrect=false;
return bCorrect;

}
}
else if(bHtml==true)
{
if((strImage.substring(iIndex+1)).toLowerCase()=="htm" || (strImage.substring(iIndex+1)).toLowerCase()=="html")
{
bCorrect=true;
return bCorrect;

}
else
{
bCorrect=false;
return bCorrect;

}
}
else
{
if((strImage.substring(iIndex+1)).toLowerCase()==strFileType.toLowerCase())
{
bCorrect=true;
return bCorrect;

}
else
{
bCorrect=false;
return bCorrect;

}
}
    }
else
    {
bCorrect=false;
return bCorrect;
    }
}

function func_popup_open(url)
{
var win_popup = window.open(url, "window", "title=Order Details ,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=850,height=500,left=0,top=0");
}


function func_popup(url,i_width,i_height)
{
var winLeft;
var winTop;
winLeft = (screen.i_width-150)/2;
winTop = (screen.i_height-(-250+110))/2;

var win_popup = window.open(url, "window", "title=HoustonPets ,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width="+i_width+",height="+i_height+",left="+winLeft+",top="+winTop);
}



var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
var i;
for (i = 0; i < s.length; i++){
// Check that current character is number.
var c = s.charAt(i);
if (((c < "0") || (c > "9"))) return false;
}
// All characters are numbers.
return true;
}

function stripCharsInBag(s, bag){
var i;
var returnString = "";
// Search through string's characters one by one.
// If character is not in bag, append to returnString.
for (i = 0; i < s.length; i++){
var c = s.charAt(i);
if (bag.indexOf(c) == -1) returnString += c;
}
return returnString;
}

function daysInFebruary (year){
// February has 29 days in any year evenly divisible by four,
// EXCEPT for centurial years which are not also divisible by 400.
return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
for (var i = 1; i <= n; i++) {
this[i] = 31
if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
if (i==2) {this[i] = 29}
}
return this
}

function is_Date(dtStr)
{
var daysInMonth = DaysArray(12)
var pos1=dtStr.indexOf(dtCh)
var pos2=dtStr.indexOf(dtCh,pos1+1)
var strMonth=dtStr.substring(0,pos1)
var strDay=dtStr.substring(pos1+1,pos2)
var strYear=dtStr.substring(pos2+1)
strYr=strYear
if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
for (var i = 1; i <= 3; i++) {
if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
    }
month=parseInt(strMonth)
day=parseInt(strDay)
year=parseInt(strYr)
if (pos1==-1 || pos2==-1){
alert("The date format should be : mm/dd/yyyy")
return false
    }
if (strMonth.length<1 || month<1 || month>12){
alert("Please enter a valid month")
return false
    }
if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
alert("Please enter a valid day")
return false
    }
if (strYear.length != 4 || year==0 || yearmaxYear){
alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
return false
    }
if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
alert("Please enter a valid date")
return false
    }
return true
}