
function check_register()
{	//alert(getEl('usrreg_email').value);
	//alert(getEl('usrreg_pass').value);
	//alert(getEl('usrreg_name').value);
	//alert(getEl('usrreg_surname').value);
	email=getEl('usrreg_email').value;
if (email == "") {
	getEl('inptErr3').innerHTML = "<div style=\"color:#f00\">Введите Email</div>";
	return false
	}
if (email.indexOf(".") == -1) {
	getEl('inptErr3').innerHTML = "<div style=\"color:#f00\">Нет символа\".\"</div>";
	return false
	}
dog = email.indexOf("@");
	if (dog == -1) {
	getEl('inptErr3').innerHTML = "<div style=\"color:#f00\">Нет символа\"@\"</div>";
	return false
	}
if ((dog < 1) || (dog > email.length - 5)) {
	getEl('inptErr3').innerHTML = "<div style=\"color:#f00\">Неверный Email</div>";
	return false
	}
if ((email.charAt(dog - 1) == '.') || (email.charAt(dog + 1) == '.')) {
	getEl('inptErr3').innerHTML = "<div style=\"color:#f00\">Неверный Email</div>";
	return false
	}
getEl('inptErr3').innerHTML = "<div style=\"color:#1DC2EF\">Ok!</div>";

pass=getEl('usrreg_pass').value;

if (pass.length < 6){	getEl('inptErr2').innerHTML = "<div style=\"color:#f00\">Короткий пароль</div>";
	return false
    }
getEl('inptErr2').innerHTML = "<div style=\"color:#1DC2EF\">Ok!</div>";

namereg=getEl('usrreg_name').value;

if (namereg.length < 1){
	getEl('inptErr4').innerHTML = "<div style=\"color:#f00\">Введите Имя</div>";
	return false
    }
getEl('inptErr4').innerHTML = "<div style=\"color:#1DC2EF\">Ok!</div>";

snamereg=getEl('usrreg_surname').value;

if (snamereg.length < 1){
	getEl('inptErr5').innerHTML = "<div style=\"color:#f00\">Введите Фам.</div>";
	return false
    }
getEl('inptErr5').innerHTML = "<div style=\"color:#1DC2EF\">Ok!</div>";

document.register.new_reg.value='register';
document.register.submit()
//alert("Адрес электронной почты был введен ВЕРНО!");
}


function auth_go(){document.auth.new_reg.value='auth';
document.auth.submit()}




function del(pid){
		//if(confirm('Do you really mean to delete this item')){
			document.form1.pid.value=pid;
			document.form1.command.value='delete';
			document.form1.submit();
		//}
	}
function clear_cart(){
		//if(confirm('This will empty your shopping cart, continue?')){
			document.form1.command.value='clear';
			document.form1.submit();
		//}
			//document.location='index.php?option=basket';
	}


function add_comment(pid){	var flag = 0;
			document.comments.command.value='addcomments';
			document.comments.pid.value=pid;
			if(document.getElementById('resp_name').value == ''){alert('Введите ваше имя!'); flag=1;}
			if(document.getElementById('resp_email').value == '') {alert('Введите ваш E-mail!'); flag=1;}
			if(document.getElementById('resp_resp').value == '') {alert('Введите ваш отзыв!'); flag=1;}
			if(flag == 0)
			{
			//document.comments.resp_name.value=document.getElementById('resp_name').value;
			//document.comments.resp_email.value=document.getElementById('resp_email').value;
			//document.comments.resp_resp.value=document.getElementById('resp_resp').value;
			document.comments.submit();
			}
	}


