var state = 'hidden';
var cd ='';
var bx = 0;
var by = 0;
var mv2 = true;
var mvbk = false;
var xi = 20;
var yi = 25;

function moveto() {
  obj = document.getElementById(cd).style;
  cx = parseInt(obj.left);
	obj.left = cx + xi + "px";
  cy = parseInt(obj.top);
	if (cy > 20) obj.top = cy - yi + "px";
  if (cx < bx) {setTimeout("moveto()", 2);} else { mvbk = true;makevis('nfo',1);}
}

function moveback() {
  obj = document.getElementById(cd).style;
  cx = parseInt(obj.left);
	obj.left = cx - xi + "px";
  cy = parseInt(obj.top);
	if (cy < by) obj.top = cy + yi + "px";
  if (cx > bx) { setTimeout("moveback()", 1);} else { mv2 = true; fill_x('rev11',1,1);}
}

function bk2it() {
 if (mvbk) {
   makevis('nfo',0);
	 mvbk=false;
   if (cd=='registration') { bx=100;by=120;}
     else if (cd=='hotel') {bx=60;by=170;}
     else if (cd=='cruise') {bx=40;by=240;}
     else if (cd=='transfer') {bx=50;by=310;}
     else if (cd=='activities') {bx=80;by=380;}
	   else if (cd=='dmc') {bx=150;by=430;}
	 moveback();
	}
}

function makevis(r,s) {
	if (s == 0) { state = 'hidden'; } else {state = 'visible';}
	if (document.all) { //IS IE 4 or 5 (or 6 beta)
		eval( "document.all." + r + ".style.visibility = state");
	}
	if (document.layers) { //IS NETSCAPE 4 or below
		document.layers[r].visibility = state;
	}
	if (document.getElementById && !document.all) {
		ms = document.getElementById(r);
		ms.style.visibility = state;
	}
}

function bpop(a,b,c,d) {
var s = "";
if (((a.value).length)>1) {
  b.options[b.length] = new Option(a.value,a.value);
  a.remove(a.selectedIndex);
  for (x = 0; x < c.length; x++)	{	 s += c.options[x].value + ",";  }
  if (s.length>0) { s = s.substring(0,s.length-1); }
  d.value = s;
 }
}

function wo(a)
{
	window.open("https://www.destinationexpress.com/"+a,"DE","menubar=1,resizable=1,width=700,height=500");
}

function wes(f,a)
{
 var aa = new Array(); 
 aa = a.split(';');
 f.region.value =aa[0];
 f.ID_CityCode.value =aa[1];
}

function finchg(s) {
 fill_x('Payment',1,1);
}

function do_clsdt(f,x,y,z) {
 f.ix.value=x;
 f.dt.value = y;
 f.bf.value=z;
}

function do_clatdtl(f) {
 var a = new Array();
 var b = new Array();
 var s = '';
 a = f.clatdtl.value.split(';');
 for (x=0;x<f.ix.value;x++) { s+=a[x]+';'; }
 b = a[x].split(',');
 s += b[0] + ',' + f.dt.value + ',' + f.bf.value;
 x++;
 if (x<a.length) { s += ';'; }
 for (x=x;x<a.length;x++) { s+=a[x]+';'; }
 f.clatdtl.value = s;
 fill_x('clsdatt',1,s); 
}

function srt(d,f)
{
 fill_x('savit','srt',d+';'+f);
 fill_x('rev11',1,1);
}

function reloader() {
 setTimeout(function(){fill_x('rev11',1,1);},1500);
}

function rhotel()
{
 a = confirm("Are you sure you want to restart your hotel section?\nThis will remove all hotel, transfer and flight options you have selected.\nClick 'Cancel' to stop this process.\nClick 'OK' to go ahead with this process.");
	if (a) {
	 fill_x('savit','hotel',0);
 	 setTimeout(function(){fill_x('rev11',1,1);},1500);
	 }
}

