// GLOBAL VARs//////////////////////////////////////////////////////////
var isBad=0;
var error_cnt = "0";
var alerts = "";
var error = 1;
var s = "S";
var t = "these";
var f = "fields";
////////////////////////////////////////////////////////////////////////
function FirstLog(a,b,c,d){
badChars(a);
badChars(b);
badChars(c);
if(isBad == 0){
var error = 0;
 if(!a){
 alert("ERROR :: Username Required.");
 error = 1;
isBad=0;
document.AdminEdit.reset()
 }
  if(a.length<4){
 alert("ERROR :: Username must be at least 5 characters long.");
 error = 1;
isBad=0;
document.AdminEdit.reset()
 }
 if(!b){
 alert("ERROR :: Password Required.");
 error = 1;
isBad=0;
document.AdminEdit.reset()
 }
  if(b.length<4){
 alert("ERROR :: Password must be at least 5 characters long.");
 error = 1;
isBad=0;
document.AdminEdit.reset()
 }
  if(b != c){
 alert("ERROR :: Password and Confirm Password do not match.");
 error = 1;
isBad=0;
document.AdminEdit.reset()
  }

 if(error == 0){
  document.AdminEdit.submit();
  var UsrChoice = confirm("You have successfully entered a username and password, this data has been written to the DataBase.\nYour username is : "+a+"\nYour password is : "+b+"\n\nFor security reasons it is required that you Sign In.\n\n To do so, click OK, to close application and Sign In later click cancel\n\nThank you.");
 if(UsrChoice){
  location = d;
 } else {
  alert("This window will now close\nTo relaunch application simply reopen or reload main launch window.\n\nThank You.");
 window.close();
 }
 }  else {
  return false;
}

} else {
alert("ERROR :: \n\tBad Characters used in Username and/or Password Field\n\tPlease use Alpha-Numerical Characters Only\n\tThank You.");
isBad=0;
document.AdminEdit.reset()
}
}
function ChkPwd(myform,action,u,p,cp){
  if((u.length>4) && (p.length>4)){
badChars(u);
badChars(p);
badChars(cp);
if(isBad == 0){
  if(p==cp){
 document.AdminEdit.submit();
 return true;
  } else {
 alert("ERROR:: Password and Confirm Password Fields do not match.\n\nPlease try again. \n\nThank You.");
 return false;
 }
 } else {
alert("ERROR :: \n\tBad Characters used in Username and/or Password Field\n\tPlease use Alpha-Numerical Characters Only\n\tThank You.");
isBad=0;
document.AdminEdit.reset()
}
} else {
 alert("ERROR :: Username/Password must be at least 5 characters long.");
}
}
function badChars(theStr){
  var i,theChar;
  var someBadChars = " ~!@#$%^&*()_+|`-=\\{}[]:\";'<>,./?¬¦ÀÁÂÃÄÆÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ";
  for (i=0; i<theStr.length; i++) {
 theChar = theStr.charAt(i);
 if (someBadChars.indexOf(theChar) != -1){ isBad = 1;}
  }
  return isBad;
}
function ConfirmDelete(a,b,c,d,e){
if(confirm("Are you sure that you want to permanently delete this record ["+c+" :: "+d+"].\n\tPress OK to delete\n\tPress Cancel to return to record.")){
  window.location = a+"?cmd="+b+"&id="+c+"&s="+e;
} else {
  alert("Deletion of Record ["+c+" :: "+d+"] Has Been Canceled, You Clumsy Flip Flopping Cnut");
}
}