function GetAJAXObject()
{
    req=false;
    try
    {
        req=new ActiveXObject('Msxml2.XMLHTTP');
    }
    catch (e)
    {
		try
		{
            req=new ActiveXObject('Microsoft.XMLHTTP'); // сработает в Internet Explorer
		}
		catch (e)
		{
            if(window.XMLHttpRequest){ // сработает в Mozilla и Safari
               req=new XMLHttpRequest();
            }
        }
    }

    return req;
}
function DoAJAXLoad () {
    if (this.req){// если какой-то из вариантов поддерживается
	   //this.req.target = this.Target;
	   thedate = new Date();
	   //alert(thedate.getTime());
	   //this.AJAXReadyState.ttarget = this.Target;
	   this.req.onreadystatechange = this.Method;
       this.req.open("GET", this.ModuleFile+'?'+this.Query+'&uniq='+thedate.getTime(), true); // загружаем серверный скрипт
       this.req.send(null); //отсылаем запрос
    }
}

function AjaxRequest(req, url,  func)
{
	req.open("GET", url, true);
    //req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    req.setRequestHeader("Content-Type", "text/xml; charset=windows-1251");

	req.onreadystatechange = function()
	    {
    		if (req.readyState == 4) {
		    	var status = req.status;
		    	if (status == 200) {

				//alert(req.responseText);
				//alert(req.responseXML);

				func(req.responseText,req.responseXML);

		    	} else if (status == 400) {
		    		//alert('Wrong request!');
		    	} else if (status == 500) {
		    		alert('Server Error (500)'+url);
		    	} else if (status == 503) {
				var time = req.getResponseHeader('Retry-After')*1000;
				//alert('Сервер перегружен. Запрос будет повторен через: '+time+' секунд');
				//setTimeout(AjaxRequest(req,url,workfn),time);
		    	} //else {
		    	//	var er = 'Wrong server response - error '+status;
		    	//	alert(er);
		    	//}
		    }
	    }
	req.setRequestHeader("Content-Type", "text/xml");
	req.send(null);
}

function AjaxCreate()
{
	var req;
	if (window.XMLHttpRequest)      // normal browser
	{
	    req = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)      //IE
	{
	    try {
	        req = new ActiveXObject('Msxml2.XMLHTTP');
	    } catch (e){}
	    try {
	        req = new ActiveXObject('Microsoft.XMLHTTP');
	    } catch (e){}
	}

	return req;
}

function checkmail(txt, xml)
{
if(getEl('inptErr3')) {
	getEl('inptErr3').innerHTML = txt;
	}
}



function listUser(txt, xml)
{
if(getEl(curElid)) {	getEl(curElid).innerHTML = txt;
	getEl(curElid).style.display ='block';
	}
}


function list_pcateg(txt, xml)
{
if(getEl(curElid)) {
	getEl(curElid).innerHTML = txt;
	getEl('remove_' + id_pcateg).innerHTML = '<a href="javascript:remove_pcateg(' + id_pcateg + ');"><img src="content/img/remove.png"></a>';
	getEl(curElid).style.display ='block';
	}
}


var curElid;
var id_pcateg;


//возвращение данных по добавленному товару в корзину

function retupdate(txt, xml){
	getEl("div_quantity").innerHTML = txt;
}



function retaddcart(txt, xml)
{
	if(getEl(curElid))
	getEl(curElid).innerHTML = '<p style= "color: #1DC2EF; border-bottom: 1px dashed #1DC2EF; font: 18px Tahoma;">Добавлен!</p>';

	if(getEl('div_basket_low'))
	getEl('div_basket_low').innerHTML = '<p style= "color: #1DC2EF; border-bottom: 1px dashed #1DC2EF; font: 18px Tahoma;">Добавлен!</p>';


	if(getEl(curElid_cat))
	getEl(curElid_cat).innerHTML = '<p style= "color: #FFFFFF; border-bottom: 1px dashed #FFFFFF; font: 18px Tahoma;">Добавлен!</p>';


 	AjaxRequest2('http://mediagadget.ru/core.php?command=update_quantity', retupdate);
	//alert(txt);
}


function none_item_basket(txt, xml)
{if(getEl(curElid))
	getEl(curElid).style.display ='none';}