function forgotpwd(s) {
 if (s.length>5) {
   a = confirm("Do you really want to assign yourself a new password and have it sent to your email?");
	 if (a) {
		 rstpwd(document.mainf.email.value);
		 alert("If your email address was used to register,\n check your email in a few minutes for your new password.");
	 } else { alert('Please try to log in.');	}
  } else {
	 alert("Type in your email address above and click the\n ''Forgot your password?''\n link again to have a new password sent to you.");}
}

function makecoord() {
  a = confirm("Do you really want to assign yourself as a coordinator?\nThis option should only be used if you are going to responsible for adding/managing multiple attendees.\nA coordinator is responsible for signing up and managing other attendees.");
	if (a) {
		fill_x('savit','makecoord',1);
		alert("You are now a coordinator, you now have options on your coordinator tab.")	
		setTimeout(function(){fill_x('rev11',1,1);},1000);
		alert('Click "OK" to see your new "Coordinator" tab on the left side of the tabs.');	 
	}
}

function canreg(c,f) {
  if (c>0) {
	  a = confirm("You are trying to cancel AFTER the cancellation date.\nYou will have to pay the cancellation fee of $"+f+ ".\nDo you really want to cancel your registration?\nThis will also remove all of your information.");
	} else {
	  a = confirm("Do you really want to cancel you registration?\nThis will remove all of your information.");
  }	
	if (a) {
		 fill_x('adel','canreg',0);
		 makevis('adel',1);
	}
}

function chgtig(n,i,p) {
	x = prompt("Enter the new password for "+n,p);
	if (x.length>4) 
	{ 
		document.wk.wesql.value = '3';
		document.wk.wkfn.value = i+','+x;
		document.wk.submit(); 
		alert('Password has been reset');
	}
	else {
	alert('Please use a password at least 5 characters long');}
}

function mkarr(f,d) {
 x = 0;
 if (f.ampm.value=='AM') {
  if (f.hr.value==12) { x = 0; } else { x = f.hr.value; }
 } else {
  if (f.hr.value==12) { x = 12; } else { x = 12 + eval(f.hr.value); }
 }
 f.arr.value=f.yr.value+'-'+f.mnth.value+'-'+f.dy.value+' '+x+':'+f.mn.value;
 fill_x('xfer',d,f.arr.value);
}

function popin(v,b) {
 if (b.value.indexOf(v)>=0) {
  b.value=b.value.replace(','+v,'');
  b.value=b.value.replace(v,'');
 } else {
  b.value +=','+v;
 }
  if (b.value.indexOf(',')==0) {b.value=b.value.substring(1,b.value.length)}
	if ((b.value.split(/,/g).length - 1)>1) {
		 alert("There are too many people in this transport.\nOther than "+v+",\nchoose one other person.");
		 b.value = v;
	} 
}
function popinx(v,b,z) {
 if (b.value.indexOf(v)>=0) {
  b.value=b.value.replace(','+v,'');
  b.value=b.value.replace(v,'');
 } else {
  b.value +=','+v;
 }
  if (b.value.indexOf(',')==0) {b.value=b.value.substring(1,b.value.length)}
	if ((b.value.split(/,/g).length - 1)>z) {
		 alert("There are too many selected.\nOther than "+v+",\nselect again.");
		 b.value = v;
	} 
}

function setdt(f,t) {
	var pd = document.eflightf.picdate.value;
	var hr = 0;
	if (pd.length<7) {
		alert("Please select a date first");
	} else {
		hr=f.flhour.value;
		if (f.flampm.value=='AM') {
			if (hr==12) {hr='00';} else {hr=f.flhour.value; } }
		else {
			if (hr==12) {hr='12';} else {hr=parseInt(f.flhour.value)+12; }
		}
		document.getElementById(t).value=pd+' '+hr+':'+f.flmin.value;
	}
}
function setdta(f) {
		document.eflightf.Flight_Arrival_Date.value=f.dt.value;
}
function setdtd(f) {
		document.eflightf.Flight_Departure_Date.value=f.dt.value;
}

