/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  echeck V2.0
//  BY: AUREAMEDIA.COM
//  
//   

function win(fileName) {
     myFloater = window.open('','myWindow','scrollbars=yes,status=no,width=300,height=330')
     myFloater.location.href = fileName;
}

var myHeight = 330;
var isResizable = true;

function createTarget(form) {
_target = form.target;
_colon = _target.indexOf(":");
if(_colon != -1) {
form.target = _target.substring(0,_colon);
form.args = _target.substring(_colon+1);
} else if(typeof(form.args)=="undefined") {
form.args = "";
}
if(form.args.indexOf("{")!=-1) {
_args = form.args.split("{");
form.args = _args[0];
for(var i = 1; i < _args.length;i++) {
_args[i] = _args[i].split("}");
form.args += eval(_args[i][0]) + _args[i][1];
   }
}
form.args = form.args.replace(/ /g,"");
_win = window.open('',form.target,form.args);
if(typeof(focus)=="function")
_win.focus();
return true;
}

// quote form validation
function validateForm(theForm) {

// alert("running validateform " + theForm.service.options[theForm.service.selectedIndex].value);
    
	/*if (typeof(theForm.media.options) != "undefined") {
	alert("theForm.media.options Exists");
	} else { alert("theForm.media.options NO Exists"); }*/
	
	
    var why = "";
	if (theForm.service != null & theForm.media == null) {  // alert("theform.service.options exists"); //71
		why += checkService(theForm.service.options[theForm.service.selectedIndex].value);
	}	//else { alert("service null or media not null"); }
	if (typeof(theForm.media) != "undefined") { //alert(theForm.media.value);     	
		why += checkMedia(theForm.media.options[theForm.media.selectedIndex].value, theForm.service.value);		
	}   //else { alert("media null"); }
	if (typeof(theForm.CustomQuant) != "undefined") { // this was set to quantity to check at start -alert("theform.quant exists");
    	why += checkQuant(theForm.quantity.value, theForm.service.value, theForm.media.options[theForm.media.selectedIndex].value);
	}   //else { alert("quant null"); }
	if (typeof(theForm.CustomQuant) != "undefined") { //alert("theform.quant exists");
    	why += checkCustom(theForm.CustomService.value, theForm.CustomQuant.value);
	}
	if (typeof(theForm.insert) != "undefined") { //alert("theform.quant exists");
    	why += checkTray(theForm.insert.value, theForm.traycard.value, theForm.packaging.value, theForm.insertprint.value);
	}
    if (why != "") {
       alert(why);
	   var pos = why.indexOf("* ")
		if (pos >= 0) {
		// alert("exists " + pos); do nothing
		} else {
       	return false;
	   }
    }
return true;
}

function checkCustom(CustomService, CustomQuant) {

    var error = "";
    if (CustomService.indexOf("None")==-1 && (CustomQuant < 1 || CustomQuant == "")) {
	    error = "You must add a Quantity for Other Services.\n";
    }
return error;
}

function checkTray(insert, traycard, packaging, insertprint) {

    var error = "";
    /* if (insert.indexOf("None")==-1) {
	    if (traycard.indexOf("4 + 4")!=-1 || traycard.indexOf("4 + 1")!=-1) {
		    if (packaging.indexOf("Clear Tray")==-1) { 
		       error = "If your tray card is 4+4 or 4+1 your must select the Standard CD Case (Clear Tray) Packaging.\n";
		    } 
	    } 
	    if (traycard.indexOf("4 + 0")!=-1 || traycard.indexOf("1 + 0")!=-1) {
		    if (packaging.indexOf("Black Tray")==-1) { 
		       error = "If your tray card is 4+0 or 1+0 your must select the Standard CD Case (Black Tray) Packaging.\n";
		    } 
	    }
    }
    if (insert.indexOf("None")!=-1 && traycard.indexOf("None")==-1) {
	    error = "You must select an Insert.\n";
    }*/
    if (insert.indexOf("None")!=-1 && insertprint.indexOf("None")==-1) {
	    error = "You must select Insert Printing.\n";
    }
    if (insert.indexOf("None")==-1 && insertprint.indexOf("None")!=-1) {
	    error = "You must select Insert and Tray Card Colors.\n";
    }
return error;
}

function checkInsertColor(insert, color) {

    var error = "";
    if (insert.indexOf("None")==-1) {
	    if (color.indexOf("None")!=-1) { 
	       error = "Please select the Colors for your Insert.\n";
	    } 
    }
return error;
}

