// JavaScript Document
function isIMEI (s)
{
    var etal = /^[0-9]{15}$/;

	if (!etal.test(s))
        return false; 
    sum = 0; mul = 2; l = 14;
    for (i = 0; i < l; i++)
	{
    	
        digit = s.substring(l-i-1,l-i);
        tp = parseInt(digit,10)*mul;
        if (tp >= 10)
            sum += (tp % 10) +1;
        else
            sum += tp;
        if (mul == 1)
            mul++;
        else
            mul--;
    }
    chk = ((10 - (sum % 10)) % 10);
    if (chk != parseInt(s.substring(14,15),10))
        return false;
    return true;
}

function get_page_size()
{
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) 
	{	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight)
	{ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else 
	{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) 
	{	// all except Explorer
		if(document.documentElement.clientWidth)
		{
			windowWidth = document.documentElement.clientWidth; 
		} else 
		{
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) 
	{ // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) 
	{ // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight)
	{
		pageHeight = windowHeight;
	} else 
	{ 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth)
	{	
		pageWidth = xScroll;		
	} else 
	{
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}

function get_scroll()
{
	var t, l, w, h;
	if (document.documentElement && document.documentElement.scrollTop) 
	{
		t = document.documentElement.scrollTop;
		l = document.documentElement.scrollLeft;
		w = document.documentElement.scrollWidth;
		h = document.documentElement.scrollHeight;
	} 
	else if (document.body) 
	{
		t = document.body.scrollTop;
		l = document.body.scrollLeft;
		w = document.body.scrollWidth;
		h = document.body.scrollHeight;
	}
	return { t: t, l: l, w: w, h: h };
}
function setCookie(name,value,Days)
{
    var exp  = new Date();    //new Date("December 31, 9998");
	exp.setTime(exp.getTime() + Days*24*60*60*1000);
	document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)
{
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
	if(arr=document.cookie.match(reg)) return unescape(arr[2]);
	else return null;
}
function delCookie(name)
{
    var exp = new Date();
	exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
	if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}

function check_all(n)
{
	var el = document.getElementsByName(n);
	for(var i = 0; i < el.length; i++)
	{
		el[i].checked = true;
	}
}

function check_none(n)
{
	var el = document.getElementsByName(n);
	for(var i = 0; i < el.length; i++)
	{
		el[i].checked = false;
	}
}

function check_reverse(n)
{
	var el = document.getElementsByName(n);
	for(var i = 0; i < el.length; i++)
	{
		el[i].checked = el[i].checked ? false : true;
	}
}
function select_radio(n)
{
	var el = document.getElementsByName(n);
	for(var i = 0; i < el.length; i++)
	{
		if(el[i].checked == true)
		{
			return el[i].value;
		}
	}
	return false;
}
function iconfirm(a, t)
{
	if(confirm(a))
	{
		location.href = t;
		return true;	
	}
	return false;
}
