var pop1_opened = false;
var pop1;
function popup(text,title)
{
	if(pop1_opened)
	{
		pop1.close();
	}
	pop1=window.open('','pop','width=250,height=250,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes');
	pop1_opened=true;
	html ='<html>';
	html+='	<header>';
	html+='		<title>'+title+'</title>';
	html+='	</header>';
	html+='	<body>';
	html+='		<div>'+text+'</div>';
	html+='<br/>';
	html+='		<div align="center"><a href="javascript:;" onClick="opener.pop1_opened=false;window.close()">close</a></div>';
	html+='	</body>';
	html+='</html>';
	pop1.document.write(html);
}

function popupPic(picURL)
{ 
	window.open( "scripts/pop.htm?"+picURL, "","scrollbars=yes, resizable=0, status=0,left=0, top=0,HEIGHT=200,WIDTH=200"); 				
}

function switchText(obj, e, title)
{
	if(e=='focus')
	{
		if(obj.value == title)
		{
			obj.value = '';								
		}
	}
	else
	{
		if(obj.value == '')
		{
			obj.value = title;								
		}		
	}		
}

function searchSwitch(obj, e, title)
{
	if(e=='focus')
	{
		if(obj.value == title)
		{
			obj.value = '';								
		}
	}
	else
	{
		if(obj.value == '')
		{
			obj.value = title;								
		}		
	}		
}	

function on_search(formObj, elmId, title)
{
	var f=formObj;
	var val=document.getElementById(elmId).value;
	if(trim(val) == '' || val == title)
		return false;	
	var url=f.action+val+'/';
	window.location=url;
	return false;
}

function do_search(subm_id)
{		
	document.getElementById(subm_id).click();
}

function subscribeSwitch(obj, e, title)
{
	if(e=='focus')
	{
		if(obj.value == title)
		{
			obj.value = '';								
		}
	}
	else
	{
		if(obj.value == '')
		{
			obj.value = title;								
		}		
	}		
}

function do_subscribe()
{		
	document.getElementById('subscribe_submit').click();
}

function on_subscribe(elmId, lang, title)
{
	var val = document.getElementById(elmId).value;	
	if(trim(val) == '' || val == title)
	{
		return false;
	}
	
	var url = '?/'+lang+'/subscribe/add/' +  trim(val);	
	window.open(url , '', 'directories=no, height=180, width=350, left=200, top=200, location=no, menubar=no, resize=no, scrollbars=no, status=no, toolbar=no');	
	
	return false;
}

Math.roundf = function(val, precision)
{
	var p = this.pow(10, precision);
	return this.round(val * p) / p;
}

Math.roundup = function(val, precision)
{
	var p = this.pow(10, precision);
	return this.ceil(val * p) / p;
}

find = function(arr, searchStr)
{
	var returnArray = false;
	for (i=0; i<arr.length; i++)
	{
		if (typeof(searchStr) == 'function')
		{
			if (searchStr.test(arr[i]))
			{
				if (!returnArray)
				{
					returnArray = []
				}
				returnArray.push(i);
			}
		}
		else
		{
			if (arr[i]==searchStr)
			{
				if (!returnArray) { returnArray = [] }
					returnArray.push(i);
			}
    	}
  	}
	return returnArray;
}

search_array = function(arr, searchStr)
{
	var returnArray = false;
	for (var i=0; i<arr.length; i++)
	{
		var elm = arr[i];
		if(typeof(searchStr) == 'object' && typeof(elm) == 'object' && elm.length == searchStr.length)
		{
			var f = true;
			if(elm.length<1)
				f = false;
			for (var j=0; j<elm.length; j++)
			{
				if (elm[j]!==searchStr[j])
				{
					f = false;
				}   
			}
			if(f)
			{
				if (!returnArray) { returnArray = [] }
						returnArray.push(i);
			}		
		}
		else if (elm===searchStr)
		{
			if (!returnArray) { returnArray = [] }
				returnArray.push(i);
		}   
	}
	return returnArray;
}


