// JavaScript Document
function goSubmit(){
	 document.form1.method="POST"
	 document.form1.submit()	
}

function delrec(a,xm,f,act){
   if (delrec!=""){
      if(xm==null)
	     xm = "Do you really want to delete this record?"
      if(confirm(xm)){
		  if(f!=null)
			 document.form1.func_act.value=f
		  if(act!=null)
		 document.form1.photoaction.value=act
	     document.form1.delid.value=a
		 document.form1.method="POST"
		 document.form1.submit()
	  }
   }
}

function delrecloc(a,xm,f,act){
   if (delrecloc!=""){
      if(xm==null)
	     xm = "Do you really want to delete this record?"
      if(confirm(xm)){
		  if(f!=null)
			 document.form2.func_inact.value=f
		  if(act!=null)
		 document.form2.folderact.value=act 
	     document.form2.folderDelId.value=a
		 document.form2.method="POST"
		 document.form2.submit()
	  }
   }
}

function delbatch(a,xm,f,act){
   if (delbatch!=""){
      if(xm==null)
	     xm = "Do you really want to delete this record?"
      if(confirm(xm)){
		  if(f!=null)
			 document.form1.batchdel.value=f
		  if(act!=null)
//		 document.form2.folderact.value=act 
//	     document.form2.folderDelId.value=a
		 document.form1.method="POST"
		 document.form1.submit()
	  }
   }
}

function app_js(w,h,d) {
window.open( "http://lottopreview.com/matrix.php?w="+w+"&h="+h+"&d="+d, "Popup","resizable=1, HEIGHT=600, WIDTH=600");
}

function PopupReg(name,from) {
window.open( "http://lottopreview.com/popup_reg.php?name="+name+"&from="+from, "Popup","resizable=1, HEIGHT=600, WIDTH=600");
}

function PopupFile(sPicURL,width,height) {
	window.open( "http://lottopreview.com/popupv.php?val="+sPicURL+"&w="+width+"&h="+height, "Popup",
	"resizable=1, HEIGHT="+height+", WIDTH="+width);
}

function PopupPic(sPicURL) {
	window.open( "http://lottopreview.com/popup.html?"+sPicURL, "Popup",
	"resizable=1, HEIGHT=200, WIDTH=200");
}

function checkAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = true ;
}

function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = false ;
}

function checkAlls(field){
	alert(field.length);
}

function redir(a,msg){
	var lc = document.getElementById(a).value;
	if(lc.length == 0){
		alert(msg);
		lc.focus();
	}
		document.location.href = lc;
	
}


function redi(a){
	var lc = document.getElementById(a).value;
	var id = document.getElementById(a);
	
	if(CheckVal(id,"Please describe the target.")){
		return false;
	}

	document.location.href = lc;
}

function CheckVal(elem,msg){
	if(elem.value.length == 0){
		alert(msg);
		elem.focus(); // set the focus to this input
		return true;
	}
	else
	return false;
}

function validateForm(msg){
	var sid = document.getElementById('searchFor');
	var sby = document.getElementById('searchBy');	

	if(CheckSearchFor(sid,msg)){
		return false;
	}	
	
	if(CheckSearchBy(sby,msg)){
		return false;
	}

}

function CheckSearchBy(elem,msg){
	if(elem.value.length == 0){
		alert(msg);
		elem.focus(); // set the focus to this input
		return true;
	}
	else
	return false;
}

function CheckSearchFor(elem,msg){
	if(elem.value.length == 0){
		alert(msg);
		elem.focus(); // set the focus to this input
		return true;
	}
	else
	return false;
}

function validateSubscriber(){
	var email = document.getElementById('subsEmail');
//	var emails = document.getElementById('subsEmailBackup');
	
	if(CheckEmail(email,"Invalid e-mail format","Your e-mail address is requierd")){
		return false;
	}
/*	
	if(CheckEmail(emails,"Invalid e-mail format","Your Alternative e-mail address is required")){
		return false;
	}
*/
	
}

function CheckEmail(elem,msg,msgs){
	if(elem.value.length != 0){
	   var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
		if(elem.value.match(emailExp)){
		return false;
	 }
		else{
			alert(msg);
			elem.focus();
			return true;
		}
	  }
	else{
		alert(msgs);
		elem.focus();
		return true;
	}
}

function getValueSubs(){
	var sname = document.getElementById('subName').value;
	var sfrom = document.getElementById('subFrom').value;

	document.a_form.name.value=sname 
	document.a_form.from.value=sfrom
	document.a_form.method="POST"
	document.a_form.submit()
}

