var regContentPasteAt = '';

var progressbar_hrml = "<table border='0' cellspacing='0' cellpadding='0' onClick='return false;'>	<tr>		<td>			<div>				<table border='0' cellpadding='0' cellspacing='0' width='100%'>					<tr>						<td>							<p>								<strong>Please wait...</strong>							</p>						</td>					</tr>				</table>			</div>		</td>	</tr></table>";

var html_progressbar = "<table border='0' cellspacing='0' cellpadding='0' id='loaderContainer' onClick='return false;'>	<tr>		<td id='loaderContainerWH'>			<div id='loader'>				<table border='0' cellpadding='0' cellspacing='0' width='100%'>					<tr>						<td>							<p>								<strong>Please wait...</strong>							</p>						</td>					</tr>				</table>			</div>		</td>	</tr></table>";

var php_exec_wait = "<table border='0' cellspacing='0' cellpadding='0' onClick='return false;'><tr><td>			<div>				<table border='0' cellpadding='0' cellspacing='0' width='100%'>					<tr>						<td id='loaderContainerWH'>							<p>								<img src='images/parsing-preloader.gif'>							</p>						</td>					</tr>				</table>			</div>		</td>	</tr></table>";	

function getFileName ()
{
 var s = document.getElementById('file_source');
 if(null != s && '' == s.value)
 {
 	alert('Define file name');
 	s.focus();
 	return false;
 }
}

function checkUserRegistrationValidation(email,img_capta_val)
{
	var c = "t";
	if(IsEmpty(document.getElementById("user_email_address")))
	{
		alert('Please Enter Email address');
		document.getElementById("user_email_address").focus();
		c = "f";
		return false;
	}
	if(echeck(document.getElementById("user_email_address").value)==false)
	{
		document.getElementById("user_email_address").value="";
		document.getElementById("user_email_address").focus();
		c = "f";
		return false;
	}	
	if(!checkEmailAddress(email))
	{
		alert("A user with this Email Id already exist. Please provide another Email Id.");
		document.getElementById("user_email_address").focus();
		c = "f";
		return false;
	}
	
	if(IsEmpty(document.getElementById("user_password")))
	{
		alert("Please Enter Passsword");
		document.getElementById("user_password").focus();
		c = "f";
		return false;
	}

	var password = document.getElementById("user_password").value;
	if(password.length < 8)
	{
		alert("Password should have atleast 8 characters");
		document.getElementById("user_password").focus();
		c = "f";
		return false;
	}
	for(i=0;i<10;i++)
	{
		var hasdigit = "0";
		var temp = password.lastIndexOf(i);
		if(temp==-1 || temp=="-1")
		{
			var hasdigit = "0";
		}
		else
		{
			var hasdigit = "1";
			break;
		}
	}
	if(hasdigit==0 || hasdigit=="0")
	{
		alert("Password should have atleast one digit");
		document.getElementById("user_password").focus();
		c = "f";
		return false;
	}
		
	var confirm_password = document.getElementById("user_confirm_password").value;
	if(password != confirm_password)
	{
		alert("Password does not match with confirm password.");
		document.getElementById("user_confirm_password").focus();
		c = "f";
		return false;
	}
		
	if(IsEmpty(document.getElementById("user_first_name")))
	{
		alert("Please Enter First Name.");
		document.getElementById("user_first_name").focus();
		c = "f";
		return false;
	}
	if(validateField(document.getElementById("user_first_name").value,"user_first_name","0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ")==false)
	{
  		document.getElementById("user_first_name").focus();
  		c = "f";
  		return false;
	}
	if(IsEmpty(document.getElementById("user_last_name")))
	{
		alert("Please Enter Last Name.");
		document.getElementById("user_last_name").focus();
		c = "f";
		return false;
	}
	if(validateField(document.getElementById("user_last_name").value,"user_last_name","0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ")==false)
	{
  		document.getElementById("user_last_name").focus();
  		c = "f";
  		return false;
	}

	if(IsEmpty(document.getElementById("user_phone")))
	{
		alert("Please Enter Phone Number.");
		document.getElementById("user_phone").focus();
		c = "f";
		return false;
	}
	
	var len=document.getElementById("user_phone").value.length;
  	if(len>20)
	{
	 	alert("Invalid phone Number.");
	 	document.getElementById("user_phone").focus();
		c = "f";
		return false;
	}
	if(validateField(document.getElementById("user_phone").value,"user_phone","0123456789).(-")==false)
	{
		document.getElementById("user_phone").focus();
		alert("Invalid phone Number.");
		c = "f";
		return false;
	}		
	if(IsEmpty(document.getElementById("user_address1")))
	{
		alert("Please Enter Address Line1.");
		document.getElementById("user_address1").focus();
		c = "f";
		return false;
	}
 	if(validateField(document.getElementById("user_address1").value,"user_address1","0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'- ")==false)
	{
		document.getElementById("user_address1").focus();
		c = "f";
		return false;
	}

	if(IsEmpty(document.getElementById("user_city")))
	{
		alert("Please Enter City.");
		document.getElementById("user_city").focus();
		c = "f";
		return false;
	}
	if(validateField(document.getElementById("user_city").value,"user_city","0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'- ")==false)
	{
		document.getElementById("user_city").focus();
		c = "f";
		return false;
	}
	if(IsEmpty(document.getElementById("user_state")))
	{
		alert("Please Enter State.");
		document.getElementById("user_state").focus();
		c = "f";
		return false;
	}
	if(validateField(document.getElementById("user_state").value,"user_state","0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'- ")==false)
	{
		document.getElementById("user_state").focus();
		c = "f";
		return false;
	}
	if(IsEmpty(document.getElementById("user_zipcode")))
	{
		alert("Please Enter Zip Code.");
		document.getElementById("user_zipcode").focus();
		c = "f";
		return false;
	}

	var zip=document.getElementById("user_zipcode").value;
	if(validateField(document.getElementById("user_zipcode").value,"user_zipcode","0123456789-")==false)
	{
		
		alert("Please enter valid Zip code");
		document.getElementById("user_zipcode").focus();
		c = "f";
		return false;
	}
	if(!validImageCatha(img_capta_val))
	{
		alert("Inserted Code and Image Code Not Matched!");
		document.getElementById("imgverify").focus();
		c = "f";
		return false;
	}
  	if(c == "t")
	{
		return true;
	}
	
}