function htlnt(n,i) {
	document.wk.wesql.value = '4';
	document.wk.wkfn.value = n.value+';'+i;
	document.wk.submit(); 
	alert('Your note has been saved.');
}
function raisit(s,k) {
	var ar = k.split(",");
	for(i = 0; i < ar.length; i++){
		document.getElementById(ar[i]).style.backgroundImage="url(/images/inactvtb.png)";
		document.getElementById(ar[i]).style.color='#556677';
		document.getElementById(ar[i]).style.zIndex=1;
		document.getElementById(ar[i]+'_div').style.zIndex=1;	
	}
	document.getElementById(s).style.backgroundImage="url(/images/actvtb.png)";
	document.getElementById(s).style.color='#000000';
	document.getElementById(s).style.zIndex=3;
	document.getElementById(s+'_div').style.zIndex=2;
}

function $(v) { return(document.getElementById(v)); }
function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
function xy(e,v) { return(v?(agent('msie')?event.clientY+document.body.scrollTop:e.pageY):(agent('msie')?event.clientX+document.body.scrollTop:e.pageX)); }

function dragOBJ(d,e) {
		var nm,xx,yy;
    function drag(e) { if(!stop) { d.style.top=(tX=xy(e,1)+oY-eY+'px'); d.style.left=(tY=xy(e)+oX-eX+'px'); xx = tY; yy = tX; nm = d.id} }

    var oX=parseInt(d.style.left),oY=parseInt(d.style.top),eX=xy(e),eY=xy(e,1),tX,tY,stop;
    document.onmousemove=drag; document.onmouseup=function(){ stop=1; document.onmousemove=''; document.onmouseup=''; fill_x('savit','dpdiv',nm+','+xx+','+yy);};
}

