// JavaScript Document
function showfile() {
var pathname = location.pathname;
var filename =pathname.substr(pathname.lastIndexOf("/")+1,pathname.length);
return (filename);
}
//alert(showfile());
if(!getCookie("___usersessid") && showfile()=="edit-profile.php")
{
	//alert(geterrmsg('e15'));
	document.location="login.php";
}
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

/********************************************************************************/
function getHTTPObject()
	{
	  try
	   {
	    req = new XMLHttpRequest();
	    }
	  catch (err1)
	   { 
		 try
		  { 
		   req = new ActiveXObject("Msxml12.XMLHTTP"); 
		  }
		 catch(err2) 
		 {
		  try
		   { 
		   req = new ActiveXObject("Microsoft.XMLHTTP");
		   } 
		  catch (err3)
		  {
		   req = false;
		  }
		 }
		} 
	return req;
	}
var http=getHTTPObject();
var st=0;
function emailexist(obj)
{
	if(trim(obj.value)!="")
	{
		document.getElementById("errorId").style.height="0px";
		var str=obj.value;
		var url="emailexist.php";
		url=url+"?email="+str;
		url=url+"&sid="+Math.random();
		http.open("GET",url,false);
		http.send(null);
		if(http.responseText!="0")
		{
			return true;
		}
		else
		{
			return false;
		}

	}
	return false;
}



function submit_Val(formobj)
{
	document.getElementById("processsubmit").innerHTML='<img src="./images/loading.gif" alt="Processing" class="flotleft" style="margin-left:20px;" border="0"/>';
	if(userdet_validate(formobj))
	formobj.submit();
	else
	{
		document.getElementById("processsubmit").innerHTML='<input class="submit-button" id="dnldsubmit" name="dnldsubmit" type="submit" value=""/>';
		return false;
	}
}

function submit_Val2(formobj)
{
	if(userdet_validate2(formobj))
	formobj.submit();
	else
	return false
}

function submitVal(formobj)
{
	formobj.submit();
}

function loginVal(formobj)
{
	if(formobj.email.value=="" || !emailValidate(formobj.email.value) || formobj.passwd.value=="")
	{
		document.getElementById("loginerrorId").style.paddingBottom="15px";
		document.getElementById("loginerrorId").style.height="auto";
		document.getElementById("loginerrorId").innerHTML='<div class="listlogin"><img src="./images/icon_critalert.gif" alt="icon_crit" class="flotleft" border="0"/><div class="flotleft padtop10"> Invalid Email Id or Password </div></div>';
		return false;
	}
	formobj.submit();
}

function forgotVal(formobj)
{
	var errStr="";
	if(formobj.email.value=="")
	{
		errStr+="<li>"+geterrmsg('e9')+"</li>";;
	}
	else if(!emailValidate(formobj.email.value))
	{
		errStr+="<li>"+geterrmsg('e10')+"</li>";;
	}
	if(errStr!="")
	{
		document.getElementById("errorId").style.height="auto";
		document.getElementById("errorId").innerHTML='<div class="padtop10"><div class="listforgot"><img src="./images/icon_critalert.gif" alt="icon_crit" class="flotleft" border="0"/><div class="flotleft padtop10"><ul>'+errStr+'</ul></div></div></div>';
		return false;
	}
	formobj.submit();
}

function autocomplete() 
{
if (document.getElementsByTagName("input")) 
	{
	var inputElements = document.getElementsByTagName("input");
	for (i=0; inputElements[i]; i++) 
		{
		inputElements[i].setAttribute("autocomplete","off");
		}
	}
} 


function downld(filepath)
{
	document.location="download.php?dwnloadfile=/"+filepath;
}


function sleepfun(sec)
{
	alert(sec);
	setTimeout("sleepfun()",sec);
}

function trim(str)// We don't want to trip JUST spaces, but also tabs,line feeds, etc.  Add anything else you want to "trim" here in Whitespace
{
  return RTrim(LTrim(str));
}
function RTrim(str)
{  
  var whitespace = new String(" \t\n\r");
  var s = new String(str);
  if (whitespace.indexOf(s.charAt(s.length-1)) != -1) // We have a string with trailing blank(s)...
  {       
        var i = s.length - 1; // Get length of string        
        while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)// Iterate from the far right of string until we don't have any more whitespace...
          i--;        
        s = s.substring(0, i+1);// Get the substring from the front of the string to where the last non-whitespace character is...
   }
  return s;
}
function LTrim(str)
{
  var whitespace = new String(" \t\n\r");
  var s = new String(str);
  if (whitespace.indexOf(s.charAt(0)) != -1) // We have a string with leading blank(s)...
  {        
        var j=0, i = s.length;        
        while (j < i && whitespace.indexOf(s.charAt(j)) != -1)// Iterate from the far left of string until we don't have any more whitespace...
            j++;        
        s = s.substring(j, i);// Get the substring from the first non-whitespace character to the end of the string...
  }
  return s;
}