function pickId(id,hitsize){
	var pdi = document.getElementById('ppick').value;
	var	newval = pdi + ',' + id;
	var numsize = document.getElementById('numSize').value;
	var count = 0;
	
	if(numsize != hitsize){
		numsize++;
		document.getElementById('numSize').value = numsize;
		document.getElementById('ppick').value = newval;
		document.getElementById('but_con_'+id).style.display = 'none';
		document.getElementById('photo_'+id).style.backgroundColor = '#99FFFF';
	}
	
	var pick = document.getElementById('ppick').value;
	var spliResult = pick.split(",");
	
	for(i = 0; i < spliResult.length; i++){
			if(spliResult[i].length != 0){
				count++;
				if(count == hitsize){
					alert('You already have ' + hitsize + ' photo(s).\nYou cannot pick more photos than ' + hitsize + ' photo(s).');
				}
			}
	}

}

function clearPicks(url,lot){
	var pick = document.getElementById('ppick').value;
	var mySplitResult = pick.split(",");
	
	for(i = 0; i < mySplitResult.length; i++){
		if(mySplitResult[i].length != 0){
			document.getElementById('but_con_'+mySplitResult[i]).style.display = 'block';
			document.getElementById('photo_'+mySplitResult[i]).style.backgroundColor = '';
		}
	}

	document.getElementById('ppick').value = '';
	document.getElementById('numSize').value = '';

//	document.location.href = url;
}

function showFile(id){
	document.getElementById(id).style.display = 'block';
}

function ViewPickMenu(){
	document.getElementById('open_lot').style.display = 'block';
	document.getElementById('viewPick').style.display = 'none';	
	document.getElementById('hidePick').style.display = 'block';		
}

function HidePickMenu(){
	document.getElementById('open_lot').style.display = 'none';
	document.getElementById('viewPick').style.display = 'block';	
	document.getElementById('hidePick').style.display = 'none';			
}

function selectLot(id){
	var pid = document.getElementById('lotpick').value;
	
	document.getElementById('lot_'+id).style.backgroundColor = '#99FFFF';
	document.getElementById('lotpick').value = id;
	if(pid.length != 0){
		document.getElementById('lot_'+pid).style.backgroundColor = '';
	}
}

function do_button(act){
	var pickId = document.getElementById('lotpick').value;
	
	if(pickId.length != 0){
		document.getElementById('action').value = act;
		document.formPick.method="POST"
		document.formPick.submit()	
	}
}

function validatePreForm(){
	var name = document.getElementById('subName');
	var from = document.getElementById('subFrom');	

	if(CheckPreName(name,'Your name is required.')){
		return false;
	}else if(CheckPreEmail(from,"Invalid e-mail format")){
		return false;
	}	

	return true;
}

function CheckPreName(elem,msg){
	if(elem.value.length == 0){
		alert(msg);
		elem.focus(); // set the focus to this input
		return true;
	}
	else
	return false;
}

function CheckPreEmail(elem,msg){
	if(elem.value.length != 0){
	   var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
		if(elem.value.match(emailExp)){
		return false;
	 }
		else{
			alert(msg);
			elem.focus();
			return true;
		}
	  }
	else{
		alert("Your e-mail address is required");
		elem.focus();
		return true;
	}
}	

function ViewHCP(){
	var a = document.getElementById('wrapper_HCP').style.display;
	
	if(a == 'none'){
		document.getElementById('wrapper_HCP').style.display = 'block';
	}else{
		document.getElementById('wrapper_HCP').style.display = 'none';		
	}
}

function lotHover(id,box,over){
	var block = document.getElementById(box).style.display;
	if(block != 'block'){
		if(over != 'off'){
			document.getElementById(id).style.background='#666666';
		}
	}
//	this.style.cursor = "url(http://www.lottopreview.com/openhand.cur)";
}

function lotOut(id,box,over){
	var block = document.getElementById(box).style.display;
	
	if(block != 'block'){
		if(over != 'off'){
			document.getElementById(id).style.background='#999999';
		}
	}
}

