function isValidDate(s)
{
	var myReg = /^\d{2}\.\d{2}\.\d{4}$/;
	if(!s.match(myReg))
		return false;
	else
		return true ;
}

function isFloat(s)
{
	if(!s.match(/^\d{0,10}[,|\.]{0,1}\d{0,2}$/))
		return false;
	else
		return true ;
}

function isNumber(s)
{
  if(s.match(/^\d{0,10}$/) && s <= 2147483647)
  	return true;
  else
  	return false ;
}

function isBlank(s)
{
	for(var i=0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if((c!=' ')&&(c!="\n")&&(c!="\t"))
		return false;
	}
	return true;
}

function isValidString(str)
{
  var ret = true;
  var illChars = ['\\','"',"'"];
  for (i in illChars)
  {
    if(str.indexOf(illChars[i]) >= 0)
    {
      ret = false;
      break;
    }
  }
  return ret;
}

function spWin(win_nm,nm,w,h)
{
  var hs=screen.height; hs=hs-80;
  var ws=screen.width; ws=ws-10;
  if(h>hs) h = hs ;
  if(w>ws) w = ws ;
  var myfeatures = 'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,resizable=yes,scrollbars=yes,width='+w+',height='+h+',left=0,top=0';
  var newImg = open(win_nm,nm,myfeatures);
  newImg.focus();
}

function spWinWithoutResize(win_nm,nm,w,h)
{
  var hs=screen.height; hs=hs-80;
  var ws=screen.width; ws=ws-10;
  if(h>hs) h = hs ;
  if(w>ws) w = ws ;
  var myfeatures = 'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,resizable=no,scrollbars=yes,width='+w+',height='+h+',left=0,top=0';
  var newImg = open(win_nm,nm,myfeatures);
  newImg.focus();
}

function openWin(win_nm,nm)
{
  var h=screen.height;
  h=h-80;

  var myfeatures = 'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,resizable=yes,scrollbars=yes,width=650,height=550,left=0,top=0';

  var newImg = open(win_nm,nm,myfeatures);
  newImg.focus();
}

function checkDelete(src,langNameAlert)
{
  var conString = msgDelConfirm +" "+ langNameAlert;

  if(eval(confirm(conString)))
    window.location.replace(src);
}
function smallWin(win_nm,nm)
{
  var h=screen.height;
  h=h-80;

  var myfeatures = 'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,resizable=yes,scrollbars=yes,width=500,height=220,left=0,top=0';

  var newImg = open(win_nm,nm,myfeatures);
  newImg.focus();
}

function confirmDel(ref)
{
  if(eval(confirm(msgDelConfirm)))
    window.location.replace(ref);
  return;
}

function submitf(ref,id,id_ri)
{
  document.sform.id_rc.value=id;
  document.sform.id_ri.value=id_ri;
  document.sform.action = ref;
  document.sform.submit();
}

