
	var win=null;
	function NewWindow(mypage,myname,w,h,scroll,pos)
	{
		if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
		if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
		else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
		settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
		win=window.open(mypage,myname,settings);
	}


	function GetCookie (name)
	{
		var arg = name + "=";  
		var alen = arg.length;  
		var clen = document.cookie.length;  
		var i = 0;  
		while (i < clen)
		{
			var j = i + alen;
			if (document.cookie.substring(i, j) == arg)  
			return getCookieVal (j);
			i = document.cookie.indexOf(" ", i) + 1;
			if (i == 0) break;   
		}  
		return null;
	}


	function getCookieVal(offset) {
		var endstr = document.cookie.indexOf (";", offset);
		if (endstr == -1)
			endstr = document.cookie.length;
		return unescape(document.cookie.substring(offset, endstr));
	}


	function SetCookie (name, value) {  
		var argv = SetCookie.arguments;  
		var argc = SetCookie.arguments.length;  
		var expires = (argc > 2) ? argv[2] : null;  
		var path = (argc > 3) ? argv[3] : null;  
		var domain = (argc > 4) ? argv[4] : null;  
		var secure = (argc > 5) ? argv[5] : false;  
		document.cookie = name + "=" + escape (value) + 
			((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
			((path == null) ? "" : ("; path=" + path)) +  
			((domain == null) ? "" : ("; domain=" + domain)) +
			((secure == true) ? "; secure" : "");
	}


	function DeleteCookie (name) {  
		var exp = new Date();  
		exp.setTime (exp.getTime() - 1);  
		var cval = GetCookie (name);  
		document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
	}
	
	
	function isValidEmail(sEmail)
	{
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
		return (filter.test(sEmail))
	}
	
	
	function setSelection( objSel, strSel, forceSelection ) {
		if( arguments.length < 3 )
			forceSelection = false;
		if( typeof(objSel) == "undefined" )
			return false;
		if( typeof(objSel.type) == "undefined" )
			return false;
		if( objSel.type != "select-one" )
			return false;
		for (var i = 0; i < objSel.length; ++i)
		{
			if( objSel.options[i].value.toUpperCase() == strSel.toUpperCase() )
			{
				objSel.options[i].selected=true;
				return true;
			}
		}
		if( forceSelection && objSel.options.length )
		{
			objSel.options[0].selected=true;
			return true;
		}
		return false;
	}


	function getSelection( objSel ) {
		return objSel[ objSel.selectedIndex ].value;
	}
	
	
	function getObjectValue(objElm) {
		if ( typeof(objElm) == 'undefined' )
			return '';

		switch( objElm.type || objElm[0].type )
		{
			case 'select-one':
				return ( objElm.selectedIndex == -1 ) ? '' : objElm[ objElm.selectedIndex ].value;
				break;
			case 'select-multiple':
				var values = new Array();
				for( var i = 0; i < objElm.options.length; ++i )
					if( objElm.options[i].selected )
						values.push( objElm.options[i].value );
				return values.join(',');
				break;
			case 'checkbox':
			case 'radio':
				if( !objElm.length )
				{
					if( objElm.value )
						return objElm.value
				}
				else
				{
					var values = new Array();
					for( var i = 0; i < objElm.length; ++i )
						if( objElm[i].checked )
							values.push( objElm[i].value );
					return values.join(',');
				}
				break;
			case 'text':
			case 'textarea':
			default:
				if( objElm.value )
					return objElm.value
				else
					return '';
				break;
		}
	}


	function stripForCC(num)
	{ // this function removes spaces and illegal characters
		num = "" + num;
		if (!num)
		return "";
		var result = "";
		for (i=0; i<num.length; i++)
		{
			character = num.charAt(i);
			if ("0123456789".indexOf(character) != -1)
				result += character;
		}
		return result;
	}

	// next get the card type
	function IsValidCC( CCtype, CCnumber )
	// types are 'M'asterCard, 'V'isa, 'A'mex, 'D'iscover
	{
		// remove illegal characters
		var cno = stripForCC(CCnumber);

		// Visa
		if( CCtype == 'V' ){
			return (((cno.length == 13) || (cno.length == 16)) && (cno.substring(0,1) == 4));
		}

		// Mastercard
		if( CCtype == 'M' ){
			var firstdig=cno.substring(0,1);
			var seconddig=cno.substring(1,2);
			return (((cno.length == 16) || (cno.length == 19)) && (firstdig == 5) && ((seconddig >= 1) && (seconddig <= 5)));
		}

		// Amex
		if( CCtype == 'A' ){
			var firstdig = cno.substring(0,1);
			var seconddig = cno.substring(1,2);
			return (((cno.length == 15) || (cno.length == 18)) && (firstdig == 3) && ((seconddig == 4) || (seconddig == 7)));
		}

		// Discover
		if( CCtype == 'D' ){
			var firstdig = cno.substring(0,1);
			var seconddig = cno.substring(1,2);
			var thirddig = cno.substring(2,3);
			var fourthdig = cno.substring(3,4);
			return ( (cno.length == 16) && (firstdig == 6) && (seconddig == 0) && (thirddig == 1) && (fourthdig == 1) );
		}

		return false;
	}

	function IsValidImailUsername( s )
	{
		var regx  = /^([a-zA-Z0-9_\.\-])+$/;
		return regx.test(s)
	}

	function IsValidImailPassword( s )
	{
		var regx1  = /[^@:\s]+/;	// match one or more not in this set;
		var regx2  = /[@:\s]+/;		// and make there are not any chars in this set
		return (regx1.test(s) && !regx2.test(s));
	}