function checkGroupRegistrationValidation(email,group_name,img_capta_val)
{
	if(!checkUserRegistrationValidation(email,img_capta_val))
	{
		//alert("main return fal");
		return false;
	}
	
	if(IsEmpty(document.getElementById("group_name")))
	{
		alert("Please Enter Group Name.");
		document.getElementById("group_name").focus();
		return false;
	}
	if(validateField(document.getElementById("group_name").value,"group_name","0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ")==false)
	{
  		document.getElementById("group_name").focus();
  		return false;
	}
	//alert(group_name);
	if(!checkGroupName(group_name))
	{
		
		alert("A Group with this name already exist. Please provide another Group Name.");
		document.getElementById("group_name").focus();
		return false;
	}
	if(IsEmpty(document.getElementById("group_email_address")))
	{
		alert("Please Enter Group Email Address.");
		document.getElementById("group_email_address").focus();
		return false;
	}
	if(echeck(document.getElementById("group_email_address").value)==false)
	{
		document.getElementById("group_email_address").value="";
		document.getElementById("group_email_address").focus();
		return false;
	}
	if(IsEmpty(document.getElementById("group_url")))
	{
		alert("Please Enter URL");
		document.getElementById("group_url").focus();
		return false;
	}
	
	if(IsEmpty(document.getElementById("group_address1")))
	{
		alert("Please Enter Address Line1.");
		document.getElementById("group_address1").focus();
		return false;
	}
 	
	if(IsEmpty(document.getElementById("group_city")))
	{
		alert("Please Enter City.");
		document.getElementById("group_city").focus();
		return false;
	}
	if(validateField(document.getElementById("group_city").value,"group_city","0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'- ")==false)
	{
		document.getElementById("group_city").focus();
		return false;
	}
	if(IsEmpty(document.getElementById("group_state")))
	{
		alert("Please Enter State.");
		document.getElementById("group_state").focus();
		return false;
	}
	if(validateField(document.getElementById("group_state").value,"group_state","0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'- ")==false)
	{
		document.getElementById("group_state").focus();
		return false;
	}
	if(IsEmpty(document.getElementById("group_zipcode")))
	{
		alert("Please Enter Zip Code.");
		document.getElementById("group_zipcode").focus();
		return false;
	}

	var zip=document.getElementById("group_zipcode").value;
	if(validateField(document.getElementById("group_zipcode").value,"group_zipcode","0123456789-")==false)
	{
		
		alert("Please enter valid Zip code");
		document.getElementById("group_zipcode").focus();
		return false;
	}

	if(IsEmpty(document.getElementById("group_phone")))
	{
		alert("Please Enter Phone Number.");
		document.getElementById("group_phone").focus();
		return false;
	}
	
	var len=document.getElementById("group_phone").value.length;
  	if(len>20)
	{
	 	alert("Invalid phone Number.");
	 	document.getElementById("group_phone").focus();
		 return false;
	}
	if(validateField(document.getElementById("group_phone").value,"group_phone","0123456789)(-+")==false)
	{
		document.getElementById("group_phone").focus();
		return false;
	}
	

	//return false;
}

