//------------------STORE NUMERIC VALUE-----------------------------//
function alphanumeric()
{
 var numaric = document.register.appname.value
 var Exp1     = /[a-zA-Z0-9]+$/;
 var Exp      = /^[a-zA-Z]+$/; 
 
 if (numaric == '')
  {
   alert("Application Name cannot be left Empty");
   document.register.appname.focus();
   return false;
  }
  else if (numaric.match(Exp1))
  {
   
  }
    else {
   alert("Must be Alphanumeric\nExample: ContactMNGT001");
   document.register.appname.focus();
   return false;
  } 
  
  return true;
}
/*--------------------------------------------------upload check and license key checking------------------------------------------------------------*/
function choosename(){
	
	var uploadapp   	     =	 	document.getElementById('appname');
	var domain    	             =	 	document.getElementById('domain');	
	var uploadproject            = 		document.getElementById('myInput');
	var licence   		     =	 	document.getElementById('cyf');
	var licence1   		     =	 	document.getElementById('cyf1');
	var licence2   		     =	 	document.getElementById('cyf2');
	var licence3   		     =	 	document.getElementById('cyf3');

			

	// Check each input in the order that it appears in the form!
	if(Appuploadapp(uploadapp, "Please Select the Registered Application")){
	                if(Appuploaddomain(domain, "Please Select the Registered Partition")){
			if(Appuploadproject(uploadproject, "Please enter a valid Email ID")){
			if(Applicence(licence, "Please enter License Key")){
			if(Applicence1(licence1, "Please enter License Key")){
			if(Applicence2(licence2, "Please enter License Key")){
			if(Applicence3(licence3, "Please enter License Key")){									
								
								uploadStatus();
								return true;
								
	        		   		                }
							   }
            					     }
					       }
				         }
			          }	
			 }
return false;
}

function uploadStatus() {
	
	$('.uploadStatus').show();
	//alert("all true");
	
}

function Appuploadapp(){
	
	var registeredname = document.getElementById('appname').selectedIndex;
	
	if (registeredname == 0)
	{
	alert("Please Select the Registered Application");
	return false;
	}
	else 
	{
	return true;
	}
}

function Appuploaddomain(){

	var domain = document.getElementById('domain').selectedIndex;	
	
	if (domain == 0)
	{
	alert("Please Select the Registered Partition");
	return false;
	}
	else 
	{
	return true;
	}
	
}

function Appuploadproject(){
	{
    
        // for mac/linux, else assume windows
        if (navigator.appVersion.indexOf('Mac') != -1 || navigator.appVersion.indexOf('Linux') != -1)
            var fileSplit = '/';
        else
            var fileSplit = '\\';
    
        var fileTypes     = new Array('.vuf', '.VUF'); // valid filetypes
        var fileName      = document.getElementById('myInput').value; // current value
        var extension     = fileName.substr(fileName.lastIndexOf('.'), fileName.length);
		var emptyfield    = document.getElementById('myInput').value;
        var valid = 0;
        
        for(var i in fileTypes)
        {
        
            if(fileTypes[i] == extension)
            {
            
                valid = 1;
                break;
                
            }
        
        }
		
		if (emptyfield == '')
		{
			alert("Please choose a file to upload");
			return false;
		}
        
        if(valid == 1)
            return true;
        else
	    
        alert("Not a .Vuf file!");
	    document.upload.myInput.focus();
	    return false;
        
    }
}


