function stopError() { return true;}
window.onerror = stopError;

var myRemote;
window.onunload=CloseRemote;

function CloseRemote()
{
	if (myRemote!=null) myRemote.close();
}

function ns_ShowWindowEx(i,newURL,x,y,w,h) {
	var NS6 = (navigator.vendor == ("Netscape6") || navigator.product == ("Gecko"));
	if (!NS6)
	{
		IE = (document.all) ? true : false;
		NS4 = (document.layers) ? true : false;
	}
	else
	{
		IE = false;
		NS4 = false;
	}
	
	if(NS4)
	{
		if (myRemote==null) {
			  myRemote = window.open(newURL, '', 'height='+h+',width='+w+',screenX='+x+',left='+x+',screenY='+y+',top='+y+',channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0', 'myWindow');
			  myRemote.focus();
		}
		else{
			if(!myRemote.closed)	// Mora zaradi Netscape oti ako myRemote e zatvoren od strana na korisnikot puka
			{
				myRemote.close();
			}
			
			myRemote = window.open(newURL, '', 'height='+h+',width='+w+',screenX='+x+',left='+x+',screenY='+y+',top='+y+',channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0', 'myWindow');
			myRemote.focus();
		}	
	}
	else
	{
		if (myRemote==null) {
			  myRemote = window.open(newURL, '', 'height='+h+',width='+w+',screenX='+x+',left='+x+',screenY='+y+',top='+y+',channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0', 'myWindow');
			  myRemote.focus();
		}
		else{
			if(!myRemote.closed)	// Mora zaradi Netscape oti ako myRemote e zatvoren od strana na korisnikot puka
			{
				myRemote.close();
			}
			
			myRemote=null;
			myRemote = window.open(newURL, '', 'height='+h+',width='+w+',screenX='+x+',left='+x+',screenY='+y+',top='+y+',channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0', 'myWindow');
			myRemote.focus();
		}	
	}
}



function dummy(){
}

//Funkciite isDomestic() i isInRange() ovozmozuvaat da se opredeli
//dali korisnikot surfa od doma ili od nadvor

function isDomestic(clientIP)
{
            var Client = clientIP;

            //ova sme nie
            if(isInRange(Client,'85.30.96.120','85.30.96.121'))
                        return true;

            //onnet
            if(isInRange(Client,'217.16.64.0','217.16.95.255'))
                        return true;
            if(isInRange(Client,'85.30.64.0','85.30.127.255'))
                        return true;                                                        

            // mtnet
            if(isInRange(Client,'62.162.0.0','62.162.255.255'))
                        return true;                                                        
            if(isInRange(Client,'195.26.128.0','195.26.159.255'))
                        return true;                                                                                                                    
            if(isInRange(Client,'62.220.192.0','62.220.223.255'))
                        return true;        
                                                            

            //marnet
            if(isInRange(Client,'194.149.158.0','194.149.159.255'))
                        return true;                                                                    
                                                            
            //Sonet
            if(isInRange(Client,'212.120.0.0','212.120.31.255'))
                        return true;                                                                                                                                
                                                            
            //unet
            if(isInRange(Client,'212.13.64.0','212.13.95.255'))
                        return true;                                                                                                                                                        
                                                            
            //neotel
            if(isInRange(Client,'80.77.144.0','80.77.159.255'))
                        return true;                                                                                                                                                        
                                                            
            //mol
            if(isInRange(Client,'212.110.64.0','212.110.95.255'))
                        return true;                                                                                                                                                        
            //Kadis
            if(isInRange(Client,'82.114.75.0','82.114.75.255'))
                        return true;                                                                                                                                                        
                                                            
            if(isInRange(Client,'82.114.78.0','82.114.78.255'))
                        return true;                                                                                                                                                        
                                                            
            return false
}
                        
function isInRange(Client,StartIP,EndIP)
{
            var IPQuadClientIP;
            var IPQuadStartIP;
            var IPQuadEndIP;
                                                
            IPQuadClientIP = Client.split(".");
            IPQuadStartIP = StartIP.split(".");
            IPQuadEndIP = EndIP.split(".");
                                                
            if(IPQuadClientIP[0]==IPQuadStartIP[0] && IPQuadClientIP[1]==IPQuadStartIP[1])
            {
                        if(IPQuadClientIP[2]>=IPQuadStartIP[2] && IPQuadClientIP[2] <= IPQuadEndIP[2])
                        {
                                    if(IPQuadClientIP[3]>= IPQuadStartIP[3] && IPQuadClientIP[3]<= IPQuadEndIP[3])
                                    {
                                                return true;
                                    }
                        }
            }
            return false;
}





function isValidEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
	return false;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
	return false;
    }
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}