/* il 10.01.06 Atilekt.com */
function c_il_CSS (){}
var er_cov=[], cov_er,er_il,il_prob, il_CSS=new c_il_CSS();
/*IE5.0*/
if(!(il_prob=[]).push)Array.prototype.push=function(){var i=this.length,j=0,a=this.push.arguments,n=a.length,k=i+n;for(;i<k;i++,j++)this[i]=a[j];return j+1}

/* PNG-блок. Приоритет без JS у IE 6.0 */
function png_Atilekt(e,n){
var u,p,t;
try{
if(((navigator.appName.slice(1,9).toLowerCase()!='icrosoft')||(window.opera))&&(u=e.src)){
	p=u.replace(/\/\w+\.(gif|jpg)$/,'/'+n);
	e.onload=null;
	if(p!=u)e.src=p
}
}catch(t){
t.il='png';
er_cov[er_cov.length]=t
}
}

/* PNG-блок pn_abs */
function pn_abs(){
var e,i,u,k,p,t;
try{
	if((navigator.appName.toLowerCase().slice(1,9)!='icrosoft')||(window.opera)){
		e=document.getElementById('div_menu').getElementsByTagName('DIV');
		for(i=0;i<e.length;i++){
			if((u=e[i]).className=='filter_pn'){
				/* Opera 8.5 - всегда буду помнить твою мать! Спасибо и на том */
				u.style.backgroundImage='url(img/pn_abs_gr.png)'
				u.style.backgroundRepeat='no-repeat'
				u.style.backgroundPosition='right top'
			}
		}
	}
}catch(t){
t.il='png_pn';
er_cov.push(t)
}
}


window.onload=on_il;
function on_il(){
var h={fs_il:fs_il},p,er;
for(p in h){
	try{
		h[p]()
	}catch(er){
	er.il='Winonl:'+p;
	er_cov.push(er_il)
	alert('готово')
	}
}
}


function off_il(){var p;for(p in er_cov)er_cov[p]=null;er_cov=null}
window.onunload=off_il;

function fs_il(){
if((navigator.appName.toLowerCase().slice(1,9)=='icrosoft')&&(navigator.userAgent.toLowerCase().indexOf('msie 5.0')!=-1)){
}
}


function imgopen (imgf,tit){
img1=new Image();
var date = new Date();
img1.src=imgf+"?"+date.getMilliseconds();;
date = new Date();
rand_id='image'+date.getMilliseconds();

outf="<html>"
 +"<head>"
 +"<title>"+tit+"</title>"
 +"<style>body{margin:0px}</style>"
 +"</head>"
 +"<body leftmargin=0 topmargin=0>"
 +"<img src=\""+imgf+"\" width=100% height=100% ></body></html>";
 

var si = setInterval(imgCheck,100);
function imgCheck(){
 if(img1.width!=0 && img1.height!=0){
  clearInterval(si);
  openIMG();
 }
}
function openIMG(){
// var leftVal = ((screen.width) - (img1.width)) / 2;
// var topVal = ((screen.height) - (img1.height)) / 2;
 var leftVal = 0;
 var topVal = 0;

 iopen="iwin=self.open('"+imgf+"', '"+rand_id+"', 'width='+(img1.width)+',height='+(img1.height)+',top='+topVal+',left='+leftVal+'');"+"iwin.document.write('"+outf+"');"+"iwin.focus();";
 eval(iopen);
 }
}
function Errsub()
{
    try
    {
       form1.submit();
    }
    catch(err)
    {
   
        alert("Incorrect file format or wrong path to file");
        return false;
 
    } 
    return true;
 } 
function errsub_check()
{
    try
    {
       form1.submit();
    }
    catch(err)
    {
        alert("Please clear your selecting files");
    } 
 }
