﻿function preload() {
	var a=preload.arguments;
	for(i=a.length-1;i>=0;i--)
	{
		(new Image).src=a[i];
	}
}

window.onload = function()
{
	preload('../images/point_up.gif', '../images/tab_up.gif', '../images/login_button_up.gif', '../images/header_menu_button_up.gif', '../images/order_up.gif', '../images/service_1_up.jpg', '../images/service_2_up.jpg', '../images/service_3_up.jpg', '../images/service_4_up.jpg', '../images/services5_up.jpg', '../images/service_6_up.jpg');
}

function swap(a,b) {
	//a=document.getElementById(a);
	if(b){document.c=a.src; a.src=b;}
	else a.src=document.c;
}

function more(id1,id2){
	document.getElementById(id1).style.display='block';
	document.getElementById(id2).style.display='none';
}
function more2(id1){
	var a=document.getElementById(id1);
	//alert(a.style.display);
	a.style.display=a.style.display=='block'?'none':'block';
}

var isIE=window.ActiveXObject?true:false;

function addFlash(path,w,h,id,alt)
{
	if(flashver<8)
	{
		code=alt;
	} else
	{
		var args=addFlash.arguments,p,pos;
		var code=isIE?'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" width="'+w+'" height="'+h+'" id="'+id+'"><param name="movie" value="'+path+'" />':'<object type="application/x-shockwave-flash" data="'+path+'" width="'+w+'" height="'+h+'" id="'+id+'">';
		for(var x=args.length-1;x>4;x--)
		{
			p=args[x];
			pos=p.indexOf('=');
			code+='<param name="'+p.substr(0,pos)+'" value="'+p.substr(pos+1)+'" />';
		}
		code+=(alt?alt:'')+'</object>';
	}
	document.write(code);
}

function getFlashVer()
{
	if(isIE)
	{
		try
		{
			var fl=new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
			fl.AllowScriptAccess = 'always';
			var ver=fl.GetVariable('$version');
			if(ver)
			{
				return ver.split(' ')[1].split(',')[0];
			}
		} catch(e)
		{
		}
	} else
	{
		if (x = navigator.plugins['Shockwave Flash'])
		{
			if (y = x.description)
			{
				var p=y.indexOf('.')-1;
				var ver = y.charAt(p);
				if(parseInt(y.charAt(p-1)))
				{
					ver+=parseInt(y.charAt(p-1))*10;
				}
				return ver;
			}
		}
	}
	return 0;
}
var flashver = getFlashVer();

var WARN_CLASS = new Array ('warn','none');
var c1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
var c2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");

String.prototype.trim = function()
{
	return this.replace(/^\s+/,'').replace(/\s+$/,'');
}

function checkValue(obj,warn)
{
	var v=obj.value.trim();
	if( obj.id == 'mail')
	{
		chk=!c1.test(v) && c2.test(v) && v.length>6;
	}else if(obj.id =='pwd2')
	{
		chk=document.getElementById('pwd').value==obj.value && obj.value.length>=3;
	} else
	{
		chk=v.length>0;
	}
	obj.className=WARN_CLASS[chk+0];
	if( warn && chk )
	{
		obj.onkeyup='';
		obj.onchange='checkValue(this)';
	} else if( !warn && !chk )
	{
		obj.onkeyup='checkValue(this,1)';
		obj.onchange='';
	}
	return chk;
}

function Logout()
{
	var http = (window.ActiveXObject) ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
		if(http)
		{
			http.onreadystatechange = function ()
			{
				if(http.readyState == 4)
				{
					if (http.status == 200)
					{
						if(document.getElementById('reg_warn'))
						{
							document.getElementById('login').style.display='block';
							document.getElementById('user').value='User name';
							document.getElementById('pass').value='Password';
							document.getElementById('reg_warn').innerHTML='<p>Not a user? <a href="register.php"> Register </a></p><a href="lost_pass.php"> Forgotten password</a>';
							document.getElementById('reg').style.display='none';
						}
					} else
					{
						if(document.getElementById('warn_user'))
							document.getElementById('warn_user').innerHTML='ERROR';
					}
				}
			};
			http.open('POST', 'login.php?ajax=1&logout=1', true);
			http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
			http.send(null);
		}
	return false;
}

