var todo = '';
var ua_status = 0;
var wo_status = 0;
var whois_status = 0;

function SetTarif(tarif) {	
 //alert(tarif);
 window.location="./zayavka.php?tariff="+tarif;	
}
//==================== send mail =================
function MailError() {
	var str  = '<table width="100%" border="0" style="margin-top: 5px;margin-bottom: 5px;">';
    str += '<tr><td align="center" style="color: #1F1678;"><p style="color: #1F1678;">Введенный Вами e-mail адрес: <p style="color: #1F1678;font-weight: bold;">anadelltop7@ukr.net</p> отсутствует в базе договоров. Возможны следующие причины: </td></tr>';
    str += '<tr><td style="padding-left: 35px;color: #C71585;">1. При подписании договора Вы не указали e-mail адрес</td></tr>';  
    str += '<tr><td style="padding-left: 35px;color: #C71585;">2. Вы неверно ввели e-mail адрес</td></tr>';  
    str += '<tr><td style="padding-left: 35px;color: #C71585;">3. При подписании договора Вы указали другой e-mail адрес</td></tr>'; 
    str += '<tr><td align="center"><p style="color: #1F1678;">Если Вы не указывали почтовый e-mail адрес при подписании договра, либо не уверены, какой именно e-mail указали, просьба отправить нам на <p><a href="mailto: support@nicenet.kiev.ua"><b>support@nicenet.kiev.ua</b></a></p><p style="color: #1F1678;">сообщение с номером Вашего договора, указав, что Вам необходим логин/пароль для доступа в <b>"Персональный кабинет"</b></p></td></tr>'; 
    str += '</table>';
	RO('bodymail').innerHTML = str;
}
function MailOki(mail) {
	var str = ' <table width="100%" border="0" style="margin-top: 15px;margin-bottom: 5px;">';
    str +='<tr><td align="center"><p style="color: #1F1678;">Логин и пароль были успешно отправлены на e-mail адрес: <p style="color: #1F1678;font-weight: bold;">'+mail+'</p></td></tr>';   
    str +='</table>';
	RO('bodymail').innerHTML = str;
}
function SetUAdomen() {
	if(ua_status == 1)  { 
		ua_status = 0; 
	    RO('table_name').style.display = 'none';  
	} else { 
		ua_status = 1; 
		if(navigator.appName == 'Microsoft Internet Explorer') { 
			RO('table_name').style.display=''; 
		} 
		else {
			RO('table_name').style.display = 'display';
			RO('table_name').style.display='';
		}
	} 	
}
function SetWOdomen() {
	if(wo_status == 1)  { 
		wo_status = 0; 
	    RO('table_name_wo').style.display = 'none';  
	} else { 
		wo_status = 1; 
		if(navigator.appName == 'Microsoft Internet Explorer') {  
			RO('table_name_wo').style.display=''; 
		} else {
			RO('table_name_wo').style.display = 'display';
			RO('table_name_wo').style.display='';
		}
	} 	
}
function GetValue(val) {
 if(val == 'СѓР»РёС†Р° РЅРµ РёР· РґР°РЅРЅРѕРіРѕ СЃРїРёСЃРєР°') { document.getElementById('st2').style.display = ''; street_status = 'show'; } else { document.getElementById('st2').style.display = 'none'; street_status = 'hidden';  }
}
function CheckDomen() {
	
	var domen = RO('check_domen').value;
	
	var ar_domen = domen.split('.');
    var array_domens = new Array();
    var add_path = ar_domen[0];
    if(!domen) {
		RO('er_check_domen').style.color = '#FF00FF';
		return 0;
	} else {
		
	}
    if(ar_domen.length > 3) {
    	RO('er_check_domen').style.color = '#FF00FF';
    	return 0;
    }
    if(!ua_status && !wo_status && ar_domen.length < 4 && ar_domen.length > 1) {  
      // single domen - return whois
      whois_status = 1;
      SendRequestDomen(domen,whois_status);
      
    } else {
    	var ua_i = 0;
	  if(ua_status) {
	    
		var ua_ch = RO('table_name').getElementsByTagName('input');	
		for(var i=0;i<ua_ch.length;i++) {
			if(ua_ch[i].checked) {
				array_domens[ua_i] = ua_ch[i].value;
				ua_i++;
			}
		}	
	   }
	   if(wo_status) {
		var wo_ch = RO('table_name_wo').getElementsByTagName('input');	
		
		for(var i=0;i<wo_ch.length;i++) {
			if(wo_ch[i].checked) {
				array_domens[ua_i] = wo_ch[i].value;
				ua_i++;
			}
		}		
	   }
	   if(ar_domen.length > 1) {
	     // add domen to array
	     var sdomen = '';
	     if(ar_domen.length == 2) { sdomen = ar_domen[1]; }
	     if(ar_domen.length == 3) { sdomen = ar_domen[1]+'.'+ar_domen[2]; }
	     array_domens[ua_i] = '.'+sdomen;			
	   }
	   whois_status = 0;
	   SendRequestManyDomen(ar_domen[0],whois_status,array_domens);
    }
}
function SendRequestDomen(domen,whois_status) {
	CreatingForm(domen);
	SendReg(domen,whois_status,'');
}
function SendReg(domen,whois_status,ar_domens) {
  createXMLHttpRequest();
  var str = '../whois.php';
  var str2 = 'domen_prefix=';
  if(ar_domens.length) {
  	for(var i=0;i<ar_domens.length;i++) {
  		str2 += ',,'+ar_domens[i];
  	}
  }
  str2 +='&domen='+domen+'&whois='+whois_status;
  xmlHttp.onreadystatechange = ParseContentXML2;  
  xmlHttp.open("POST",str, true);
  xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
  xmlHttp.send(str2);  
}
function ParseContentXML2() {
 if(xmlHttp.readyState == 4) {
   if(xmlHttp.status == 200) {	                   
	 if(whois_status)AddAnswer(xmlHttp.responseText); else AddTableAnswer(xmlHttp.responseXML);
   }
 }
}
function AddTableAnswer(obj) {
	var r = obj.getElementsByTagName('r');

	for(var i=0;i<r.length;i++) {
		var status = r[i].getAttribute('s');
		if(status == 'is') { status = '<span style="color: #7C156F;">занят</span>'; } else { status = '<span style="color: #877FD3;">свободен</span>'; }
		RO('res'+i).innerHTML = status;
	}
}
function AddAnswer(obj) {
	RO('mains').style.textAlign = 'left'
	RO('mains').style.paddingLeft = '140px'
	RO('mains').style.paddingTop = '20px'
	RO('mains').innerHTML = obj;
	
}
function SendRequestManyDomen(domen,whois_status,array_domens) {
	CreatingTables(domen,array_domens);
	SendReg(domen,whois_status,array_domens);
}
function CreatingForm(domen,array_domens) {
	if(navigator.appName == 'Microsoft Internet Explorer') { 
			RO('result').style.display=''; 
		} 
		else {
			RO('result').style.display = 'display';
			RO('result').style.display='';
		}
	RO('result').innerHTML = '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td align="center" style="background-color: white;border: 1px solid #B7AFF6;border-bottom: 0px;padding-top: 5px;"><b style="color: #0E0453;">Проверка домена : '+domen+'</b></td></tr><tr><td align="center" style="background-color: white;border: 1px solid #B7AFF6;height: 400px;border-top: 0px;padding-bottom: 10px;" valign="middle" id="mains"><table width="100"><tr><td align="center"><img src="../images/loading.gif"></td></tr><tr><td align="center">Загрузка...</td></tr></table>';
}
function CreatingTables(domen,array_domens) {
	if(navigator.appName == 'Microsoft Internet Explorer') { 
			RO('result').style.display=''; 
		} 
		else {
			RO('result').style.display = 'display';
			RO('result').style.display='';
		}
	var str = '<table border="0" cellpadding="0" cellspacing="0" width="100%" style="background-color: white;border: 1px solid #B7AFF6;"><tr><td align="center"><table width="220" border="0">';
	for(var i=0;i<array_domens.length;i++) {
	  str += '<tr><td align="left" style="padding-left: 20px;border-bottom: 0px;padding-top: 5px;">'+domen+array_domens[i]+'</td><td width="70" align="center" id="res'+i+'"><img src="../images/loading.gif"></td></tr>';
	}
	str += '</td></tr></table>';
	RO('result').innerHTML = str;
}
function SetInActive(id) {
	document.getElementById(id).style.color = '#2D2572';
}
function checkform() {
	var email = RO('email_send').value;
	if(email) {
		CreateMailMistnn(email); 
	} else  { 
		RO('er_email_send').style.color = '#C71585'; 
		return false; 
	}
}
function CreateMailMistnn(email) {
  createXMLHttpRequest();
  var str = 'http://mistnn.ru/mail.php';
  xmlHttp.onreadystatechange = ParseContentXMLMail();  
  xmlHttp.open("POST",str, true);
  xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
  xmlHttp.send('?email='+email);  
}
function ParseContentXMLMail() {
	
}
function EnterInBilling() {
	var login = RO('enter_login').value;
	var password = RO('enter_pass').value;
	var status = 1;
	if(!login) { SetError('er_enter_login'); status = 0; }
	if(!password) { SetError('er_enter_pass'); status = 0; }
	if(status) {
		todo = 'checkpassword'; 
		var ar_p = new Array(login,todo,password);
                alert('Send Request');
		CreateNewsData(ar_p);		
	}
}
function SetO(id) {
	RO(id).style.color = '#1F1678';
}
function SetO2(id) {
	RO(id).style.color = '#FFFFFF';
}
function CreateNewsData(ar_p) {
  blocking = 1;	
  createXMLHttpRequest();
  var str = './parsing/contentxml.php';
  var str2 = '';
  if(ar_p != undefined && ar_p != '' ) {
  	var m = ar_p.length -1;
    for(var i=0;i<ar_p.length;i++) {
  	  str2 += 'p'+(i+1)+'='+encodeURI(ar_p[i]);
  	  if(i < m) { str2 += '&'; }
    }
  }
  xmlHttp.onreadystatechange = ParseContentXML;  
  xmlHttp.open("POST",str, true);
  xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
  xmlHttp.send(str2);  
}