function validString(s)
{
  if((s.match(/^[\'&#\/,.a-zA-Z0-9 !@\?åÅäÄöÖ\n\r\f-]*$/) || s==""))
    return true;
  else
    return false ;
}

function delAttach(id)
{
	if(eval(confirm(msgDelConfirm)))
	{
		document.dform.id_attach.value=id;
		document.dform.submit();
	}
}

function getLength(s)
{
  return s.length ;
}

function checkData(str, max)
{
	if( getLength(s) > 0 && getLength(s) <= max)
	{
		return true ;
	}
	else if( getLength(s) > max)
	{
    alert(msgMaxCharExceeded);
    return false ;
	}
	return true ;
}

function spDelete(loc)
{
  if(eval(confirm(msgDelConfirm)))
  {
    document.location.href=loc;
    return true;
	}
}

function spOld(loc)
{
	if(eval(confirm(msgOldConfirm)))
	{
		document.location.href=loc;
		return true;
	}
}

function spActive(loc)
{
	if(eval(confirm(msgActiveConfirm)))
	{
		document.location.href=loc;
		return true;
	}
}

function isValidChar(s)
{
	if(!validString(s))
	{
		alert(msgValidCharAllowed);
		return false ;
	}
	else
	  return true ;
 }

function groupOfUrlFun(formName,category,winWidth,winHeight)
{
  cform = document.forms[formName] ;
  val = cform.groupOfUrl.checked ;
  if(val)
  {
  	spWin("addGroupUrl.php?category="+category,"myinyt",winWidth,winHeight);
  }
}
function groupofDocumentFun(formName,category,winWidth,winHeight)
{
	cform = document.forms[formName] ;
	val = cform.groupOfDocument.checked ;
  if(val)
  {
  	spWin("addGroupDocument.php?category="+category,"myinyt",winWidth,winHeight);
	}
}
function submitPageForLinkDocAndUrl(formNameForLink,item,winW,winH)
{
	cform = document.forms[formNameForLink];
	cform.linkToAdd.value=item;
	cform.winWidth.value=winW;
	cform.winHeight.value=winH;
	cform.submit();
}
function canclePageRedirect(formName)
{
	cform = document.forms[formName] ;
	val = cform.phpName.value;
	window.location = val;

}

function isEmailValid(email)
{

  var ok = true;
  if (!(/^.+@.+\..{2,3}$/.test(email)))
  {
    ok = false;
  }
 	if (email.match(/[\(\)\<\>\,\;\:\\\/\?\*\!\¤\%\&\$\#\"\[\]\|]/))
 	{
    ok = false;
  }
  return ok;
}

function isTimeValid(time)
{
  var ok = true;
  if(!(/^[0-2][0-9]:[0-5][0-9]$/.test(time)))
  {
    ok = false;
  }
  return ok;
}

function urlValid(curl)
{
  var ok = true;

  if(!(/^.*\.(.*)\..{2,3}$/.test(curl)))
    ok = false;
  return ok;
}

function checkDeleteWithScroll(src,langNameAlert,ev)
{
	conString = msgDelConfirm +" "+ langNameAlert;
	if(eval(confirm(conString)))
	{
		window.location.replace(src);
	}
}

function DoNav(theUrl,a,b,wid,hei,del,event)
{
	atest=b;
	alignment = 'height='+hei+',width='+wid+'resizable=yes,scrollbars=yes';
	if(!apr && !del)
	{
		if(b=='td')
		{
			from='a';
			document.location.href = theUrl;
		}
		else
			window.open(theUrl,'',alignment);
	}
	apr='a';

	if(del == 'delete')
	{
		checkDeleteWithScroll(theUrl,'?',event)
		apr='a';
	}
}

function func1()
{
	if(!from)
	{
		if(atest == 'lnk')
			apr = '';
	}
}

function isPosNumber(s)
{
	if(s < 0)
		return true;
	else
		return false;
}

function goToDel()
{
  langNameAlert = "?";
  conString = msgDelConfirm +" "+ langNameAlert;

  if(eval(confirm(conString)))
  {
    return true;
  }
  return false;
}

function noDelete(src,name)
{
  alert(msgNoDelete+" "+name);
  window.location.replace(src);
}

function detectKey(e)
{
	var key;
	if(window.event)
		key=event.keyCode;
	else
		key=e.which;
	return key;
}

function createXml()
{
  var xmlhttp;
	if(navigator.appName.indexOf("Microsoft") == 0)
		xmlhttp = new ActiveXObject('microsoft.xmlhttp');
	else
		xmlhttp = new XMLHttpRequest();
	return xmlhttp;
}

function callAjax(xmlhttp,reqFile,eleName,divName,funcName,reqMethod,postParam)
{
  var reqMethod;

  if(!reqMethod)
    reqMethod = 'get';

	var rand = new Date().getTime();
	var param = unescape(reqFile).substring(1).split("?");

  if(reqMethod != 'posst')
  {
  	if(param.length > 1)
  		reqFile += "&rand="+rand;
  	else
  		reqFile += "?rand="+rand;
  }

	xmlhttp.open(reqMethod,reqFile,'true');

	if(reqMethod == 'post')
	{
	  xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.setRequestHeader("Content-length", postParam.length);
    xmlhttp.setRequestHeader("Connection", "close");
	}

  if(!funcName)
  {
    xmlhttp.onreadystatechange = function()
  	{
  	  if(xmlhttp.readyState == 4)
      {
  		  if(xmlhttp.status == 200)
  			{
    		  var resText = xmlhttp.responseText;
    			if(eleName)
    			{
    			  document.getElementById(eleName).value = '';
    				document.getElementById(eleName).value = resText;
    		  }
  				else if(divName)
  				{
  				  document.getElementById(divName).innerHTML= resText;
  				}
  			}
  		}
  	}
  }
  else
  {
    xmlhttp.onreadystatechange = eval(funcName);
  }

  if(reqMethod == 'post')
    xmlhttp.send(postParam);
  else
    xmlhttp.send(null);
}



function callAjaxMultiResponse(xmlhttp,reqFile,eleName,divName,funcName)
{
	var rand = new Date().getTime();
	var param = unescape(reqFile).substring(1).split("?");
	if(param.length > 1)
		reqFile += "&rand="+rand;
	else
		reqFile += "?rand="+rand;
	xmlhttp.open('get',reqFile,'true');
  var responseDivision = divName.split('|');
  if(!funcName)
  {
  	  xmlhttp.onreadystatechange = function(){
  		if(xmlhttp.readyState == 4)
  		{
  			if(xmlhttp.status == 200)
  			{
  				//alert(xmlhttp.responseText);
  				var resText = xmlhttp.responseText;
  				if(eleName)
  				{
  					document.getElementById(eleName).value = '';
  					document.getElementById(eleName).value = resText;
  				}
  				else if(divName)
  				{
					var responseObj = resText.split("|||||||");
  					document.getElementById(responseDivision[0]).innerHTML = responseObj[0];
					if( responseObj[1] && responseDivision[1]){
						$("#listRecipents").hide();
	  					document.getElementById(responseDivision[1]).innerHTML= responseObj[1];
					}else if(responseDivision[1]){
						document.getElementById(responseDivision[1]).innerHTML= "";
						$("#listRecipents").hide();
					}

  				}
  			}
  		}
  	}
  }
  else
  {  
    xmlhttp.onreadystatechange = eval(funcName);
  }  
    	
	xmlhttp.send(null);
}

