/*
----------------------------------------------------------
Page Name	    :	CommonValidation.js
Type		    :	Javasciprt file
Purpose			:	Hols the common validations for myWebLeads
Created By	    :	Srinivas
Date		    :	12/24/2006
Version			:	V 1.0       
Notes			:	All common validation functions are written here.
					All common validaiton messages are declared here.
					Each function purpose and usage and inputs and output are written
					Each message varibale purpose and pages declared for are maintained.
----------------------------------------------------------
*/

//-----------------------------------------Global Variables declaration Section Starts------------------
/*
Start of Global Variables section
Section - Global Variables Declaration
Notes - regular expression variables,global variables used in functions are declared in this section
*/

var regExpEmail = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/

/*
End of of Global Variables section
*/

//-----------------------------------------Error / Waring Message Section Starts-------------------------
var msg_common_required = "Required Field."
var msg_common_allspaces = "Invalid Entry-this field must contain at least one character."
var msg_common_email = "Invalid Entry. Enter Email in the format xxxxxxx@xxx.xxx"
var msg_common_zip = "Invalid Entry-Enter valid Zip code."

//-----------------------------------------End of Error / Waring Message Section Starts-------------------------


//-----------------------------------------Common Functions Section Starts Here-------------------------

/* 
function name	:	isEmpty
input			:	Character
ouput			:	boolean (true/false)
Purpose			:	to check whether the value provided is not assigned a value or empty
created by		:	Srinivas	
*/
function isEmpty(s)
	{
		if ((s == "") || (s == null))
			return true;
			return false;
	}
//end of isEmpty

/* 
function name	:	isInteger
input			:	string
ouput			:	boolean (true/false)
Purpose			:	to check whether the value provided is integer
created by		:	Srinivas	
*/

function isInteger(s) 
	{
		var i;
		
		for (i = 0; i < s.length; i++)
		 {
			var c = s.charAt(i);
			if (isIntegerDigit(c)==false) return false;
		}
			return true;
	}//end of isInteger

function isIntegerDigit(c)
	{
		return ((c >= "0") && (c <= "9"))
	}  //end of isIntegerDigit	
	

/* 
function name	:	isEmptyAfterTrim
input			:	string
ouput			:	boolean (true/false)
Purpose			:	to check whether the value provided is of all white spaces/tabs.
created by		:	Srinivas	
*/
function isEmptyAfterTrim(s)
	{
		if (Trim(s) == "")
			return true;
			return false;
	}//end of isEmptyAfterTrim
	
	
// end of isEmptyAfterTrim	

/* 
function name	:	Trim
input			:	string
ouput			:	string
Purpose			:	Trims all spaces to the left and right of a specific string by calling RTim and LTrim
created by		:	Srinivas	
*/	

// Trims all spaces to the left and right of a specific string by calling RTim and LTrim
function Trim(str)
	{
		return RTrim(LTrim(str));
	}

//end function "Trim"

// Trims all spaces to the left of a specific string
function LTrim(str)	
	{
		var whitespace = new String(" \t\n\r "); 
		// last space character is not a space, but alt+0160, 
		// another invisible char. 
		var s = new String(str);
		if (whitespace.indexOf(s.charAt(0)) != -1) {
			// We have a string with leading blank(s)...
			var j=0, i = s.length;
			// Iterate from the far left of string until we
			// don't have any more whitespace...
			while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
				j++;
			// Get the substring from the first non-whitespace
			// character to the end of the string...
			s = s.substring(j, i);
		}//end if
		return s;
	}
//end function "LTrim"
		
// Trims all spaces to the right of a specific string
function RTrim(str)
	{
		// We don't want to trip JUST spaces, but also tabs,
		// line feeds, etc.  Add anything else you want to
		// "trim" here in whitespace
		var whitespace = new String(" \t\n\r "); 
		// last space character is not a space, but alt+0160,
		// another invisible char. 
		var s = new String(str);
		if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
			// We have a string with trailing blank(s)...
			var i = s.length - 1;       // Get length of string
			// Iterate from the far right of string until we
			// don't have any more whitespace...
			while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
				i--;
			// Get the substring from the front of the string to
			// where the last non-whitespace character is...
			s = s.substring(0, i+1);
		}//end if
		return s;
	}
	//end function "RTrim"
	