function MergeOptions(form,type){

if(type == 3){
var sizeresults = "";

for(var i = 0; i < form.size.length; i++){
  if(form.size.options[i].selected){
  sizeresults += form.size.options[i].text+",";
  }
}

if(sizeresults.length>0){
  sizeresults = sizeresults.substring(0,sizeresults.length - 1)
}

form.sizeresults.value = sizeresults;

var colourresults = "";

for(var i = 0; i < form.colours.length; i++){
  if(form.colours.options[i].selected){
  colourresults += form.colours.options[i].text+",";
  }
}

if(colourresults.length>0){
  colourresults = colourresults.substring(0,colourresults.length - 1)
}

form.colourresults.value = colourresults;
}
// Create Press Articles From Options, If type is CD or Vinyl
if(form.type.value == "1" || form.type.value == "2"){
form.press_list.value = "";

for(var i=0;i<form.press_list_tmp.options.length;i++){
re1 = /^\s+/;
re2 = /\s+$/;
form.press_list_tmp.options[i].text = form.press_list_tmp.options[i].text.replace(re1,"");
form.press_list_tmp.options[i].value = form.press_list_tmp.options[i].value.replace(re1,"");
form.press_list_tmp.options[i].text = form.press_list_tmp.options[i].text.replace(re2,"");
form.press_list_tmp.options[i].value = form.press_list_tmp.options[i].value.replace(re2,"");
form.press_list.value += (escape(form.press_list_tmp.options[i].text+","+form.press_list_tmp.options[i].value+","));
}

//alert(form.press_list.value);

form.press_list.value.replace(/%2C/g, ",");//Replace the commas, the press article pair delimiter
}

form.submit();
}