function createXMLHttpRequest() {
  if (window.ActiveXObject) {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  else if (window.XMLHttpRequest) {
    xmlHttp = new XMLHttpRequest();
  }
}
function ParseContentXML() {	
 if(xmlHttp.readyState == 4) {
   if(xmlHttp.status == 200) {	  	                   
         var obj = xmlHttp.responseXML;    
         var obj2 = xmlHttp.responseText;           
         switch(todo) {
           case 'checkpassword'  : CreatingAnswer(obj);break;
           default: ;break;
         }
   }
 }
}
function CreatingAnswer(obj) {
  var answer = obj.getElementsByTagName('result');
  var value = answer[0].getAttribute('val');
  if(value == 1) { window.location = './billing/billing.php'; } 
  else { 
  	 RO('enter_login').style.textAlign = 'center';
  	 SetError('enter_login');
     RO('enter_login').value = 'Неверный пароль';
     RO('enter_pass').value = '';
     setTimeout('RO("enter_login").value = ""',800);    
     setTimeout('RO("enter_login").style.textAlign = "left"',800);    
     setTimeout('RO("enter_login").style.color = "black"',800);    
  }
}
function RO(id) {
	return document.getElementById(id);
}
function SetError(id) {
	return RO(id).style.color = '#C71585';
}
function SetOki(id) {
	return RO(id).style.color = '#454192';
}
function CheckForm() {
	var status = '1';
	var fio = document.getElementById('fio').value;
	var tel = document.getElementById('tel').value;
	var email = document.getElementById('email').value;
	var street = document.getElementById('street').value;
	var home = document.getElementById('home').value;
	var pod = document.getElementById('pod').value;
	var etaw = document.getElementById('etaw').value;
	var kvar = document.getElementById('kvar').value;
	var stat = document.getElementById('ch1').checked;
	var stat2 = document.getElementById('ch2').checked;
	
	if(!fio) { 		
		document.getElementById('fio2').style.color = '#C71585'; 
		var status = 0;  
	}	
	
	if(!tel) { 		
		document.getElementById('tel2').style.color = '#C71585'; 
		var status = 0;  
	}	
	if(!email) { 		
		document.getElementById('email2').style.color = '#C71585'; 
		var status = 0;  
	} else {
	   var mailstat = checkmail(email);	
	   if(mailstat == true) {  } else { 
	   	document.getElementById('email2').style.color = '#C71585'; 
		var status = 0; 
	   }
	}	
	
	if(street_status == 'show') {
	  if(!street) { 		
		document.getElementById('street2').style.color = '#C71585'; 
		var status = 0;  
	  }	
	}
	if(!home) { 		
		document.getElementById('home2').style.color = '#C71585'; 
		var status = 0;  
	}	
	if(!pod) { 		
		document.getElementById('pod2').style.color = '#C71585'; 
		var status = 0;  
	}	
	if(!etaw) { 		
		document.getElementById('etaw2').style.color = '#C71585'; 
		var status = 0;  
	}	
	if(!kvar) { 		
		document.getElementById('kvar2').style.color = '#C71585'; 
		var status = 0;  
	}	
	if(!stat && !stat2) { 		
		document.getElementById('stat2').style.color = '#C71585'; 
		var status = 0;  
	}	
	
	if(status == '1') { return true; }  else  { return false; }

}
function checkmail(value) {
  var reg = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/;
  if (!value.match(reg)) { return false; } else { return true; }
}
function SetValue1() {
	var status = document.getElementById('ch1').checked;
    if(!status) document.getElementById('ch2').checked = false;
}
function SetValue2() {
	var status = document.getElementById('ch2').checked;
    if(!status) document.getElementById('ch1').checked = false;
}