function FormCheck(forma)
{
	if(!forma) forma=0;
	var f=document.forms[forma];
	var items=f.elements;
	var test=true,cnt=items.length,params='',AnD=false,i,t;
	for( var x=0; x<cnt; x++ )
	{
		t=(i=items[x]).type;
		if(i.id=='user' || i.id=='pass' || i.id=='firstname' || i.id=='lastname' || i.id=='phone' || i.id=='mail' || i.id=='user_name'  || i.id=='pwd' || i.id=='pwd2' || i.id=='city_name' || i.id=='street' || i.id=='name' || i.id=='message')
		{
			
			if(!checkValue(i) && test)
			{
				i.focus();
				test=false;
			} else if(test)
			{
				params=params+(AnD?'&':'')+i.id+'='+i.value;
				AnD=true;
			}
		}
		else
		{
			params=params+(AnD?'&':'')+i.id+'='+i.value;
			AnD=true;
		}
	}
	if(test)
	{
		var http = (window.ActiveXObject) ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
		if(http)
		{
			http.onreadystatechange = function ()
			{
				if(http.readyState == 4)
				{
					if (http.status == 200)
					{
						if(http.responseText!='0')
						{
							var results=http.responseText
							if(results=='Wrong password!')
							{
								if(document.getElementById('reg_warn'))
								{
									text = false;
									document.getElementById('reg_warn').innerHTML='<p>'+results+'<a href="lost_pass.php"> Forgotten password</a>'+'<a href="register.php">Register</a></p>';
									document.getElementById('reg').style.display='none';
									//document.getElementById('log_pic').style.display='block';
									//document.getElementById('warn_user').style.padding='0 10px';
									document.getElementById('user').value='Username';
									document.getElementById('pass').value='password';
								}
							}else if(results=='11')
							{
								text ='Thank you for your message';
									
							}
							else if(results=='12')
							{
								text ='Your password has been sent to your e-mail!';
									
							}
							else if(results=="This username doesn't exists")
							{
								text =results;
									
							}
							else
							{
								if(document.getElementById('reg_warn'))
								{
									text = false;
									document.getElementById('reg_warn').innerHTML=results;
									document.getElementById('login').style.display='none';
									document.getElementById('reg').style.display='none';
									/*document.getElementById('log_pic').style.display='block';
									document.getElementById('warn_user').style.padding='0 10px';*/
								}
							}
						} else
						{
							var text = '';
						}
					} else
					{
						var text='';
					}
					if(text!==false)
					{
						f.innerHTML=text;
					}
				}
			};
			var t=f.method=='post';
			
			http.open(f.method, f.action+'?ajax=1'+(t?'':params), true);
			if(t)
			{
				http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
				http.setRequestHeader('Content-length', params.length);
			}
			http.send(t?params:null);
		}
	}
	return false;
}
function RegCheck(forma)
{
	if(!forma) forma=0;
	var f=document.forms[forma];
	//alert(window.location.pathname);
	var items=f.elements;
	var test=true,cnt=items.length,params='',AnD=false,i,t;
	for( var x=0; x<cnt; x++ )
	{
		t=(i=items[x]).type;
		if(i.id=='usera' || i.id=='passa' || i.id=='firstname' || i.id=='lastname' || i.id=='phone' || i.id=='mail' || i.id=='user_name'  || i.id=='pwd' || i.id=='pwd2' || i.id=='city_name' || i.id=='street')
		{
			
			if(!checkValue(i) && test)
			{
				i.focus();
				test=false;
			} else if(test)
			{
				params=params+(AnD?'&':'')+i.id+'='+i.value;
				AnD=true;
			}
		}
		else
		{
			params=params+(AnD?'&':'')+i.id+'='+i.value;
			AnD=true;
		}
	}
	if(!test)
	return false;
}

function checkName(obj, warn)
{
	var param='&name='+obj.value;
	var http = (window.ActiveXObject) ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
	if(http)
	{
		http.onreadystatechange = function ()
		{
			if(http.readyState == 4)
			{
				var obj=document.getElementById('results');
				
				if (http.status == 200)
				{
					var results=http.responseText
					if(http.responseText!='')
					{
						if(document.getElementById('warn_user_2'))
							document.getElementById('warn_user_2').innerHTML='<span class="warn">'+results+'</span>';
					} else
					{
						if(document.getElementById('warn_user_2'))
							document.getElementById('warn_user_2').innerHTML='';
					}
				} else
				{
					if(document.getElementById('warn_user_2'))
						document.getElementById('warn_user_2').innerHTML='ERROR';
				}
			}
		};
		
		http.open('POST', 'confirm.php'+'?ajax=1'+param, true);
		http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		http.setRequestHeader('Content-length', param.length);
		http.send(param);
	}
}

function clears(a)
{

	document.getElementById('user').value='';
}

function clearp(a)
{

	document.getElementById('pass').value='';
}
function cleara(a)
{

	document.getElementById('usera').value='';
}

function change_service(ch)
{
	var first=window.location.toString();
	var pos=(first.indexOf('php'));
	if(pos>0)
	{
		if(ch.value=='1' || ch.value=='2' || ch.value=='3')
		{
			first='http://pcfixteam.com/request_service.php?plan=1&s_id='+ch.value;
		}else
			first='http://pcfixteam.com/request_service.php?s_id='+ch.value;
	}
	window.location=first;

}

function check_word()
{
	a=document.getElementById('user').value;
	if(a.length<1|| a=='User name')
	{
		document.getElementById('user').value='User name';

		return false;
	}else
	{
		return true;
	}
}

function check_pasa()
{
	a=document.getElementById('pass').value;
	if(a.length<1)
	{
		document.getElementById('pass').value='password';

		return false;
	}else
	{
		return true;
	}
}