function OpenWin(a,b){
var Loc = "../osaka/"+b+"/"+a;
window.open(Loc,'PopWin','width=400,height=400,left=0,top=0,screenX=0,screenY=0,toolbar=no,location=yes,status=no,menubar=no,scrollbars=1,resizable=yes');
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function UpDateForm(a,b,c,d,e,f,g,h){
var test = isNaN(f);
if(test){f=1;} // Not A Number, Reset f to 1

if(f == 0 || f.length == 0){
if(confirm("Inadequate quantity entered\nWould you like to have the product removed from the cart?\nClick OK to remove product\nClick cancel to reset product quantity to 1")){
window.location = a+"?cmd=5&title="+c+"&s="+d+"&rid="+e+"&Size="+g+"&Colour="+h; // Remove From Cart
} else {
f = "1"; // Set Value of f to 1
//alert(a+"\n"+b+"\n"+c+"\n"+d+"\n"+e+"\n"+f);
window.location = a+"?cmd="+b+"&title="+c+"&s="+d+"&id="+e+"&qty="+f+"&Size="+g+"&Colour="+h;
}
} else {
window.location = a+"?cmd="+b+"&title="+c+"&s="+d+"&id="+e+"&qty="+f+"&Size="+g+"&Colour="+h;
}
}

function ExtraOptions(a,b,c){
var d = document.Pro_Options.Colours.options[document.Pro_Options.Colours.selectedIndex].value;
var e = document.Pro_Options.Sizes.options[document.Pro_Options.Sizes.selectedIndex].value;
window.location = a+"?cmd=3&title=shop&id="+b+"&s="+c+"&Colour="+d+"&Size="+e;
}

function CheckFinalForm(){
if(document.SendForm.email.value && !document.SendForm.email.value.match(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/)){
error_cnt++;alerts += error_cnt+". Email format is incorrect\nPlease use the following format\n\nyouraddress\@yourserver.suffix\n\n";error = 0;
}
if(document.SendForm.email.value == ""){error_cnt++;alerts += error_cnt+". Email is Required\n";error = 0;}
if(document.SendForm.first_name.value == ""){error_cnt++;alerts += error_cnt+". First Name is Required\n";error = 0;}
if(document.SendForm.last_name.value == ""){error_cnt++;alerts += error_cnt+". Last Name is Required\n";error = 0;}
if(document.SendForm.address1.value == ""){error_cnt++;alerts += error_cnt+". Address 1 is Required\n";error = 0;}
if(document.SendForm.address2.value == ""){error_cnt++;alerts += error_cnt+". Address 2 is Required\n";error = 0;}
if(document.SendForm.country.value == ""){error_cnt++;alerts += error_cnt+". Country is Required\n";error = 0;}

if(error){
document.SendForm.submit();
} else {
alerts = error_cnt+" ERROR"+s+"\n\n"+alerts+"\nPlease return to Request Page and fill in "+t+" "+error_cnt+" required "+f+"\nThank You.\nOsaka.";
alert(alerts);
error_cnt = 0;
alerts = "";
error = 1;
}
}
function CheckExport(){
if(document.ExportForm.ftype.value == ""){error_cnt++;alerts += error_cnt+". File Type is Required\n";error = 0;}
if(document.ExportForm.fdelim.value == ""){error_cnt++;alerts += error_cnt+". Field Delimiter is Required\n";error = 0;}
if(document.ExportForm.rdelim.value == ""){error_cnt++;alerts += error_cnt+". Record Delimiter is Required\n";error = 0;}

if(error){

if(confirm("Subscribers Data to be exported as\nFile type :: \t\t"+document.ExportForm.ftype.options[document.ExportForm.ftype.selectedIndex].text+"\nField Delimiter :: \t\t"+document.ExportForm.fdelim.options[document.ExportForm.fdelim.selectedIndex].text+"\nRecord Delimiter :: \t\t"+document.ExportForm.rdelim.options[document.ExportForm.rdelim.selectedIndex].text+"\nClick OK to proceed with export, Cancel to return to page.")){
document.ExportForm.submit();
}

} else {
alerts = error_cnt+" ERROR"+s+"\n\n"+alerts+"\nPlease return to Request Page and fill in "+t+" "+error_cnt+" required "+f+"\nThank You.\nPurtell.";
alert(alerts);
error_cnt = 0;
alerts = "";
error = 1;
}
}

function ChkNewsLetter(){
if(document.nw_form.nw_email.value && !document.nw_form.nw_email.value.match(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/)){
error_cnt++;alerts += error_cnt+". Email format is incorrect\nPlease use the following format\n\nyouraddress\@yourserver.suffix\n\n";error = 0;
}

if(document.nw_form.nw_name.value && document.nw_form.nw_name.value.match(/\|/) || document.nw_form.nw_name.value.match(/\:/)){error_cnt++;alerts += error_cnt+". Illegal Character used in name\n";error = 0;}
if(document.nw_form.nw_email.value && document.nw_form.nw_email.value.match(/\|/) || document.nw_form.nw_email.value.match(/\:/)){error_cnt++;alerts += error_cnt+". Illegal Character used in email\n";error = 0;}
if(document.nw_form.nw_name.value == ""){error_cnt++;alerts += error_cnt+". Name is Required\n";error = 0;}
if(document.nw_form.nw_email.value == ""){error_cnt++;alerts += error_cnt+". Email is Required\n";error = 0;}

if(error){
document.nw_form.submit();
} else {
if(error_cnt<2){s = "";t = "this";f = "field";}
alerts = error_cnt+" ERROR"+s+"\n\n"+alerts+"\nPlease return to Request Page and fill in "+t+" "+error_cnt+" required "+f+"\nThank You.\nOsaka.";
alert(alerts);
error_cnt = 0;
alerts = "";
error = 1;
}
}

function ChkContactForm(){
if(document.c_form.email.value && !document.c_form.email.value.match(/(\w+).*\@(\w+)\.(\w+)/)){
error_cnt++;alerts += error_cnt+". Email format is incorrect\nPlease use the following format\n\nyouraddress\@yourserver.suffix\n\n";error = 0;
}

if(document.c_form.name.value && document.c_form.name.value.match(/\|/) || document.c_form.name.value.match(/\:/)){error_cnt++;alerts += error_cnt+". Illegal Character used in name\n";error = 0;}
if(document.c_form.email.value && document.c_form.email.value.match(/\|/) || document.c_form.email.value.match(/\:/)){error_cnt++;alerts += error_cnt+". Illegal Character used in email\n";error = 0;}
if(document.c_form.name.value == ""){error_cnt++;alerts += error_cnt+". Name is Required\n";error = 0;}
if(document.c_form.email.value == ""){error_cnt++;alerts += error_cnt+". Email is Required\n";error = 0;}
if(document.c_form.enquiry.value == ""){error_cnt++;alerts += error_cnt+". Enquiry is Required\n";error = 0;}

if(error){
document.c_form.submit();
} else {
if(error_cnt<2){s = "";t = "this";f = "field";}
alerts = error_cnt+" ERROR"+s+"\n\n"+alerts+"\nPlease return to Request Page and fill in "+t+" "+error_cnt+" required "+f+"\nThank You.\nOsaka.";
alert(alerts);
error_cnt = 0;
alerts = "";
error = 1;
}
}

function QueryStr(i){
var start = i.indexOf('?');
var end = i.length;
var q = i.substring(start+1,end);
WriteFrames(q);
}
function WriteFrames(q){
document.write("<frameset rows='99%,1%' cols='*' border='0' framespacing='0' frameborder='NO'  onUnLoad=\"OpenWin('../../../cgi-bin/osaka_aso.cgi','AUTO','scrollbars=no,resizable=no,width=680,height=500,menubar=no,status=no');\">");
document.write("<frame src='../../cgi-bin/osaka_pro_be.cgi?"+q+"' name='TOPFRAME' marginwidth='0' marginheight='0' frameborder='NO' scrolling='YES'>");
document.write("<frame src='bottom.html' marginwidth='0' marginheight='0' scrolling='NO' frameborder='NO'>");
document.write("</frameset>");
}
function autosignout(i){
alert("ERROR :: A Sign Out or Reload error has occured.\n\nREASON :: Improper use of content management application.\nUser has improperly Reloaded the browser window or exited the application without first Signing Out.\nUser has been Signed Out automatically.\n\nSOLUTION :: In future please use the Refresh link provided and use the Sign Out facility before closing applications window.\n\nThank you");
window.close();
}
function Append(theUrl,theSession){
if(theUrl.indexOf("?") == -1){
window.location = theUrl+theSession;
} else {
theSession = theSession.substr(1,theSession.length);
window.location = theUrl+"&"+theSession;
}
}
function EditPressRelease(a,b){
b.ept.value = a.text;
b.epv.value = a.value;
}

function AddFields(){
// Colon : 1
// Pipe : 2
// Quote : 3
// Hash : 4
// Comma ; 5
// New Line ; 6
var form = document.ExportForm;
if(form.ftype.options[form.ftype.selectedIndex].value == "1" || form.ftype.options[form.ftype.selectedIndex].value == "3"){

while (form.fdelim.options.length>0){
deleteIndex=form.fdelim.options.length-1;
form.fdelim.options[deleteIndex]=null;
}

field_texts = new Array("Pipe |","Quote \"","Hash #","Comma ,");
field_values = new Array("2","3","4","5");

for(var i=0;i<field_texts.length;i++){
myOption=new Option();
myOption.text= field_texts[i];
myOption.value= field_values[i];
form.fdelim.options[i]=myOption;
}
myBlank=new Option("","",true,true);
form.fdelim.options[form.fdelim.options.length]=myBlank;
}

if(form.ftype.options[form.ftype.selectedIndex].value == "2"){
form.fdelim.options.length = 0;
myOption=new Option("Comma ,","5");
form.fdelim.options[0]=myOption;
myBlank=new Option("","",true,true);
form.fdelim.options[form.fdelim.options.length]=myBlank;
}
}

function AddRecord(){
// Colon : 1
// Pipe : 2
// Quote : 3
// Hash : 4
// Comma ; 5
// New Line ; 6
var form = document.ExportForm;

if(form.fdelim.options[form.fdelim.selectedIndex].value == "5"){
rec_texts = new Array("New line");
rec_values = new Array("6");
}
if(form.fdelim.options[form.fdelim.selectedIndex].value == "4"){
rec_texts = new Array("Colon :","Pipe |","Quote \"","Comma ,","New line");
rec_values = new Array("1","2","3","5","6");
}
if(form.fdelim.options[form.fdelim.selectedIndex].value == "3"){
rec_texts = new Array("Colon :","Pipe |","Hash #","Comma ,","New line");
rec_values = new Array("1","2","4","5","6");
}
if(form.fdelim.options[form.fdelim.selectedIndex].value == "2"){
rec_texts = new Array("Colon :","Quote \"","Hash #","Comma ,","New line");
rec_values = new Array("1","3","4","5","6");
}
if(form.fdelim.options[form.fdelim.selectedIndex].value == "1"){
rec_texts = new Array("Pipe |","Quote \"","Hash #","Comma ,","New line");
rec_values = new Array("2","3","4","5","6");
}

while (form.rdelim.options.length>0){
deleteIndex=form.rdelim.options.length-1;
form.rdelim.options[deleteIndex]=null;
}

for(var i=0;i<rec_texts.length;i++){
myOption=new Option();
myOption.text= rec_texts[i];
myOption.value= rec_values[i];
form.rdelim.options[i]=myOption;
}
}

function insertNewOption(){
var form = document.pro;
myOption=new Option();
myOption.text=form.ept.value;
myOption.value=form.epv.value;
if (form.press_list_tmp.selectedIndex>=0){
insertIndex=form.press_list_tmp.selectedIndex;
} else {
insertIndex=form.press_list_tmp.options.length;
}
form.press_list_tmp.options[insertIndex]=myOption;
}

function deleteOption(){
var form = document.pro;
if(form.press_list_tmp.selectedIndex == -1){
alert("Select An Article From List, Then Hit Delete");
} else {
form.press_list_tmp.options[form.press_list_tmp.selectedIndex]=null;
}
}

function deleteOptions(){
var form = document.pro;
while (form.press_list_tmp.options.length>0){
deleteIndex=form.press_list_tmp.options.length-1;
form.press_list_tmp.options[deleteIndex]=null;
}
}

function CreateCookie(form){
var first_name = "";
var last_name = "";
var email = "";
var address1 = "";
var address2 = "";
var city = "";
var zip = "";
var state = "";
var night_phone_a = "";
var night_phone_b = "";
var day_phone_a = "";
var day_phone_b = "";

if(form.first_name.value){
for(var i = 0;i<form.first_name.value.length;i++){
first_name += form.first_name.value.charCodeAt(i)+" ";
}
first_name = first_name.substr(0,first_name.length-1);
}

if(form.last_name.value){
for(var i = 0;i<form.last_name.value.length;i++){
last_name += form.last_name.value.charCodeAt(i)+" ";
}
last_name = last_name.substr(0,last_name.length-1);
}

if(form.email.value){
for(var i = 0;i<form.email.value.length;i++){
email += form.email.value.charCodeAt(i)+" ";
}
email = email.substr(0,email.length-1);
}

if(form.address1.value){
for(var i = 0;i<form.address1.value.length;i++){
address1 += form.address1.value.charCodeAt(i)+" ";
}
address1 = address1.substr(0,address1.length-1);
}

if(form.address2.value){
for(var i = 0;i<form.address2.value.length;i++){
address2 += form.address2.value.charCodeAt(i)+" ";
}
address2 = address2.substr(0,address2.length-1);
}

if(form.city.value){
for(var i = 0;i<form.city.value.length;i++){
city += form.city.value.charCodeAt(i)+" ";
}
city = city.substr(0,city.length-1);
}

if(form.zip.value){
for(var i = 0;i<form.zip.value.length;i++){
zip += form.zip.value.charCodeAt(i)+" ";
}
zip = zip.substr(0,zip.length-1);
}

if(form.state.value){
for(var i = 0;i<form.state.value.length;i++){
state += form.state.value.charCodeAt(i)+" ";
}
state = state.substr(0,state.length-1);
}

if(form.night_phone_a.value){
for(var i = 0;i<form.night_phone_a.value.length;i++){
night_phone_a += form.night_phone_a.value.charCodeAt(i)+" ";
}
night_phone_a = night_phone_a.substr(0,night_phone_a.length-1);
}

if(form.night_phone_b.value){
for(var i = 0;i<form.night_phone_b.value.length;i++){
night_phone_b += form.night_phone_b.value.charCodeAt(i)+" ";
}
night_phone_b = night_phone_b.substr(0,night_phone_b.length-1);
}

if(form.day_phone_a.value){
for(var i = 0;i<form.day_phone_a.value.length;i++){
day_phone_a += form.day_phone_a.value.charCodeAt(i)+" ";
}
day_phone_a = day_phone_a.substr(0,day_phone_a.length-1);
}

if(form.day_phone_b.value){
for(var i = 0;i<form.day_phone_b.value.length;i++){
day_phone_b += form.day_phone_b.value.charCodeAt(i)+" ";
}
day_phone_b = day_phone_b.substr(0,day_phone_b.length-1);
}

var date = new Date();
date.setTime(date.getTime()+(101*24*60*60*1000));
var expires = ";expires="+date.toGMTString();

var stuff_for_cookie = first_name+"&"+last_name+"&"+email+"&"+address1+"&"+address2+"&"+city+"&"+zip+"&"+state+"&"+night_phone_a+"&"+night_phone_b+"&"+day_phone_a+"&"+day_phone_b+expires+";path=/";

document.cookie = escape(stuff_for_cookie);
}

