function sameAddr(val1)
{
	if(val1 === true)
	{
		var addr1 = document.getElementById('id_addr1').value;
		var addr2 = document.getElementById('id_addr2').value;
		var city = document.getElementById('id_city').value;
		var state = document.getElementById('id_state').value;
		var postcode = document.getElementById('id_postcode').value;
		
		document.getElementById('id_m_addr1').value = addr1;
		document.getElementById('id_m_addr2').value = addr2;
		document.getElementById('id_m_city').value = city;
		document.getElementById('id_m_state').value = state;
		document.getElementById('id_m_postcode').value = postcode;
	}
}
function confirmation(val1)
{
	var answer = confirm(val);
	if(answer)
		return true;
	else
		return false;
}
function cc_expriy_date(mth, yr)
{
	var currentTime = new Date();
	var year = currentTime.getFullYear();
	var month = (currentTime.getMonth()+1);
	
	if(yr < year)
		return false;
	else if(yr == year && mth<month)
		return false;
	else
		return true;
}
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function encode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);
   
   return output;
}

function decode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);

   return output;
}

function urlencode(plaintext)
{
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for
	return encoded;
};

function urldecode(encoded)
{
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
};

function confirmation(val)
{
	var answer = confirm(val+'?');
	if(answer)
		return true;
	else
		return false;
}
function AllowOnlyNumeric()
{
    var key = window.event.keyCode;

    // Verify if the key entered was a numeric character (0-9) or a decimal (.) or space
    if ( (key > 47 && key < 58) || key == 46 || key == 47 || key == 37 || key == 32)
        return;
    else
        window.event.returnValue = null;
}
function doSomething(e) {
	var code;
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	var character = String.fromCharCode(code);
	alert('Character was ' + character);
}
function toggle(elementID, size)
{
	if(elementID != 'open' && elementID != 'close')
	{
		var target_arr = elementID.split(',');
		for (var x = 1; x <= target_arr.length; x++)
		{
			var i = x-1;
			var target = document.getElementById(target_arr[i]);
			target.style.display=((target.style.display=="none") ? "block" : "none");
		}
	}
	else if(elementID == 'open')
	{
		for (var x = 1; x <= size; x++)
		{
			var tag = 'tag'+x;
			document.getElementById(tag).style.display="block";
		}
	}
	else if(elementID == 'close')
	{
		for (var x = 1; x <= size; x++)
		{
			var tag = 'tag'+x;
			document.getElementById(tag).style.display="none";
		}
	}
}
function chk_email(str)
{
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (!filter.test(str))
		return false;
}
function replace_space(value)
{
	value = value.replace(/\s+/g,'');
	return value;
}
function IsNumeric(sText, extra)
{
	sText = replace_space(sText);
	var ValidChars = "0123456789"+extra;
	var IsNumber=true;
	var Char;
	
	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1)
			IsNumber = false;
	}
	return IsNumber;	
}

function phone_format(value)
{
	if(value != '')
	{
		if(value.length <10)
			return false;
	}
}