function fill_x(dv,x,v)
{ 	
  url = "/inc/rev11.php?dv=" + dv + "&x=" + x + "&v=" + v;
  var http_request = false;
  if (window.XMLHttpRequest) {
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {
      http_request.overrideMimeType('text/xml');  }
  } else if (window.ActiveXObject) { // IE
  try {
    http_request = new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (e) {
   try {
     http_request = new ActiveXObject("Microsoft.XMLHTTP"); } 
	catch (e) {} }
  }
  if (!http_request) {
    alert('Giving up :( Cannot create an XMLHTTP instance');
    return false; }
  http_request.onreadystatechange = function() { ajax_x(http_request,dv); };
  http_request.open('GET', url, true);
  http_request.send(null);
}

function ajax_x(http_request,dv)
{ if (http_request.readyState == 4)
 { if (http_request.status == 200) { // alert(dv);
	   document.getElementById(dv).innerHTML=http_request.responseText;}
   else {
      alert('There was a problem with the request. 1');
}}}

function fill_wesql(x) 
	{
		var wesql = '',fn='';v='';
		if (x.idx.value>0) {
			for (var i=7; i<x.elements.length; i++) {
				wesql += '`' + x.elements[i].name + '`=\'' + x.elements[i].value.replace(/'/g,"''")  + '\',';
			}
			document.wk.wesql.value = 'UPDATE `' + x.tablename.value + '` SET ' +  wesql.substring(0, wesql.length-1).replace(/^ \t\r\n\v\f/,'') + ' WHERE id=' + x.idx.value;
			document.wk.submit();
		} else {
			for (var i=7; i<x.elements.length; i++) {
				fn += '`' + x.elements[i].name + '`,';
				v += '\'' + x.elements[i].value.replace(/'/g,"''") + "',";
			}
			document.wk.wesql.value = 'INSERT INTO `' + x.tablename.value + '` (' +  fn.substring(0, fn.length-1) + ') VALUES (' +v.substring(0, v.length-1) .replace(/^ \t\r\n\v\f/,'') + ')';
			document.wk.submit();
		}
		fill_x('savit','saved',1);
		fill_x('rev11','showxtab',x.tablename.value);
}

function fille_wesql(x) 
{
		fill_x('savit','wait...',1);
		for (var i=7; i<x.elements.length; i++) {
				document.wk.wesql.value = 'UPDATE `dpdiv` SET headername=\'' +  x.elements[i].value + '\' WHERE tablename=\'' + x.tablename.value + '\' AND fieldname=\'' + x.elements[i].name + '\'';
				document.wk.submit(); }
		document.wk.submit();
		fill_x('savit','saved',1);
		fill_x('rev11','showxtab',x.tablename.value);
}

function delrec(t,i)
{
	document.wk.wesql.value = 'DELETE FROM `'+t+'` WHERE id=' + (i/1013);
	document.wk.submit(); }
	
function makeall(t,i,ec,da)
{
	if (da==0) {
	document.wk.wesql.value = 'DELETE FROM `'+t+'` WHERE NOT ContactEmail=\'control\' AND ID_EventCode=\''+ec+'\'';
	document.wk.submit(); }
	else if (da==1) {
		document.wk.wesql.value = 'INSERT INTO `'+t+'` (ID_EventCode,ContactEmail,pid) SELECT \''+ec+'\',Email,'+i+' FROM `Attendee Info` WHERE ID_EventCode=\''+ec+'\'  AND NOT Email in (SELECT ContactEmail FROM `Breakout Info` WHERE pid='+i+' AND ID_EventCode=\''+ec+'\')';
		document.wk.submit();	}
	fill_x('savit','saved',1);
}

function addat(a)
{
	fill_x('adel','coordinator'+a,0);
	makevis('adel',1);
}

function reqcoord()
{
 	a = prompt("Type in the email address of the person you wish to manage your entire itinerary or click ``OK`` with nothing in this box to cancel.");			 
 	if (a) {
		 fill_x('savit','reqcoord',a);
		 alert("An email will go to this person requesting that they click on a link to accept this request.\nContact them by phone to follow up on this request.");
 	} else {	
		alert("No action will be performed on this cancellation.");
	} 	
}

function mancli(fn,f)
{
 if (fn==1) {
 		fill_x('ediv','7;1;'+f.usr.value,0); 
 } else if (fn==2) {
 		fill_x('ediv','7;2;'+f.usrlst.value,0);
 } else if (fn==3) {
		a = confirm("Are you sure you want to REMOVE their access to this event?");
		if (a) {
			  fill_x('savit','remue',f.usrid.value+';'+f.inev.value);
				fill_x('ediv','7;0;0;',0);
				fill_x('rev11',1,1);
		}		 
 } else if (fn==4) {
		a = confirm("Are you sure you want to ADD their access to this event?");
		if (a) {
			  fill_x('savit','addue',f.usrid.value+';'+f.outev.value);
				fill_x('ediv','7;0;0;',0);
				fill_x('rev11',1,1);
		}		 
 } else {
 	 alert('not yet');
 }

}

function picedit(s)
{
 document.upr.elnm.value=s;
 //picup.style.visibility = "visible"; 
 makevis('picup',1);
}
function mugedit()
{
 document.upr.elnm.value='Headshot';
 makevis('picup',1);
 fill_x('ediv','0;edit_headshot',0);
 makevis('ediv',1);
}
function subprofile(z)
{
 if ((z.a.value.length==0)||(z.b.value.length==0)||(z.c.value.length==0)||(z.d.value.length==0)||(z.e.value.length==0)||(z.f.value.length==0)||(z.g.value.length==0)||(z.h.value.length==0)) {
 		alert('Please fill out all of the fields in this section'); }
	else {
		z.submit();
		makevis('ediv',0); }
}

function tabclick(t,i) {
	if (t=='events') {
		fill_x('savit','events',i);
		setTimeout(function(){fill_x('rev11',1,1);},2000);		
	} else if (t=='client breakout') {
		fill_x('ediv','1;Breakout Info',i);
		makevis('ediv',1);
	} else if (t=='client dining') {
		fill_x('ediv','1;Dining Info',i);
		makevis('ediv',1);
	} else if (t=='client hotel') {
		fill_x('ediv','1;Hotel Info',i);
		makevis('ediv',1);
	} else if (t=='client ticket') {
		fill_x('ediv','1;Tickets Info',i);
		makevis('ediv',1);
	} else if (t=='client tour') {
		fill_x('ediv','1;Tours Info',i);
		makevis('ediv',1);
	} else if (t=='attendee') {
		fill_x('ediv','1;Attendee Info',i);
		makevis('ediv',1);
	} else if (t=='attendee breakouts') {
		fill_x('ediv','0;attendee breakouts',i);
		makevis('ediv',1);
	} else if (t=='attendee tour') {
		fill_x('ediv','0;attendee tour',i);
		makevis('ediv',1);
	} else if (t=='attendee transfer') {
		fill_x('ediv','0;attendee transfer',i);
		makevis('ediv',1);
	} else if (t=='attendee dining') {
		fill_x('ediv','0;attendee dining',i);
		makevis('ediv',1);
	} else if (t=='attendee hotel') {
		fill_x('ediv','0;attendee hotel',i);
		makevis('ediv',1);
	} else if (t=='attendee ticket') {
		fill_x('ediv','0;attendee ticket',i);
		makevis('ediv',1);
	} else {
		//alert('Not yet available for '+t); 
	}
}

function genlgn(i)
{
	document.wk.wesql.value = 'INSERT INTO usr (full_name,ClientName,email,cur_eventcode,pwd) SELECT GuestFullName,`Company Name`,Email,ID_EventCode,sha1(CONCAT(CHAR(65+round(25*rand())),CHAR(97+round(25*rand())) ,round(316*rand()),CHAR(97+round(25*rand())))) FROM `Attendee Info` WHERE id='+i;
	document.wk.submit();
	fill_x('rev11',1,1);}

function rstpwd(e)
{	document.wk.wesql.value = '1';
	document.wk.wkfn.value = e;
	document.wk.submit(); }

function printdiv(node){
  var content=node.innerHTML
  var pwin=window.open('','print_content','width=100,height=100');
  pwin.document.open();
  pwin.document.write('<html><body onload="window.print()">'+content+'</body></html>');
  pwin.document.close(); 
  setTimeout(function(){pwin.close();},1000);
}

function chev(e){
  fill_x('savit','events',e);
  setTimeout(function(){ fill_x('rev11',1,1);},500);
}

function fill_detail(f) {
	var s = "";
	for (x = 0; x < f.bedtype.length; x++)
	{
	 s += f.bedtype.options[x].value + ",";
  }
	if (s.length>1) { s = s.substring(0,s.length-1); }
	f.detail.value = s;
}

function evsub(f)
{
 if (!f.tos.checked) {
 		alert('You must read and agree with our terms of service in order to continue.');
 		return false; }
// else if ((!f.coord.checked)&&(!f.attnd.checked)) {
// 		alert('You must be either check yes on being an attendee or check yes for coordinating attendees in order to continue.');
// 		return false; }
 else if (f.cn.value.length<2) {
 		alert('We will need your company name');
 		return false; } 
 else if (f.Emaila.value.length<3) {
 		alert('We will need your email address.');
 		return false; } 
 else if (f.Emaila.value!=f.Emailz.value) {
 		alert('The email boxes were not identical. Your email address must be entered twice.');
 		return false; } 
 else if (!ValEm1(f.Emaila)) {
 		return false; } 
 else if ((f.Guest_FirstName.value.length<1)||(f.Guest_LastName.value.length<1)) {
 		alert('Your first and last name need to be filled out');
 		return false; } 
 else if ((f.Phone.length<1)||(f.carrier.value.length<1)) {
 		alert('Your mobille phone number and mobile carrier are needed.');
 		return false; }  
 else if (!ValPx(f.Phone)) {
 		return false; }
 else if (f.passw1.value.length<7) {
 		alert('Please enter a strrong password that is at least 7 letters and numbers.');
 		return false; } 
 else if (f.passw1.value!=f.passw2.value) {
 		alert('The password boxes were not identical. Your password must be entered twice.');
 		return false; }
 else {  f.submit(); }
 
}

//-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
var digits = "0123456789";
var phoneNumberDelimiters = "()- ";
var validWorldPhoneChars = phoneNumberDelimiters + "+";
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    return true;
}
function trim(s)
{   var i;
    var returnString = "";
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function ValPx(px){
	if ((px.value==null)||(px.value=="")){
		alert("We need a mobile number\n example 123-555-1212")
		px.focus()
		return false
	}
	if (checkInternationalPhone(px.value)==false){
		alert("Please Enter a Valid Phone Number\n example 123-555-1212")
		px.value=""
		px.focus()
		return false
	}
	return true
 }
//-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
function ValCr(cr){
	if ((cr.value==null)||(cr.value=="none")){
		alert("We need the mobile carrier or choose 'other'\n (i.e. Verizon, T-Mobile, Sprint...)'")
		px.focus()
		return false
	}
	return true
 }
//-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
var dtCh= "-";
var sepCh= " ";
var tmCh= ":";
var minYear=1900;
var maxYear=2100;

function daysInFebruary (year){
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDateTm(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var pos3=dtStr.indexOf(sepCh,pos2+1)
	var pos4=dtStr.indexOf(tmCh,pos3+1)
	var strMonth=dtStr.substring(pos1+1,pos2)	//(0,pos1)
	var strDay=dtStr.substring(pos2+1,pos3)			//(pos1+1,pos2)
	var strYear=dtStr.substring(0,pos1)		//(pos2+1)
	var strHour=dtStr.substring(pos3+1,pos4)
	var strMin=dtStr.substring(pos4+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	hour=parseInt(strHour)
	minu=parseInt(strMin)
	if (pos1==-1 || pos2==-1 || pos3==-1 || pos4==-1){
		alert("The date-time format needs to be : yyyy-mm-dd hh:mm")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month (01-12) \n (i.e.yyyy-mm-dd hh:mm )")
		return false
	}
	if (strHour.length<1 || hour<0 || hour>23){
		alert("Please enter a valid hour (00-23) \n (i.e.yyyy-mm-dd hh:mm )")
		return false
	}
	if (strMin.length<1 || minu<0 || minu>59){
		alert("Please enter a valid minute (00-59) \n (i.e.yyyy-mm-dd hh:mm )")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day (00-31) \n (i.e.yyyy-mm-dd hh:mm )")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear+" \n (i.e.yyyy-mm-dd hh:mm )")
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1){
		alert("You need a date and a time. \n Please enter the valid date and time  \n (i.e.yyyy-mm-dd hh:mm )")
		return false
	}
	if (isInteger(stripCharsInBag(stripCharsInBag(stripCharsInBag(dtStr, dtCh),sepCh),tmCh))==false){
		alert("Time format is 24-hour format \n Please enter the valid date and time \n (i.e.yyyy-mm-dd hh:mm )")
		return false
	}
return true
}

function ValDt(dt){
	if (isDateTm(dt.value)==false){
		dt.focus()
		return false
	}
    return true
 }
 //-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
 function ValEm1(Em)
{
	var Email;
	Email=/\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))*/;
	if (Em.value.search(Email) == -1) {
		alert ("Please enter a normal email address.\n (i.e. name@email.com)")
		Em.focus()
		return false
	}
	return true
}
 //-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
	
	
	
function mod10( cardNumber ) { // LUHN Formula for validation of credit card numbers.
	var ar = new Array( cardNumber.length );
	var i = 0,sum = 0;
    	for( i = 0; i < cardNumber.length; ++i ) {
    		ar[i] = parseInt(cardNumber.charAt(i));
    	}
    	for( i = ar.length -2; i >= 0; i-=2 ) { // you have to start from the right, and work back.
    		ar[i] *= 2;							 // every second digit starting with the right most (check digit)
    		if( ar[i] > 9 ) ar[i]-=9;			 // will be doubled, and summed with the skipped digits.
    	}										 // if the double digit is > 9, ADD those individual digits together 


        	for( i = 0; i < ar.length; ++i ) {
        		sum += ar[i];						 // if the sum is divisible by 10 mod10 succeeds
        	}
        	return (((sum%10)==0)?true:false);	 	
    }

 function expired( month, year ) {
        	var now = new Date();							// this function is designed to be Y2K compliant.
        	var expiresIn = new Date(year,month,0,0,0);		// create an expired on date object with valid thru expiration date
        	expiresIn.setMonth(expiresIn.getMonth()+1);		// adjust the month, to first day, hour, minute & second of expired month
        	if( now.getTime() < expiresIn.getTime() ) return false;
        	return true;									// then we get the miliseconds, and do a long integer comparison
}


function validateCard(amnt,cardNumber,cardType,cardMonth,cardYear) {
        	if( amnt.length == 0 ) {						//most of these checks are self explanitory
        		alert("Please go to the 'View Cart' tab, check the amount then return to this tab to complete your payment.");
        		return false;				
        	}        	if( cardNumber.length == 0 ) {						//most of these checks are self explanitory
        		alert("Please enter a valid card number.");
        		return false;				
        	}
        	for( var i = 0; i < cardNumber.length; ++i ) {		// make sure the number is all digits.. (by design)
        		var c = cardNumber.charAt(i);


            		if( c < '0' || c > '9' ) {
            			alert("Please enter a valid card number. Use only digits. do not use spaces or hyphens.");
            			return false;
            		}
            	}
            	var length = cardNumber.length;			//perform card specific length and prefix tests


                	switch( cardType ) {
                		case 'a':
                    			if( length != 15 ) {
                    				alert("Please enter a valid American Express Card number.");
                    				return;
                    			}
                    			var prefix = parseInt( cardNumber.substring(0,2));


                        			if( prefix != 34 && prefix != 37 ) {
                        				alert("Please enter a valid American Express Card number.");
                        				return;
                        			}
                        			break;
                        		case 'd':
                            			if( length != 16 ) {
                            				alert("Please enter a valid Discover Card number.");
                            				return;
                            			}
                            			var prefix = parseInt( cardNumber.substring(0,4));


                                			if( prefix != 6011 ) {
                                				alert("Please enter a valid Discover Card number.");
                                				return;
                                			}
                                			break;
                                		case 'm':
                                    			if( length != 16 ) {
                                    				alert("Please enter a valid MasterCard number.");
                                    				return;
                                    			}
                                    			var prefix = parseInt( cardNumber.substring(0,2));


                                        			if( prefix < 51 || prefix > 55) {
                                        				alert("Please enter a valid MasterCard Card number.");
                                        				return;
                                        			}
                                        			break;
                                        		case 'v':
                                            			if( length != 16 && length != 13 ) {
                                            				alert("Please enter a valid Visa Card number.");
                                            				return;
                                            			}
                                            			var prefix = parseInt( cardNumber.substring(0,1));


                                                			if( prefix != 4 ) {
                                                				alert("Please enter a valid Visa Card number.");
                                                				return;
                                                			}
                                                			break;
                                                	}
                                                	if( !mod10( cardNumber ) ) { 		// run the check digit algorithm
                                                		alert("Sorry! this is not a valid credit card number.");
                                                		return false;
                                                	}
                                                	if( expired( cardMonth, cardYear ) ) {							// check if entered date is already expired.
                                                		alert("Sorry! The expiration date you have entered would make this card invalid.");
                                                		return false;
                                                	}
                                                	
                                                	return true; // at this point card has not been proven to be invalid
}