function showRegistrationForm(who_register)
{
	
	regContentPasteAt = "which_form_display";
	if(who_register == "user")
	{
		document.getElementById(regContentPasteAt).innerHTML = php_exec_wait;
		var url = "ajax_user_registration_form.php?display_through_ajax=yes&who_register=" + who_register;
		loadXMLDocRegistrationForm(url);	
	}
	if(who_register == "group")
	{
		document.getElementById(regContentPasteAt).innerHTML = php_exec_wait;
		var url = "ajax_group_registration_form.php?display_through_ajax=yes&who_register=" + who_register;
		loadXMLDocRegistrationForm(url);	
		
	}
	if(who_register == "application")
	{
		document.getElementById(regContentPasteAt).innerHTML = "Coming Soon";
		var url = "ajax_application_registration_form.php?display_through_ajax=yes&who_register=" + who_register;	
		
	}

	
}

function checkApplicationRequestValidation(appl_name)
{

  	
  	if(IsEmpty(document.getElementById("appl_name")))
	{
		alert("Please Enter Application Name.");
		document.getElementById("appl_name").focus();
		return false;
	}
	/*if(validateField(document.getElementById("appl_name").value,"appl_name","0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-)( ")==false)
	{
  		document.getElementById("appl_name").focus();
  		alert("Invalid character found in Application field.");
  		return false;
	}*/
	
	if(!checkApplicationName(appl_name))
	{
		
		alert("An Application with this name already exist. Please provide another Application Name.");
		document.getElementById("appl_name").focus();
		return false;
	}
	
	if(IsEmpty(document.getElementById("appl_desc")))
	{
		alert("Please Enter Application Description.");
		document.getElementById("appl_desc").focus();
		return false;
	}
	if(IsEmpty(document.getElementById("appl_url")))
	{
		alert("Please Enter URL");
		document.getElementById("appl_url").focus();
		return false;
	}
	if(!testUrl(document.getElementById("appl_url").value))
	{
		alert("Invalid URL format.");
		document.getElementById("appl_url").focus();
		return false;
	}
	
	if(IsEmpty(document.getElementById("appl_owner_name")))
	{
		alert("Please Enter Contact Person Name.");
		document.getElementById("appl_owner_name").focus();
		return false;
	}
 	
 	
	
	if(IsEmpty(document.getElementById("appl_owner_addr")))
	{
		alert("Please Enter Address Line1.");
		document.getElementById("appl_owner_addr").focus();
		return false;
	}
 	
 	if(IsEmpty(document.getElementById("appl_owner_city")))
	{
		alert("Please Enter City.");
		document.getElementById("appl_owner_city").focus();
		return false;
	}
	
	if(IsEmpty(document.getElementById("appl_owner_state")))
	{
		alert("Please Enter State.");
		document.getElementById("appl_owner_state").focus();
		return false;
	}
	
	if(IsEmpty(document.getElementById("appl_owner_zipcode")))
	{
		alert("Please Enter Zip Code.");
		document.getElementById("appl_owner_zipcode").focus();
		return false;
	}

	var zip=document.getElementById("appl_owner_zipcode").value;
	if(validateField(document.getElementById("appl_owner_zipcode").value,"appl_owner_zipcode","0123456789-")==false)
	{
		
		alert("Please enter valid Zip code");
		document.getElementById("appl_owner_zipcode").focus();
		return false;
	}

	if(IsEmpty(document.getElementById("phone")))
	{
		alert("Please Enter Phone Number.");
		document.getElementById("phone").focus();
		return false;
	}
	
	var len=document.getElementById("phone").value.length;
  	if(len>20)
	{
	 	alert("Invalid phone Number.");
	 	document.getElementById("phone").focus();
		 return false;
	}
	if(validateField(document.getElementById("phone").value,"phone","0123456789.)(-+")==false)
	{
		
		alert("Invalid phone Number.");
		document.getElementById("phone").focus();
		return false;
	}
	
	if(document.getElementById("billing_fld").style.display == "block")
	{
		//alert(document.getElementById("appl_credit_days").value);
		if(IsEmpty(document.getElementById("appl_credit_days")))
		{
			alert("Please Enter Credit Days.");
			document.getElementById("appl_credit_days").focus();
			return false;
		}

		if(validateField(document.getElementById("appl_credit_days").value,"appl_credit_days","0123456789")==false)
		{
			alert("Please Enter Only Numeric value.");
			document.getElementById("appl_credit_days").focus();
			return false;
		}
	}
	//return false;
}

