  function picture(link, pic_w, pic_h){

if (screen.availWidth > pic_w) {
var w = pic_w;
var left = (screen.availWidth-pic_w)/2;
}

if (screen.availWidth < pic_w) {
var w = screen.availWidth-20;
var left = 5;
}

if (screen.availHeight > pic_h) {
var h = pic_h;
var top = (screen.availHeight-pic_h)/2;
}

if (screen.availHeight < pic_h) {
var h = screen.availHeight-40;
var top = 5;
}


var s = 'width='+w+', height='+h+', top='+top+', left='+left+', location=no,toolbar=no,status=no,scrollbars=yes';

    photo=window.open(link,null,s);
    photo.focus();
  }




function color(id1, id2) {
eval('document.getElementById("' + id1 + '").style.background = "#FFCCCC"');
eval('document.getElementById("' + id2 + '").style.background = "#FFCCCC"');
}

function color_white (id1, id2) {
eval('document.getElementById("' + id1 + '").style.background = "#EEEEEE"');
eval('document.getElementById("' + id2 + '").style.background = "#EEEEEE"');
}



function checkform(){

var at=0;

if (document.addtable.model_new.value == "0") {at = 10; color("c1","c2");} else {color_white("c1","c2");}
if (document.addtable.symptom_new.value == "0") {at = 10; color("c5","c6");} else {color_white("c5","c6");}
if (document.addtable.defect_new.value == "0") {at = 10; color("c7","c8");} else {color_white("c7","c8");}

var res = /^[0-9]{7}$/.test(document.addtable.serial_new.value);
if (res == false) {at = 10; color("c3","c4");} else {color_white("c3","c4");}

var res = /^[0-9]{2}.[0-9]{2}.[0-9]{2}$/.test(document.addtable.id_new.value);
if (res == false) {at = 10; color("c9","c10");} else {color_white("c9","c10");}

var res = /^[0-9]{2}.[0-9]{2}.[0-9]{2}$/.test(document.addtable.rd_new.value);
if (res == false) {at = 10; color("c11","c12");} else {color_white("c11","c12");}


if (at == 10) {alert("Not all data in the fields is correct!\nPlease check and correct the fields marked red.\n");}
else {

var wind_w = 350;
var left = (screen.availWidth-wind_w)/2;
var wind_h = 350;
var top = (screen.availHeight-wind_h)/2;
var s = 'width='+wind_w+', height='+wind_h+', top='+top+', left='+left+', location=no,toolbar=no,status=no,scrollbars=no';


window.open('about:blank','test1', s);
addtable.submit();
}
}



function checkformadmin(){

var at=0;

if (document.addtable.model_new.value == "0") {at = 10; color("c1","c2");} else {color_white("c1","c2");}
if (document.addtable.symptom_new.value == "0") {at = 10; color("c5","c6");} else {color_white("c5","c6");}
if (document.addtable.defect_new.value == "0") {at = 10; color("c7","c8");} else {color_white("c7","c8");}

var res = /^[0-9]{7}$/.test(document.addtable.serial_new.value);
if (res == false) {at = 10; color("c3","c4");} else {color_white("c3","c4");}

var res = /^[0-9]{2}.[0-9]{2}.[0-9]{2}$/.test(document.addtable.id_new.value);
if (res == false) {at = 10; color("c9","c10");} else {color_white("c9","c10");}

var res = /^[0-9]{2}.[0-9]{2}.[0-9]{2}$/.test(document.addtable.rd_new.value);
if (res == false) {at = 10; color("c11","c12");} else {color_white("c11","c12");}


if (at == 10) {alert("Some fields are incorrect!\nPlease correct the fields marked red.\n");}
else {
addtable.submit();
}
}





function dateform(inp){

var wind_w = 230;
var left = (screen.availWidth-wind_w)/2;
var wind_h = 275;
var top = (screen.availHeight-wind_h)/2;

var s = 'width='+wind_w+', height='+wind_h+', top='+top+', left='+left+', location=no,toolbar=no,status=no,scrollbars=no';

if (inp == 'rds') {var date1 = window.document.table.rds.value;}
if (inp == 'rde') {var date1 = window.document.table.rde.value;}
if (inp == 'ids') {var date1 = window.document.table.ids.value;}
if (inp == 'ide') {var date1 = window.document.table.ide.value;}
if (inp == 'tds') {var date1 = window.document.table.tds.value;}
if (inp == 'tde') {var date1 = window.document.table.tde.value;}
if (inp == 'rd_new') {var date1 = window.document.addtable.rd_new.value;}
if (inp == 'id_new') {var date1 = window.document.addtable.id_new.value;}

var l = 'calendar.php?date1=' + date1 + '&inp=' + inp;

window.open(l,'test1', s);
}


function returnDate(d,inp) {
var txt = d;

if (inp == 'rds') { window.opener.table.rds.value = txt;}
if (inp == 'rde') { window.opener.table.rde.value = txt;}
if (inp == 'tds') { window.opener.table.tds.value = txt;}
if (inp == 'tde') { window.opener.table.tde.value = txt;}
if (inp == 'ids') { window.opener.table.ids.value = txt;}
if (inp == 'ide') { window.opener.table.ide.value = txt;}
if (inp == 'rd_new') { window.opener.addtable.rd_new.value = txt;}
if (inp == 'id_new') { window.opener.addtable.id_new.value = txt;}

window.close();
}


function closeandreload() {

if (!opener.closed) {opener.location.href = 'form.php?order=2';}
self.close();
}