function userdet_validate2(formobj)
{
	var errStr="";
	if(formobj.firstname.value=="")
	{
		errStr+="<li>"+geterrmsg('e1')+"</li>";;
	}
	else if(!nameValidate(formobj.firstname.value))
	{
		errStr+="<li>"+geterrmsg('e2')+"</li>";;
	}
	if(formobj.lastname.value=="")
	{
		errStr+="<li>"+geterrmsg('e3')+"</li>";;
	}
	else if(!nameValidate(formobj.lastname.value))
	{
		errStr+="<li>"+geterrmsg('e4')+"</li>";;
	}
	if(formobj.organisation.value=="")
	{
		errStr+="<li>"+geterrmsg('e5')+"</li>";;
	}
	else if(!textValidate(formobj.organisation.value))
	{
		errStr+="<li>"+geterrmsg('e6')+"</li>";;
	}
	if(formobj.role.value=="")
	{
		errStr+="<li>"+geterrmsg('e7')+"</li>";;
	}
	else if(!textValidate(formobj.role.value))
	{
		errStr+="<li>"+geterrmsg('e8')+"</li>";;
	}
	if(formobj.passwd.value=="")
	{
		errStr+="<li>"+geterrmsg('e12')+"</li>";;
	}
//	else if(!alphanumeric(formobj.passwd.value))
//	{
//		errStr+="<li>"+geterrmsg('e13')+"</li>";;
//	}
	if(errStr!="")
	{
		document.getElementById("errorId").style.paddingBottom="15px";
		document.getElementById("errorId").style.height="auto";
		document.getElementById("errorId").innerHTML='<div class="list"><img src="./images/icon_critalert.gif" alt="icon_crit" class="flotleft" border="0"/><div class="flotleft"> Your information is incomplete or incorrect&#46; Please correct the fields below and try again&#46;<ul>'+errStr+'</ul></div></div>';
		return false;
	}
	else
	return true;
}

function userdet_validate(formobj)
{
	var errStr="";
	if(formobj.firstname.value=="")
	{
		errStr+="<li>"+geterrmsg('e1')+"</li>";;
	}
	else if(!nameValidate(formobj.firstname.value))
	{
		errStr+="<li>"+geterrmsg('e2')+"</li>";;
	}
	if(formobj.lastname.value=="")
	{
		errStr+="<li>"+geterrmsg('e3')+"</li>";;
	}
	else if(!nameValidate(formobj.lastname.value))
	{
		errStr+="<li>"+geterrmsg('e4')+"</li>";;
	}
	if(formobj.organisation.value=="")
	{
		errStr+="<li>"+geterrmsg('e5')+"</li>";;
	}
	else if(!textValidate(formobj.organisation.value))
	{
		errStr+="<li>"+geterrmsg('e6')+"</li>";;
	}
	if(formobj.role.value=="")
	{
		errStr+="<li>"+geterrmsg('e7')+"</li>";;
	}
	else if(!textValidate(formobj.role.value))
	{
		errStr+="<li>"+geterrmsg('e8')+"</li>";;
	}
	if(formobj.email.value=="")
	{
		errStr+="<li>"+geterrmsg('e9')+"</li>";;
	}
	else if(!emailValidate(formobj.email.value))
	{
		errStr+="<li>"+geterrmsg('e10')+"</li>";;
	}
	else if(emailexist(formobj.email))
	{
		errStr+="<li>"+geterrmsg('e11')+"</li>";;
	}
	if(errStr!="")
	{
		document.getElementById("errorId").style.paddingBottom="15px";
		document.getElementById("errorId").style.height="auto";
		document.getElementById("errorId").innerHTML='<div class="list"><img src="./images/icon_critalert.gif" alt="icon_crit" class="flotleft" border="0"/><div class="flotleft"> Your information is incomplete or incorrect&#46; Please correct the fields below and try again&#46;<ul>'+errStr+'</ul></div></div>';
		return false;
	}
	else
	return true;
}


function emailValidate(email) 
{
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,3})$/;
   return reg.test(trim(email));
}

function nameValidate(string) 
{
//   var reg = /^([a-z]+)$/i;
    var reg = /^([A-Za-z]+(\s|\s)?[A-Za-z]*){1,2}$/i;
  return reg.test(trim(string));
}

function textValidate(string) 
{
   var reg = /^([A-Za-z0-9,.'-]+(\s|\s)?[A-Za-z0-9,.'-]*){2,3}$/i;
   return reg.test(trim(string.replace(" ","")));
}

function alphanumeric(string) 
{
	string=trim(string);
	if(string.search(/[^a-zA-Z0-9 ]/g) != -1 )
	{
		return false;
	}
	else
	return true;
}

function password(string) 
{
	string=trim(string);
	if(string.search(/[^a-z0-9]/g) != -1 )
	{
		return false;
	}
	else
	return true;
}

function registersubmit()
{
	document.getElementById("processsubmit").innerHTML='<img src="./images/loading.gif" alt="Processing" class="flotleft" style="margin-left:20px;" border="0"/>';
	document.downloadform.submit();
}