function getCities(){

					document.getElementById('citeis_code_loader').style.display = "block";
					var box = document.getElementById('countreis_code');
					var country = box.options[box.selectedIndex].value;
 					
			new Ajax.Request('/countryCode.html?country='+country,
	{
		method: 'post',
		onSuccess: function(o){	
			if(o.responseText !== undefined){
						//var is = Is();
						///	alert(is.info);
							document.getElementById('citeis_code_loader').style.display = "none";
							 parent.document.getElementById("citeis_code_table").innerHTML= o.responseText;
							}
							},
		onFailure : function (){alert("Error")}
		
		}
		);			 
					 
				}
				
				

		
function getRoamingOperatorsPre(){
					document.getElementById("operator_info_table_pre").innerHTML = "";
					document.getElementById('citeis_code_loader_pre').style.display = "block";
					var box = document.getElementById('countreis_huree_pre');
					var country = box.options[box.selectedIndex].value;	
					new Ajax.Request('/roamingOperatorsPre.html?country='+country,
	{
		method: 'post',
		onSuccess: function(o){		 
			if(o.responseText !== undefined){
						//var is = Is();
						///	alert(is.info);
							document.getElementById('citeis_code_loader_pre').style.display = "none";
							 parent.document.getElementById("operator_info_table_pre").innerHTML= o.responseText;
									/*
									end
									*/
									
							}},
		onFailure : function (){alert("Error")}
		
		}
		);	
		
		} 


function getRoamingOperators(){
					document.getElementById("operator_info_table").innerHTML = "";
					document.getElementById('citeis_code_loader').style.display = "block";
					var box = document.getElementById('countreis_huree');
					var country = box.options[box.selectedIndex].value;	
					new Ajax.Request('/roamingOperators.html?country='+country,
	{
		method: 'post',
		onSuccess: function(o){		 
			if(o.responseText !== undefined){
						//var is = Is();
						///	alert(is.info);
							document.getElementById('citeis_code_loader').style.display = "none";
							 parent.document.getElementById("operator_info_table").innerHTML= o.responseText;
									/*
									end
									*/
									
							}},
		onFailure : function (){alert("Error")}
		
		}
		);	
		
		} 
function getRoamingOperatorsPrepaid(){
					document.getElementById("operator_info_table").innerHTML = "";
					document.getElementById('citeis_code_loader').style.display = "block";
					var box = document.getElementById('countreis_huree');
					var country = box.options[box.selectedIndex].value;	 
				  	
			new Ajax.Request('/roamingOperatorsPrepaid.html?country='+country ,{
				method: 'post',
				onSuccess: function(o){		 
							if(o.responseText !== undefined){ 
							document.getElementById('citeis_code_loader').style.display = "none";
							 parent.document.getElementById("operator_info_table").innerHTML= o.responseText;
							}},
				onFailure : function (){alert("Error")}
			});	
					  }
					  
function getRoamingAllOperatorsPrepaid(){
					document.getElementById("operator_info_table").innerHTML = "";
					document.getElementById('citeis_code_loader').style.display = "block";
	    	new Ajax.Request('/roamingOperatorsPrepaidAll.html' ,{
				method: 'post',
				onSuccess: function(o){		 
								if(o.responseText !== undefined){ 
							document.getElementById('citeis_code_loader').style.display = "none";
							 parent.document.getElementById("operator_info_table").innerHTML= o.responseText; 		
							}},
				onFailure : function (){alert("Error")}
			});	
				}

function phonerequest(){
	var name = document.getElementById('name').value;
	var phonenumber = document.getElementById('phonenumber').value;
	var lname = document.getElementById('lname').value;
	var address = document.getElementById('address').value;
	var mail = document.getElementById('mail').value;
	if(name!=''&&phonenumber!=''&&lname!=''&&address!=''&&mail!=''){
		if(checkPhone(phonenumber)==true){
		if(echeck(mail)==true){
	var models = document.getElementsByName("model");
	var model= 0;
	for (var x = 0; x < models.length; x ++) {
		if (models[x].checked) {
			model = models[x].value;		
			}
		}
	var pays = document.getElementsByName("pay");
	var pay= 0;
	for (var x = 0; x < pays.length; x ++) {
		if (pays[x].checked) {
			pay = pays[x].value;		
			}
		}
	var paytimes = document.getElementsByName("paytime");
	var paytime = 0;
	for (var x = 0; x < paytimes.length; x ++) {
		if (paytimes[x].checked) {
			paytime= paytimes[x].value;		
			}
		}
    	new Ajax.Request('/phoneRequest.html?name='+name + '&phonenumber='+phonenumber + '&lname='+lname+ '&address='+address + '&mail='+mail + '&model='+model + '&pay='+pay + '&paytime='+paytime  ,{
				method: 'post',
				onSuccess: function(o){		 
								if(o.responseText !== undefined){
							 parent.document.getElementById("requestphone").innerHTML= o.responseText; 		
							}},
				onFailure : function (){alert("Error")}
			});
		}} 
	}else {
		alert("Та дутуу бөглөсөн байна");
	}
				}



function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Э-Шуудан буруу байна")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Э-Шуудан буруу байна")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Э-Шуудан буруу байна")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Э-Шуудан буруу байна")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Э-Шуудан буруу байна")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Э-Шуудан буруу байна")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Э-Шуудан буруу байна")
		    return false
		 }

 		 return true					
	}

 
function checkPhone(phone){
	var lstr=phone.length
	if(lstr!=8){
		alert("Утасны дугаар буруу байна")
		return false;
	}
	if (isNaN(phone))
	{
		alert("Утасны дугаар буруу байна")
		return false;
	}
	if (!phone.startsWith('99')&&!phone.startsWith('95'))
	{
		alert("Утасны дугаар буруу байна")
		return false;
	}
	
	return true;
}