function editApplicationRequestValidation(appl_name)
{
  var app_id=document.getElementById("app_id").value;
  if(IsEmpty(document.getElementById("appl_name")))
	{
		alert("Please Enter Application Name.");
		document.getElementById("appl_name").focus();
		return false;
	}
	/*if(validateField(document.getElementById("appl_name").value,"appl_name","0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-)( ")==false)
	{
  		document.getElementById("appl_name").focus();
  		alert("Invalid character found in Application field.");
  		return false;
	}*/
	
	if(!checkApplicationName(appl_name,app_id))
	{
		alert("An Application with this name already exist. Please provide another Application Name.");
		document.getElementById("appl_name").focus();
		return false;
	}
	
	if(IsEmpty(document.getElementById("appl_desc")))
	{
		alert("Please Enter Application Description.");
		document.getElementById("appl_desc").focus();
		return false;
	}
	if(IsEmpty(document.getElementById("appl_url")))
	{
		alert("Please Enter URL");
		document.getElementById("appl_url").focus();
		return false;
	}
	if(!testUrl(document.getElementById("appl_url").value))
	{
		alert("Invalid URL format.");
		document.getElementById("appl_url").focus();
		return false;
	}
	
	if(IsEmpty(document.getElementById("appl_owner_name")))
	{
		alert("Please Enter Contact Person Name.");
		document.getElementById("appl_owner_name").focus();
		return false;
	}
 	 	
	
	if(IsEmpty(document.getElementById("appl_owner_addr")))
	{
		alert("Please Enter Address Line1.");
		document.getElementById("appl_owner_addr").focus();
		return false;
	}
 	
 	if(IsEmpty(document.getElementById("appl_owner_city")))
	{
		alert("Please Enter City.");
		document.getElementById("appl_owner_city").focus();
		return false;
	}
	
	if(IsEmpty(document.getElementById("appl_owner_state")))
	{
		alert("Please Enter State.");
		document.getElementById("appl_owner_state").focus();
		return false;
	}
	if(IsEmpty(document.getElementById("appl_owner_zipcode")))
	{
		alert("Please Enter Zip Code.");
		document.getElementById("appl_owner_zipcode").focus();
		return false;
	}
	var zip=document.getElementById("appl_owner_zipcode").value;
	if(validateField(document.getElementById("appl_owner_zipcode").value,"appl_owner_zipcode","0123456789-")==false)
	{
		
		alert("Please enter valid Zip code");
		document.getElementById("appl_owner_zipcode").focus();
		return false;
	}
	if(IsEmpty(document.getElementById("phone")))
	{
		alert("Please Enter Phone Number.");
		document.getElementById("phone").focus();
		return false;
	}
	
	var len=document.getElementById("phone").value.length;
  if(len>20)
	{
	 	alert("Invalid phone Number.");
	 	document.getElementById("phone").focus();
		return false;
	}
	if(validateField(document.getElementById("phone").value,"phone","0123456789.)(-+")==false)
	{
		alert("Invalid phone Number.");
		document.getElementById("phone").focus();
		return false;
	}
	
	if(document.getElementById("billing_fld").style.display == "block")
	{
		if(IsEmpty(document.getElementById("appl_credit_days")))
		{
			alert("Please Enter Credit Days.");
			document.getElementById("appl_credit_days").focus();
			return false;
		}

		if(validateField(document.getElementById("appl_credit_days").value,"appl_credit_days","0123456789")==false)
		{
			alert("Please Enter Only Numeric value.");
			document.getElementById("appl_credit_days").focus();
			return false;
		}
	}
	//return false;
}



function loadXMLDocRegistrationForm(url)
{
	// branch for native XMLHttpRequest object
	//alert(1);
	if (window.XMLHttpRequest)
	{
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChangeRegistrationForm;
		req.open("GET", url, true);
		req.send(null);
		// branch for IE/Windows ActiveX version
	}
	else if (window.ActiveXObject)
	{
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req)
		{
			req.onreadystatechange = processReqChangeRegistrationForm;
			req.open("GET", url, true);
			req.send();
		}
	}
}

function processReqChangeRegistrationForm()
{
	// only if req shows "complete"
	if (req.readyState == 4)
	{
		
		// only if "OK"
		if (req.status == 200)
		{
			response = req.responseXML.documentElement;
			var urlpath='';
			////alert(response.getElementsByTagName('testingnode')[0].childNodes[x].data); inside for loop
			for(var x = 0; response.getElementsByTagName('urlpath')[0].childNodes[x]; x++ )
				 urlpath = urlpath.concat(response.getElementsByTagName('urlpath')[0].childNodes[x].data);			
			document.getElementById(regContentPasteAt).innerHTML = urlpath;
		}
		else
		{
			alert("There was a problem retrieving the XML data:\n" + req.statusText);
		}
	}
}