function addtocart(pid){	 curElid = "div_basket";	 curElid_cat = "div_basket_cat_" + pid;
	if(document.getElementById('num_it').value > 0)
		 ed = document.getElementById('num_it').value;
		 else  ed = 1; 	AjaxRequest2('http://mediagadget.ru/core.php?command=addtocar&id=' + pid + '&ed=' + ed, retaddcart);
	//alert(pid+ ' ' + ed);
	/*document.getElementById('div_basket').innerHTML = 'Добавлен!'; */
}


function deletes_item_basket(pid)
{	curElid = "itemb_" + pid;
 	AjaxRequest2('http://mediagadget.ru/core.php?command=deletes_item_basket&id=' + pid, none_item_basket);
 	AjaxRequest2('http://mediagadget.ru/core.php?command=update_quantity', retupdate);}


function retcheckapplication(txt, xml){
curElid = "blockone";
if(getEl(curElid)) getEl(curElid).style.display ='none';//innerHTML = '';

if(getEl('basket_basket')) getEl('basket_basket').innerHTML = '<div class="fr w730"><br><br><img src="http://mediagadget.ru/content/img/rt1.gif"><div class="bwhite"><p>Ваш заказ принят. В ближайшее время с Вами свяжется наш менеджер.</p></div><img src="http://mediagadget.ru/content/img/lt1.gif"></div>';

AjaxRequest2('http://mediagadget.ru/core.php?command=update_quantity', retupdate);

//alert();
}



function check_application()
{
namereg=getEl('app_name').value; //Имя юзера
if (namereg.length < 1){
	getEl('inptErr6').innerHTML = "<div style=\"color:#f00\">Введите Имя</div>";
	return;
    }
getEl('inptErr6').innerHTML = "<div style=\"color:#1DC2EF\"></div>";


snamereg=getEl('app_addr').value; //адресс

if (snamereg.length < 1){
	getEl('inptErr7').innerHTML = "<div style=\"color:#f00\">Введите ваш адрес.</div>";
	return;
    }
getEl('inptErr7').innerHTML = "<div style=\"color:#1DC2EF\"></div>";


	email=getEl('app_mail').value; //почта
if (email == "") {
	getEl('inptErr8').innerHTML = "<div style=\"color:#f00\">Введите Email</div>";
	return;
	}
if (email.indexOf(".") == -1) {
	getEl('inptErr8').innerHTML = "<div style=\"color:#f00\">Нет символа\".\"</div>";
	return;
	}
dog = email.indexOf("@");
	if (dog == -1) {
	getEl('inptErr8').innerHTML = "<div style=\"color:#f00\">Нет символа\"@\"</div>";
	return;
	}
if ((dog < 1) || (dog > email.length - 5)) {
	getEl('inptErr8').innerHTML = "<div style=\"color:#f00\">Неверный Email</div>";
	return;
	}
if ((email.charAt(dog - 1) == '.') || (email.charAt(dog + 1) == '.')) {
	getEl('inptErr8').innerHTML = "<div style=\"color:#f00\">Неверный Email</div>";
	return;
	}
getEl('inptErr8').innerHTML = "<div style=\"color:#1DC2EF\"></div>";


sphonereg=getEl('app_phone').value;  //телефон

if (sphonereg.length < 1){
	getEl('inptErr9').innerHTML = "<div style=\"color:#f00\">Введите ваш номер телефона.</div>";
	return false
    }
getEl('inptErr9').innerHTML = "<div style=\"color:#1DC2EF\"></div>";

metro=getEl('app_metro').value;  //метро
comment=getEl('app_comment').value;  //комент


	AjaxRequest2('http://mediagadget.ru/core.php?command=application&app_name='+namereg+'&app_phone='+sphonereg+'&app_addr='+snamereg+'&app_mail='+email+'&app_metro='+metro+'&app_comment='+comment+'&br='+navigator.appName, retcheckapplication);

//document.application.new_app.value='application';
//document.application.submit()
//alert("Адрес электронной почты был введен ВЕРНО!");


}















