function addslashes(str) {
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\0/g,'\\0');
	return str;
}
function stripslashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\0/g,'\0');
	str=str.replace(/\\\\/g,'\\');
	return str;
}

function urlEncode(str) {
    str=str.replace(/\%/g,'%25');
    str=str.replace(/\ /g,'%20');
    str=str.replace(/\"/g,'%22');
    str=str.replace(/\#/g,'%23');
	str=str.replace(/\$/g,'%24');
	str=str.replace(/\&/g,'%26');
	str=str.replace(/\+/g,'%2B');
	str=str.replace(/\,/g,'%2C');
	str=str.replace(/\//g,'%2F');
	str=str.replace(/\:/g,'%3A');
	str=str.replace(/\;/g,'%3B');
	str=str.replace(/\</g,'%3C');
	str=str.replace(/\=/g,'%3D');
	str=str.replace(/\>/g,'%3E');
	str=str.replace(/\?/g,'%3F');
	str=str.replace(/\@/g,'%40');
	str=str.replace(/\[/g,'%5B');
	str=str.replace(/\\/g,'%5C');
	str=str.replace(/\]/g,'%5D');
	str=str.replace(/\^/g,'%5E');
	str=str.replace(/\`/g,'%60');
	str=str.replace(/\{/g,'%7B');
	str=str.replace(/\|/g,'%7C');
	str=str.replace(/\}/g,'%7D');
	str=str.replace(/\~/g,'%7E');
	return str;
}

function isNumeric(str)
{
	var numaric = str;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if (!(hh>47 && hh<59)) {
			 return false;
		  }
		}
 return true;
}

function getUrlVariable( name ) {  
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
	var regexS = "[\\?&]"+name+"=([^&#]*)";  
	var regex = new RegExp( regexS );  
	var results = regex.exec( window.location.href );  
	if( results == null )    
		return "";  
	else    
		return results[1];
}

function modalAlert(message, title) {
	document.getElementById("blackout").style.display = "";
	document.getElementById("modalmessagebox").style.display = "";
	document.getElementById("modalmessagemain").innerHTML = message;
	document.getElementById("modalmessagesub").style.display = "none";
	document.getElementById("modalmessageboxok").innerHTML = "<a href='javascript:closeModalDialog();'>Ok</a>";
	document.getElementById("modalmessageboxcancel").style.display = "none";
}

function closeModalDialog() {
	document.getElementById("blackout").style.display = "none";
	document.getElementById("modalmessagebox").style.display = "none";
}

function showProcessing() {
	if (document.getElementById("blackout") != null) {
		document.getElementById("blackout").style.display = "";
		document.getElementById("modalwaiting").style.display = "";
	}
}

function closeProcessing() {
	if (document.getElementById("blackout") != null) {
		document.getElementById("blackout").style.display = "none";
		document.getElementById("modalwaiting").style.display = "none";
	}
}

function FormatNumber(num, format, shortformat) {

	if(format==null){
		// Choose the default format you prefer for the number. 
		format = "(###) ###-#### ";			// Telephone w/ Area Code
	}					

	if(shortformat==null)
	{
		// Choose the short format (without area code) you prefer. 
		//If you do not want multiple formats, leave it as "".

		//var shortformat = "###-#### ";
		var shortformat = "";
	}
	
	var validchars = "0123456789";
	var tempstring = "";
	var returnstring = "";
	var extension = "";
	var tempstringpointer = 0;
	var returnstringpointer = 0;
	count = 0;

	// Get the length so we can go through and remove all non-numeric characters
	if(num.value != null)
		var length = num.value.length;
		

	// We are only concerned with the format of the phone number - extensions can be left alone.
	if (length > format.length)
	{
		length = format.length;
	};
	
	// scroll through what the user has typed
	for (var x=0; x<length; x++)
	{
		if (validchars.indexOf(num.value.charAt(x))!=-1) {
			tempstring = tempstring + num.value.charAt(x);
		};
	};
	// We should now have just the #'s - extract the extension if needed
	if(num.value != null){
		if (num.value.length > format.length) {
			length = format.length;
			extension = num.value.substr(format.length, (num.value.length-format.length));
		}
	}
	// if we have fewer characters than our short format, we'll default to the short version.
	for (x=0; x<shortformat.length;x++)
	{
		if (shortformat.substr(x, 1)=="#") {
			count++;
		};
	}
	if (tempstring.length <= count) {
		format = shortformat;
	};

	
	//Loop through the format string and insert the numbers where we find a # sign
	for (x=0; x<format.length;x++)
	{
		if (tempstringpointer <= tempstring.length)
		{
			if (format.substr(x, 1)=="#") {
				returnstring = returnstring + tempstring.substr(tempstringpointer, 1);
				tempstringpointer++;
			}else{
				returnstring = returnstring + format.substr(x, 1);
			}
		}
		
	}

	returnstring = returnstring + extension;
	
	if (returnstring.length > format.length) {
		returnstring = returnstring.substring(0, format.length);
	}

	num.value = returnstring;
}