/* 
function name	:	isValidUSPhone
input			:	string
ouput			:	boolean(true/false)
Purpose			:	check whether the Phone Number is valid
created by		:	Srinivas	
*/
function isValidUSPhone(value) 
	{	
		var reg = /^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$/				
		return reg.test(value);					
	}
//end of isValidUSPhone

/* 
function name	:	isValidUSZIP
input			:	string
ouput			:	boolean(true/false)
Purpose			:	check whether the ZIP code is valid
created by		:	Srinivas	
*/	
function isValidUSZIP(field) 
	{
			var valid = "0123456789-";
			var hyphencount = 0;

			if (field.length!=5 && field.length!=10) {			
			return false;
			}
			for (var i=0; i < field.length; i++) {
			temp = "" + field.substring(i, i+1);
			if (temp == "-") hyphencount++;
			if (valid.indexOf(temp) == "-1") {			
			return false;
			}
			if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) {			
			return false;
			}
			}	
			return true;
	}//end of isValidUSZIP


/* 
function name	:	openWindow
input			:	string
ouput			:	boolean(true/false)
Purpose			:	Function used to Open window with Full Screen Mode
created by		:	rajesh	
*/
function openWindow(mywindow)
{
	window.open(mywindow, 'HomePage');
	return mywindow;
} // End Function openWindow


//Function used to Open Popup and positioning the popup to center of Screen.
function openPopup(mywindow,width,height)
{
	//Height and Width of the Editor
	var w = width;
	var h = height;
	
	//Finding the Top and Left Coordinates for Editor
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;

	//mywindow = 'http://' + document.domain + '/MerlinWebsiteBuilder' + mywindow;
	//mywindow = mywindow;
	window.open(mywindow, 'myWin', 'toolbar=no, directories=no, location=no, status=yes, menubar=no, resizable=no, scrollbars=no, width=' + w + ', height=' + h + ',left=' + winl + ',top=' + wint);
	return mywindow;
}	//End function openPopuup


//Function used to Open Popup and positioning the popup to center of Screen with scrollbars.
function openPopupwithScrollbars(mywindow,width,height)
{
	//Height and Width of the Editor
	var w = width;
	var h = height;
	
	//Finding the Top and Left Coordinates for Editor
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;

	//mywindow = 'http://' + document.domain + '/MerlinWebsiteBuilder' + mywindow;
	//mywindow = mywindow;
	window.open(mywindow, 'myWin', 'toolbar=no, directories=no, location=no, status=yes, menubar=no, resizable=no, scrollbars=yes, width=' + w + ', height=' + h + ',left=' + winl + ',top=' + wint);
	return false;
}	//End function openPopuup


//Function used to Open ModalDialog and positioning the Dialog to center of Screen with scrollbars.
function openModalDialog(mywindow,width,height)
{
	//Height and Width of the Editor
	var w = width;
	var h = height;
	
	//Finding the Top and Left Coordinates for Editor
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;

	//mywindow = 'http://' + document.domain + '/MerlinWebsiteBuilder' + mywindow;
	//mywindow = mywindow;
	
	if (window.showModalDialog)
	{
		window.showModalDialog(mywindow, 'myWin', 'toolbar=no, directories=no, location=no, status=no, menubar=no, resizable=no, scrollbars=yes, width=' + w + ', height=' + h + ',left=' + winl + ',top=' + wint);		
	}
	else
	{
		window.open(mywindow, 'myWin', 'modal,toolbar=no, directories=no, location=no, status=no, menubar=no, resizable=no, scrollbars=yes, width=' + w + ', height=' + h + ',left=' + winl + ',top=' + wint);
	}
	return false;
}	//End function openPopuup





//-----------------------------------------End ofCommon Functions Section Starts Here-------------------------