function remove_pcateg(el_id)
{
curElid = "pcateg_"+el_id;
if(getEl(curElid)) getEl(curElid).style.display ='none';
getEl('remove_' + el_id).innerHTML = '<a href="javascript:load_pcateg(' + el_id + ');"><img src="content/img/add.png"></a>';
}


function closes_reg(){curElid = "reg";
if(getEl(curElid)) getEl(curElid).style.display ='none';//innerHTML = '';
}
function closes_auth(){
curElid = "auth";
if(getEl(curElid)) getEl(curElid).style.display ='none';//innerHTML = '';
}



function registr() { curElid = "reg";
 getEl(curElid).style.display ='block';
}

function auth() {
 curElid = "auth";
 getEl(curElid).style.display ='block';
}


function check_email(){
	email=getEl('usrreg_email').value;
 	AjaxRequest2('functions.php?email='+email, checkmail);
}

function load_mess(el_id) {
 curElid = "div_"+el_id;
 AjaxRequest2('referrals_list.php?messid='+el_id, listUser);
}

function load_comment(el_id) {
 curElid = "div_"+el_id;
 AjaxRequest2('core.php?commid='+el_id, listUser);
}

function load_city(el_id){ curElid = "cityblock"; AjaxRequest2('core.php?coutryid='+el_id, listUser);
}

function load_platform(el_id) {
 curElid = "div_"+el_id;
 AjaxRequest2('core.php?id_plan='+el_id, listUser);
}
function check(h){	os=getEl(h);	curElid = "checkes";
	AjaxRequest2('core.php?checkes='+h, listUser);
}

function load_pcateg(el_id) {
 curElid = "pcateg_"+el_id;
 id_pcateg = el_id;
 AjaxRequest2('core.php?pcateg='+el_id, list_pcateg);
}

function getSS(p){
	o=getEl(p);
	if (!o.options) return "";
	var selectedOptions = [];
	for (var i = 0; i < o.options.length; i++) if (o.options[i].selected) selectedOptions.push(o.options[i].value);
	curElid = "categblock";
	AjaxRequest2('core.php?list_city='+selectedOptions.join(","), listUser);
}


function AjaxRequest2(url,  func)
{
	AjaxRequest(AjaxCreate(), url,  func);
}

function AjaxXmlRequest(xmlString,url,func)
{
	  xmlHttp = AjaxCreate();
	  xmlHttp.open("POST", url, true);
	  xmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

	  xmlHttp.onreadystatechange = function (){
    		if (xmlHttp.readyState == 4) {
		    	var status = xmlHttp.status;
		    	if (status == 200) {
		    		//alert('Successfully sent');
				func(xmlHttp.responseText,xmlHttp.responseXML);
		    	} else if (status == 400) {
		    		alert('Wrong request!');
		    	} else if (status == 500) {
		    		alert('Server Error (500)');
		    	} else if (status == 503) {
				alert('need to retry');
				//alert('Server is busy. Запрос будет повторен через: '+time+' секунд');
				//setTimeout(AjaxRequest(req,url,workfn),time);
		    	} else {
		    		var er = 'Wrong server response - error '+status;
		    		alert(er);
		    	}
		    }
	  }

	  xmlHttp.send(xmlString);
}

var ajaxQueue;


function getEl(id)
{
    return document.getElementById(id);
}

function _wGetTxt(obj)
{
	return (obj.textContent? obj.textContent : ( obj.firstChild.nodeValue ? obj.firstChild.nodeValue : obj.nodeValue ) );
}

function _wGetTxt(obj)
{
    if (obj != null)
	    return (obj.textContent? obj.textContent : ( obj.firstChild.nodeValue ? obj.firstChild.nodeValue : obj.nodeValue ) );
    else
        return '';
}

function _wGetAttr(el,attr)
{
	return el.getAttribute(attr);
}

function fake_func(text, xml)
{
}

function gexml(obj)
{
    if (obj != null)
	    return (obj.textContent? obj.textContent : ( obj.firstChild.nodeValue ? obj.firstChild.nodeValue : obj.nodeValue ) );
	else
	    return "";
}
