/*
-- Program: CakeMail Interface
-- Author: The Code Kitchen Inc.
-- Email: info@cakemail.com
-- Date: 10/31/2007
@ [2007] - The Code Kitchen.

This software is subjected to the terms and conditions of the CakeMail Interface
License Agreement, version 1.0. You cannot use this software, except by 
complying to the terms of this license.  In short, the CakeMail interface is 
available for you to download, use, copy, modify, integrate in your own software
and propagate, as long as you agree to use it exclusively with the CakeMail 
hosted application service and application programming interface (API). You can
download a copy of the license at the following URL:
http://www.cakemail.com/license_1.0

This software is propagated "as is", without any warranty of any kind, express
or tacit.  Read the license to learn the exact conditions pertaining to your 
rights and obligations in relation with this work.
*/

String.prototype.trim=function(){
        return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.ltrim=function(){
        return this.replace(/(^\s*)/g,"");
}
String.prototype.rtrim=function(){
        return this.replace(/(\s*$)/g,"");
}

function addslashes_all(str) {
    str = str.replace(/\'/g,'\\\'');
    str = str.replace(/\"/g,'\\"');
    str = str.replace(/\\/g,'\\\\');
    return str;
}


function addslashes(str) {
    str = str.replace(/\"/g,'\\"');
}


function stripslashes_all(str) {
    str = str.replace(/\\'/g,'\'');
    str = str.replace(/\\"/g,'"');
    str = str.replace(/\\\\/g,'\\');
    return str;
}

function popitup(url) {
	newwindow=window.open(url,'name','height=250,width=800');
	if (window.focus) {newwindow.focus()}
	return false;
}

function popitup2(url) {
	newwindow=window.open(url,'name','height=700,width=630');
	if (window.focus) {newwindow.focus()}
	return false;
}


function IsEmpty( val ) {
	re = /\S/i;
	if( re.exec(val)  ) {
		return false;
	}else{
		return true;
	}
}

function HasRealValue( val, default_val ){
	if( val!= default_val && !IsEmpty(val) ) {
		return true;
	}else{
		return false;
	}
}

function checkMail( mail ) {
	var regEmail=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	flag=regEmail.test(mail);
    if(flag) return true;
    return false;

}

function checkDate( date ) {
	var regDate=/^[0-3]{1}\d{1}\/[0-1]{1}\d{1}\/[1-9]{1}\d{3}$/;
	var dArray=date.match(regDate);  
    if (dArray==null){
        return (false);
    }
    else {            
		var dArray = date.split("/");                    
        var y = dArray[2];
        var m = dArray[1];
        var d = dArray[0];
		
        var maxDays = 31;               

        if (m>12 || m<1 ) return false;
        if (m == 4 || m == 6 || m == 9 || m == 11) maxDays = 30;
        else if(m == 2) {
            if ( y % 4 > 0) maxDays = 28;
            else if ( y % 100 == 0 && y % 400 > 0) maxDays = 28;
            else maxDays = 29;
        }
        if (d>maxDays || d<1){
            return false;
        }
        else {
            return true;
        }
    }

}