function trim(inputString)
{
	if (typeof inputString != "string")
		return inputString;
	var retValue = inputString;
	var ch = retValue.substring(0, 1);	
	while (ch == " ")
	{ 
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	ch = retValue.substring(retValue.length - 1, retValue.length);
	
	while (ch == " ")
	{ 
		retValue = retValue.substring(0, retValue.length - 1);
		ch = retValue.substring(retValue.length - 1, retValue.length);
	}
	
	while (retValue.indexOf("  ") != -1)
	{
		retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ") + 1, retValue.length);
	}
	return retValue; 
}
/*  checks the validity of an email address entered 
	*   returns true or false 
	*/ 
function validateEmail(email)
{
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
	return false;
}

function TestInputType(objValue,strRegExp)
{
	var ret = false;
	//alert("1");
	
	var charpos = objValue.search(strRegExp); 
	if(objValue.length > 0 &&  charpos >= 0) 
	{
		//alert("1");
		ret = true; 
	}
	return ret;
}
function addFavorite()
{
	if(document.all) 
		window.external.AddFavorite(document.location.href,document.title);
}
function switchDate(d,m,y,lang,module,params,all)
{
	if(d<1) d=0;
	if(m<1) m=0;
	if(y<1) y=0;
	var date = d+"."+m+"."+y;
	
	var url = "?/"+lang+"/"+module;
	for(i=0; i<params.length; i++)
	{
		url += "/"+	params[i];
	}
	if(!all)
		url += "/"+	date;
	
	window.location=url;	
}

function isNumberKey(evt)
{
	var charCode = (document.all) ? event.keyCode :  evt.which;
	if((charCode > 31 
			&& (charCode < 48 || charCode > 57)
			|| charCode==46)
	 	&& charCode!=40 && charCode!=41 && charCode!=45 &&  charCode!=43&&  charCode!=46)
		return false;
	return true;
}

function getDaysInMonth(year, month)
{
	var startDate = new Date(year, month+1, 1);
	timeDifference = startDate - 86400000;
	var result = new Date(timeDifference);
	return result.getDate();
}

function daysInMonth(iMonth, iYear)
{
	return 32 - new Date(iYear, iMonth, 32).getDate();
}

function pause(numberMillis)
{
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true)
	{
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}	
}

function sleep(numberMillis)
{
	return pause(numberMillis);
}


/**********************************NEW********************************/
function getRef(id)
{
	return document.getElementById(id);
}

function validateLogin()
{
	if (getRef("email").value != "" && getRef("password").value != "")
	{	
		if(validateEmail(getRef("email").value))
			return true;
	}
	return false;
}

function validateForgot()
{
	if (getRef("email").value != "" )
	{
		if(validateEmail(getRef("email").value))
			return true;
	}
	return false;
}

function checkAlll(name, elm)
{
	var chk = elm.checked;
	
	var elts = document.getElementsByName(name);
	for (var i=0; i<elts.length; i++) 
    {
		elts[i].checked = chk;
    }
}

function changeCheckbox(mainid, obj)
{	
	if(getRef(mainid).checked)
	{
		if(!obj.checked)
		{
			getRef(mainid).checked = false;
		}
	}
}

function loadURL(url)
{
	location.href = url;
}

function doAction(frmId, chkName, lg, action, chkOne, del)
{	
	if(chkOne!=2)
	{
		var s=0;			  
		
		var elts = document.getElementsByName(chkName);
		for (var i=0; i<elts.length; i++) 
	    {
			if(elts[i].checked)
			{
				ids += elts[i].value+','; 
				s++;
			}
	    }
	    
	    if(s==0)
	    {	
	    	alert(lg['one']);
	    	return;
	    }
	    
	    if(chkOne==1 && s!=1)
	    {
	      	alert(lg['onlyone']);
	      	return;
	    }
	    
	    if(del)
		{
			if(!confirm(lg['confirm']))return;
		}
	}
	else if(del)
	{
		if(!confirm(lg['confirm']))return;
	}
			
	var frm = getRef(frmId);
	
	var newdiv = document.createElement('div');
	newdiv.innerHTML = '<input type="hidden" name="action" value="'+action+'">';
	frm.appendChild(newdiv);
    
	frm.submit();
}	

if (!Array.prototype.indexOf) Array.prototype.indexOf = function(item, i) {
  i || (i = 0);
  var length = this.length;
  if (i < 0) i = length + i;
  for (; i < length; i++)
    if (this[i] === item) return i;
  return -1;
};