function check_opera()
{
     if(navigator.userAgent.toLowerCase().indexOf("opera")!=-1)
    {
          
        document.getElementById(document.getElementById("sp_FileUpload1").innerHTML).style.color = "#000000";
        document.getElementById(document.getElementById("sp_FileUpload2").innerHTML).style.color = "#000000"; 
        document.getElementById(document.getElementById("sp_FileUpload3").innerHTML).style.color = "#000000";
        document.getElementById(document.getElementById("sp_FileUpload4").innerHTML).style.color = "#000000";
        document.getElementById(document.getElementById("sp_FileUpload5").innerHTML).style.color = "#000000";

    }
}
function open_window(url)
{
   var _screenX = screen.width/1.5;
   var _screenY = screen.height/1.5;
   var _left = screen.width/10;
   var _top = screen.height/10;
   
   var wind = window.open(url,"none","width="+_screenX+",height="+_screenY+",scrollbars=yes, resizable=yes,left=" + _left + ",top= " + _top + "'");
   wind.focus();
}
function checked_(){
var Span_please_All =  document.getElementById("Span_please_All");  
var tbx_name =  document.getElementById(document.getElementById("sp_tbx_name").innerHTML); 
var TDName =  document.getElementById("TDName");    
var DDL_country =  document.getElementById(document.getElementById("sp_DDL_country").innerHTML);  
var TDCountry =  document.getElementById("TDCountry");    
var DDL_month =  document.getElementById(document.getElementById("sp_DDL_month").innerHTML);   
var DDL_Day =  document.getElementById(document.getElementById("sp_DDL_Day").innerHTML);  
var DDL_Year =  document.getElementById(document.getElementById("sp_DDL_Year").innerHTML); 
var TDDate =  document.getElementById("TDDate"); 
var SPErrDate =  document.getElementById("SPErrDate"); 
var tbx_email =  document.getElementById(document.getElementById("sp_tbx_email").innerHTML);
var TDEmail =  document.getElementById("TDEmail"); 
var TDFile =  document.getElementById("TDFile");

var FileUpload1 =  document.getElementById(document.getElementById("sp_FileUpload1").innerHTML);
var TDFile1 =  document.getElementById("TDFile1");
var TDErr1 =  document.getElementById("TDErr1");
var FileUpload2 =  document.getElementById(document.getElementById("sp_FileUpload2").innerHTML);  
var TDFile2 =  document.getElementById("TDFile2");
var TDErr2 =  document.getElementById("TDErr2");
var FileUpload3 =  document.getElementById(document.getElementById("sp_FileUpload3").innerHTML);
var TDFile3 =  document.getElementById("TDFile3");
var TDErr3 =  document.getElementById("TDErr3");
var FileUpload4 =  document.getElementById(document.getElementById("sp_FileUpload4").innerHTML); 
var TDFile4 =  document.getElementById("TDFile4");  
var TDErr4 =  document.getElementById("TDErr4");
var FileUpload5 =  document.getElementById(document.getElementById("sp_FileUpload5").innerHTML); 
var TDFile5 =  document.getElementById("TDFile5"); 
var TDErr5 =  document.getElementById("TDErr5"); 
var checkbox =  document.getElementById(document.getElementById("sp_checkbox").innerHTML); 

var SpanCheck =  document.getElementById("SpanCheck");    
var cordat = true;
    if(tbx_name.value == "")
        {
            TDName.style.color = "#f00f00";
            tbx_name.style.borderColor = "#f00f00"; 
            cordat = false;
        }
    else
        {
            tbx_name.style.borderColor = "#83093d";
            TDName.style.color = "";
        }
    if(DDL_country.value == "-1")
        {
            DDL_country.style.borderColor = "#f00f00"; 
            TDCountry.style.color = "#f00f00";
            cordat = false;
        }
    else
        {
           DDL_country.style.borderColor = "#83093d";
           TDCountry.style.color = "";
        }
var month = 0;
var year = 0;
var day = 0;
    month = parseInt(DDL_month.value);
    day = parseInt(DDL_Day.value) == -1 ? 0 : parseInt(DDL_Day.value);
    year = parseInt(DDL_Year.value) == "-1" ? 0 : parseInt(DDL_Year.value);
    if(
       (month == -1 || day < 1 || year == 0)
       ||
       (day > 31 && (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12))
       ||
       (day > 30 && (month == 4 || month == 6 || month == 9 || month == 11))
       ||
       (day > 29 && month == 2 && (year % 4) == 0)
       ||
       (day > 28 && month == 2 && (year % 4) != 0)
      )
      {
          DDL_month.style.borderColor = "#f00f00";   
          DDL_Day.style.borderColor = "#f00f00"; 
          DDL_Year.style.borderColor = "#f00f00"; 
          DDL_month.style.backgroundColor= "#83093d"; 
          DDL_Day.style.backgroundColor= "#83093d"; 
          DDL_Year.style.backgroundColor= "#83093d";        
          TDDate.style.color = "#f00f00"; 
       //   SPErrDate.innerHTML = "Incorrect Date";
          cordat = false;
        }
    else
        {
          DDL_month.style.borderColor = "";   
          DDL_Day.style.borderColor = ""; 
          DDL_Year.style.borderColor = ""; 
          DDL_month.style.backgroundColor= "";  
          DDL_Day.style.backgroundColor= "";  
          DDL_Year.style.backgroundColor= "";          
          TDDate.style.color = ""; 
      //    SPErrDate.innerHTML = "";
        }
var string = "";

var str=tbx_email.value; 
//var reg=/([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/i;
var reg=/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i;

var result_email=reg.test(str);
    if(!result_email)
        {
            TDEmail.style.color = "#f00f00";
            tbx_email.style.borderColor = "#f00f00"; 
            cordat = false;
                if(tbx_email.value.length>0)
                string += "E-mail is not correct.\n";
        }
    else
        {
            TDEmail.style.color = "";
            tbx_email.style.borderColor = "#83093d";
        }
var td_file = true;

    function DecodeS(s)
    {
        //alert("DecodeS "+s);
        return s;
    }
    
    function TestS(s)
    {
        var i=s.lastIndexOf(".");
        var ext=s.substr(i+1).toLowerCase();
        
        //alert("i="+i);
        //alert("ext="+ext);
        
        var rez= 
        ( 
            //(s.indexOf(":\\")==1 || s.indexOf("\\\\")==1)  &&
            (i>s.indexOf(":\\") || i>s.indexOf("\\\\")) && 
            (ext =="jpg" || ext =="png" || ext =="bmp" || ext =="jpeg" || 
               ext =="gif" || ext =="tiff" || ext =="tif")
        );
        //alert("rez="+rez);
        
        return rez;
    }

    ///////////// 1
    var srt_file = DecodeS(FileUpload1.value.toString());

//fso = new ActiveXObject("Scripting.FileSystemObject");
//        file = fso.OpenTextFile("images\\1.jpg", 1, false);
//        if(file){
//            alert('файл на месте');
//        }
//                  else{alert('файла нет');}

    var len=srt_file.length;
    
    if (TestS(srt_file)) 
    {    
        TDFile1.style.color = ""; 
        FileUpload1.style.backgroundColor= "";
        TDErr1.innerHTML = ""; 
    }   
    else 
    {
       TDFile1.style.color = "#f00f00"; 
       FileUpload1.style.backgroundColor= "#83093d";
       TDErr1.innerHTML = "Incorrect file format or wrong path to file."; 
       cordat = false;
       td_file = false;
    }
    /////////////// 2
    srt_file = DecodeS(FileUpload2.value.toString());
    if (TestS(srt_file)) 
    {    
        TDFile2.style.color = ""; 
        FileUpload2.style.backgroundColor= "";
        TDErr2.innerHTML = "";
    }   
    else 
    {
        TDFile2.style.color = "#f00f00"; 
        FileUpload2.style.backgroundColor= "#83093d";
        TDErr2.innerHTML = "Incorrect file format or wrong path to file.";
        cordat = false;
        td_file = false;
    }
    /////////////// 3
    srt_file =  DecodeS(FileUpload3.value.toString());
    if (TestS(srt_file)) 
    {    
        TDFile3.style.color = ""; 
        FileUpload3.style.backgroundColor= "";
        TDErr3.innerHTML = "";
    }   
    else 
    {
        TDFile3.style.color = "#f00f00"; 
        FileUpload3.style.backgroundColor= "#83093d";
        TDErr3.innerHTML = "Incorrect file format or wrong path to file.";
        cordat = false;
        td_file = false;
    }
    /////////////// 4
    srt_file =  DecodeS(FileUpload4.value.toString())
    if(TestS(srt_file)) 
    {    
        TDFile4.style.color = ""; 
        FileUpload4.style.backgroundColor= "";
        TDErr4.innerHTML = "";
    }   
    else 
    {
        TDFile4.style.color = "#f00f00"; 
        FileUpload4.style.backgroundColor= "#83093d";
        TDErr4.innerHTML = "Incorrect file format or wrong path to file.";
        cordat = false;
        td_file = false;
    }
    /////////////// 5
    srt_file =  DecodeS(FileUpload5.value.toString());
    if(TestS(srt_file)) 
    {    
        TDFile5.style.color = ""; 
        FileUpload5.style.backgroundColor= "";
        TDErr5.innerHTML = "";
    }   
    else 
    {
        TDFile5.style.color = "#f00f00"; 
        FileUpload5.style.backgroundColor= "#83093d";
        TDErr5.innerHTML = "Incorrect file format or wrong path to file.";
        cordat = false;
        td_file = false;
    }
    ///////////
    ////////////// сравниваем 5 файлов
    var i = 1;
    var j = 1;
    var string_photo ="";
    for (i=1;i<6;i++)
    {
        for (j = i;j<6;j++)
        {
            if (document.getElementById(document.getElementById("sp_FileUpload"+i).innerHTML).value == document.getElementById(document.getElementById("sp_FileUpload"+j).innerHTML).value
                && document.getElementById(document.getElementById("sp_FileUpload"+i).innerHTML).value != "" 
                && document.getElementById(document.getElementById("sp_FileUpload"+j).innerHTML).value != ""
                && i!=j
                && document.getElementById("TDFile"+i).style.color != "#f00f00"
                && document.getElementById("TDFile"+j).style.color != "#f00f00"
                )
            {
                 cordat = false;
                if (string_photo.indexOf(i)==-1)
                {
                    if (string_photo.length < 1)
                    {
                        string_photo += i+","+j+"";
                    }
                    else 
                    {
                         string_photo += " and "+i+","+j+"";
                    }
                }
                else if (string_photo.indexOf(j)==-1)
                {
                    string_photo += ","+j+"";
                }
            }
       }
    }
    if (string_photo.length>2)
        string = string + "You are trying to upload the same photo with number " + string_photo+".";
    if (string.length>2)
        alert(string);
    
    //////////////////

    
    if (!checkbox.checked)
    {
        SpanCheck.style.color = "#f00f00"; 
        checkbox.style.backgroundColor= "#f00f00";
        cordat = false;
    }
    else 
    {
        checkbox.style.backgroundColor= "";
        SpanCheck.style.color = "";
    }
    
    if (td_file&&cordat)
    {
        TDFile.style.color = "";
        Span_please_All.style.color = "";
    }
    else if ((!td_file)&&(!cordat))
         {
            TDFile.style.color = "#f00f00"; 
            Span_please_All.style.color = "#f00f00"; 
          //  alert("Please complete all required fields. Incorrect file format.");
         }
    else if (td_file&&(!cordat))
         {
            TDFile.style.color = ""; 
            Span_please_All.style.color = "#f00f00"; 
         //   alert("Please complete all required fields.");
         }
 //////////////////////////////////////

return cordat;
}