function lotMiss(id,box,num,delay,sound,hit,over){
	var timer_val = document.getElementById('timer').value;
	var countthis = 0;
	var hitsize = document.getElementById('count').value;	
	hitsize++;
	if(hitsize <= hit){
		
		var pick = document.getElementById('log_txt').value;
		var mySplitResult = pick.split(",");
		
		var countmiss = document.getElementById('count_miss').value;

		for(i = 0; i < hitsize; i++){
			if(document.getElementById('hit_'+i).value == num){
				alert('blocks are already opened.');
				document.getElementById('timer').value = 'F';
			}
		}
		
		if(timer_val == ''){
			document.getElementById('timer').value = 'T';
			clearTimeout(t)
			var t = setTimeout("lotMissFunc('"+id+"','"+box+"','"+num+"','"+sound+"','"+over+"')",delay)
			document.getElementById('miss').value = hitsize;
		}else{
			document.getElementById('timer').value = '';
			clearTimeout(t)
		}
		countmiss++;
		document.getElementById('count_miss').value = countmiss;
	}else{
		alert('you already have ' + hit + ' picks.');
	}
/*
		document.getElementById(id).style.background='#FF0000';	
		document.getElementById(box).style.display='block';
		alert("Ooops... you miss... Please try again.");
	
		document.matrixForm.method="POST"
		document.getElementById('matrixloadApp').value = "Y";
		document.getElementById('matrixoLot').value = num;
		document.matrixForm.submit()
*/
	
}

function lotMissFunc(id,box,num,sound,over){
	if(document.getElementById('timer').value == 'T'){
		if(over != 'off'){
			document.getElementById(id).style.background='#FF0000';	
		}
		document.getElementById(box).style.display='block';
		if(sound == 'on'){
			EvalSound('miss_sound');
		}

		document.getElementById('timer').value = '';		
/*	
		document.matrixForm.method="POST"
		document.getElementById('matrixloadApp').value = "Y";
		document.getElementById('matrixoLot').value = num;
		document.matrixForm.submit()	
*/		
	}
}

function lotHit(id,box,num,delay,sound,hit,over){
	var countthis = 0;
	var hitsize = document.getElementById('count').value;

	if(hitsize < hit){
		var pick = document.getElementById('log_txt').value;
		var mySplitResult = pick.split(",");

		for(i = 0; i < hitsize; i++){
			if(document.getElementById('hit_'+i).value == num){
				alert('blocks are already opened.');
				document.getElementById('timer').value = 'F';
			}
		}	
		
		var timer_val = document.getElementById('timer').value;		
		if(timer_val == '' && timer_val != 'F'){			
			document.getElementById('timer').value = 'T';
			clearTimeout(t)

			var t = setTimeout("lotHitFunc('"+id+"','"+box+"','"+num+"','"+sound+"','"+over+"')",delay)
		}else{
			document.getElementById('timer').value = '';
			clearTimeout(t)
		}
	}else{
		alert('you already have ' + hit + ' picks.');
	}	
}

function lotHitFunc(id,box,num,sound,over){	
	if(document.getElementById('timer').value == 'T'){
		if(over != 'off'){
			document.getElementById(id).style.background='#00CC33';		
		}
		document.getElementById(box).style.display='block';

		var hitsize = document.getElementById('count').value;	
		var current_num = document.getElementById('log_txt').value;
		var boxBlock = document.getElementById(box).style.display;
	
		if(boxBlock == 'block'){
			if(current_num == ""){
				document.getElementById('log').innerHTML = num;
				document.getElementById('log_txt').value = num;
				document.getElementById('hit_0').value = num;
			}else{
				newnum = current_num + ', ' + num;
				document.getElementById('log').innerHTML = newnum;
				document.getElementById('log_txt').value = newnum;
				document.getElementById('hit_'+hitsize).value = num;
			}
			hitsize++;
			document.getElementById('count').value = hitsize;			
			document.getElementById('timer').value = '';			
		}	
		
		if(sound == 'on'){
			EvalSound('hit_sound');
		}
	}
}

function EvalSound(soundobj) {
  var thissound=document.getElementById(soundobj);
  thissound.Play();
}


function validateCommentForm(cat){
	var name = document.getElementById(cat+'_name');
	var email = document.getElementById(cat+'_email');	
	var msg = document.getElementById(cat);		

	if(CheckCommentName(name,'Your name is required.')){
		return false;
	}else if(CheckCommentEmail(email,"Invalid e-mail format")){
		return false;
	}else if(CheckCommentMsg(msg,'Message is required.')){
		return false;
	}	
	return true;
}

function CheckCommentName(elem,msg){
	if(elem.value.length == 0){
		alert(msg);
		elem.focus(); // set the focus to this input
		return true;
	}
	else
	return false;
}

function CheckCommentEmail(elem,msg){
	if(elem.value.length != 0){
	   var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
		if(elem.value.match(emailExp)){
		return false;
	 }
		else{
			alert(msg);
			elem.focus();
			return true;
		}
	  }
	else{
		alert("Your e-mail address is required");
		elem.focus();
		return true;
	}
}

function CheckCommentMsg(elem,msg){
	if(elem.value.length == 0){
		alert(msg);
		elem.focus(); // set the focus to this input
		return true;
	}
	else
	return false;
}