function checkInsert(insert, service) {

    var error = "";
    if (service.indexOf("Duplication")!=-1) {
	    if (insert.indexOf("1 Panel")==-1 && insert.indexOf("2 Panel")==-1 && insert.indexOf("None")==-1) { 
	       error = "Please select 1 Panel 2 Page or 2 Panel 4 Page Insert for Duplication.\n";
	    } 
    }
return error;
}

function checkPackaging(media, packaging) {

    var error = "";
/*    if (media.indexOf("3 Inch")!=-1 || media.indexOf("Business")!=-1 && packaging.indexOf("None")>0) {
	alert(media);
	alert(packaging);
	    if (packaging.indexOf("3 Inch")==-1) { 
	       error = "Please select Vinyl Business Card CD Sleeve for Packaging.\n";
	    } 
		if (packaging.indexOf("Business")==-1) {
	       error = "Please select Vinyl Mini CD Sleeve for Packaging.\n";
		}
    }*/
return error;
}

function checkCDColor(CDColor, service) {

    var error = "";
    if (service.indexOf("Replication")!=-1) {
	    if (CDColor.indexOf("Labels")!=-1) { 
	       error = "CD Face Labels are for Duplication service only.\n";
	    }
    } else {
		if (service.indexOf("Duplication")!=-1) {  
		    if (CDColor.indexOf("Silkscreen")!=-1) { 
		       error = "Please select either Full Color or B & W Labels.\nSilkscreen is generly for Replication service only.\nPlease call for special pricing for Short Run Silkscreen.\n1 877 244-8844\n";
		    }
		}
	}
return error;
}

function checkTurn(rush, service) {

    var error = "";
    if (service.indexOf("Replication")!=-1) {
	    if (rush.indexOf("3 Day")!=-1 || rush.indexOf("Next Day")!=-1 || rush.indexOf("Same Day")!=-1) { 
	       error = "3 Day, Next Day and Same are for Duplication service only.\n";
	    }
    } else {
		if (service.indexOf("Duplication")!=-1) {  
		    if (rush.indexOf("6 Day")!=-1) { 
		       error = "6 Day Turn is for Replication service only.\nThe Stadard Turn for Duplication is 5 days.\n";
		    }
		}
	}
return error;
}

function checkService(service) {

    var error = "";
	if (service == "") { 
		error += "Please select a Service Type.\n";
	}
return error;
}

function checkMedia(media, service) {

    var error = "";
	if (media == "") { 
		error += "Please select a Media Type.\n";
	} else {
	    if (service.indexOf("Duplication")!=-1) {   
		    if (media.indexOf("DVD 9")!=-1 || media.indexOf("DVD 10")!=-1) { 
		       error += "DVD 9 and DVD 10 formats are for Replication service only.\n";
		    }
	    } 
	}   
return error;
}

function checkQuant(quant, service, media) {

    var error = "";
	var notice = "";
	if (quant < 1 || quant == "") { 
		error = "Please enter a quantity.\n";
	} else {
	    if (quant < 500 && service.indexOf("Replication")!=-1) { 
	       error = "Replication is only for quantities of 1000 or more DVDs and 500 or more CDs.\n";
	    } else if (quant < 1000 && media.indexOf("DVD")!=-1 && service.indexOf("Replication")!=-1) { 
			error = "Replication is only for quantities of 1000 or more DVDs.\n";
		}    
		if (quant < 500 && media.indexOf("DVD")==-1 && service.indexOf("Replication")!=-1) {
		   error = "Replication is only for quantities of 500 or more CDs.\n";
		}
	    if (quant > 500 && service.indexOf("Duplication")!=-1 && media.indexOf("DVD-R")==-1) { 
	       error = "* If you need more then 500 CD's and you have more then 10 business days to receive them,\nthen run your job as Replication for better pricing.";
	    }
	    if (quant > 1000 && service.indexOf("Duplication")!=-1 && media.indexOf("DVD-R")!=-1) { 
	       error = "* If you need more then 1000 DVD's and you have more then 10 business days to receive them,\nthen run your job as Replication for better pricing.";
	    }
	    if (quant < 500 && service.indexOf("Silkscreen")!=-1) { 
	       error = "Silkscreen Blanks are 500 Quantity minimum\n";
	    }
	}   
return error;
}