function Applicence(elem, helperMsg){
	var alphaExp = /^[a-z A-Z 0-9 .]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function Applicence1(elem, helperMsg){
	var alphaExp = /^[a-z A-Z 0-9 .]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function Applicence2(elem, helperMsg){
	var alphaExp = /^[a-z A-Z 0-9 .]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function Applicence3(elem, helperMsg){
	var alphaExp = /^[a-z A-Z 0-9 .]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

/*---------------------------------------------------registeration validation------------------------------------------*/
function registerformValidator(){
	
	var registerfullname    = document.getElementById('fullname');
	var registeremailid     = document.getElementById('emailid');
	var registerpassword    = document.getElementById('password');		
	var registerconfirmpass = document.getElementById('confirmpass');
	var registertermsagree   = document.register.agree.checked

			

	// Check each input in the order that it appears in the form!
	if(registerisAlphabet(registerfullname, "Please enter Full Name")){
			if(registeremailValidator(registeremailid, "Please enter a valid Email ID")){
       				if(registerlengthRestriction(registerpassword, 6, 16)){
						if(registerchkpassword(registerpassword,registerconfirmpass)){
								if(registerlicense(registertermsagree)){																				
								return true;
	        		   	    }
		        	 }	
		        } 
	     }
	}
return false;
}



function registerisAlphabet(elem, helperMsg){
	var alphaExp = /^[a-z A-Z .]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function registeremailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function registerlengthRestriction(elem, min, max){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("Your Password must be of atleast " +min+ " Characters and Maximum of" +max+ " ");
		elem.focus();
		return false;
	}
}


function registerchkpassword(elem1,elem2) {

	if(elem1.value != elem2.value) {
		alert('Your Passwords do not match. Please enter again');
		elem2.focus();
		return false;
		}
return true;
}

function registerlicense(form) { 

	if(!document.register.agree.checked)
	{
		alert("Please accept Terms of Use to register"); 
		return false;
	}else{
		return true;
}
}
/*-------------------------------------------------------------------login---------------------------------------------------------------------------------------*/
function loginValidator(){
	
	var loginemailid     = document.getElementById('useremailid');
	var loginpassword    = document.getElementById('userpassword');		
			
	// Check each input in the order that it appears in the form!
		if(loginemailValidator(loginemailid, "Please enter Registered Email ID")){
       				if(loginlengthRestriction(loginpassword, 6, 16)){
						return true;
	        		   } 
			     }
return false;
}



function loginemailValidator(elem, helperMsg){
	if((elem.value.length<=4) || (elem.value==null)) {
		alert(helperMsg);
		elem.focus();
		return false;
	}else{		
		return true;
	}
}

function loginlengthRestriction(elem, min, max){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("Your Password must be of atleast " +min+ " Characters");
		elem.focus();
		return false;
	}
}

/*---------------------------------------------------------------forgot password----------------------------------------------------------------------------*/
function forgotpassword(){
	
	var forgotemailid     = document.getElementById('emailid');
	if(forgotemailValidator(forgotemailid, "Please enter valid Email ID")){
       			return true;
	
  }
return false;
}
function forgotemailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
/*--------------------------- testzone_adminlist.html -------------------------*/
function checkselect() {
	var check  =  document.getElementById('corpname').selectedIndex;
	if (check == 0) 
	{
		alert("Please Select a Corpus");
		return false;
	}
	else
	{
	return true;
	}
}
/*----------------- testzone_startapp.html -------------------------*/
function startapp() {
	var checkappname  =  document.getElementById('appname').selectedIndex;
	if (checkappname == 0) 
	{
		alert("Please Select a Registered Application");
		return false;
	}
	else
	{
	return true;
	}
}
/*----------------- view log testzone_applog.html -------------------------*/
function viewlog() {
	var checkappname  =  document.getElementById('appname').selectedIndex;
	if (checkappname == 0) 
	{
		alert("Please Select a Registered Application");
		return false;
	}
	else
	{
	return true;
	}
}
/*---------------- listing application ----------------*/

function listappValidator(){
	
	var listtitle    = document.getElementById('title');
	var listcategory     = document.getElementById('category');
	var listdesc = document.getElementById('desc');
	var listprivacy   = document.getElementById('checkbox1');

			

	// Check each input in the order that it appears in the form!
	if(LAtitle(listtitle, "Please enter Application Title")){
			if(LAcategory(listcategory, "Please Choose a Category")){
       				if(LAlistdesc(listdesc, "Please a brief description about the Application")){
								if(LAprivacy(listprivacy, "Please a brief description about the Application")){									
								return true;
	        		   	    }
		        	 }	
		        } 
		}
return false;
}



function LAtitle(elem, helperMsg){
	var alphaExp = /^[a-z A-Z .]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function LAcategory(){
	var listcategory = document.getElementById('category').selectedIndex; 	
	if (listcategory  == 0) 
	{
		alert("Please Select a Category");
		return false;
	}
	else
	{
	return true;
	}
}

function LAlistdesc(elem, helperMsg){
	var uInput = elem.value;
	if(uInput.length <=6){
	alert("Please a brief description about the Application");
	elem.focus();
	return false;
	}
	if(uInput.length <= max){
		return true;
	}
	else{
		alert("Description should be more than 6 characters!");
		elem.focus();
		return false;

	}
}

function LAprivacy(elem, helperMsg){
	var uInput = elem.value;
	if(uInput.length <=6){
	alert("Please a brief description about the Application");
	elem.focus();
	return false;
	}
	if(uInput.length <= max){
		return true;
	}
	else{
		alert("Description should be more than 6 characters!");
		elem.focus();
		return false;

	}
}


function LAprivacy() { 

	alert("inside agree");
	
}
/*--------------------------------------------------------------post query and contact form--------------------------------------------------------------------*/
function open_limitations()
{
   window.open("/limitations.html","_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, width=700, height=500")
}