function getParameter(insertId)
{
	var pageParameter='';
	insertId = insertId.split('|');
	for(var i = 0; i < (insertId.length-1); i++)
		pageParameter +=  "&" + insertId[i] + "=" +  escape(trim(document.getElementById(insertId[i]).value)) ;
	return  pageParameter;
}
function getInsertPageAddress(pageId,insertId,updateId,validationLevelText,validationText,viewPageId)
{
	var pageAddress='';
	var pageParameter = '';
	if(viewPageId == 'admin')
		directory = "../server_script/insert.php.php?pageId=" + pageId; 
	else
		directory = "server_script/insert.php.php?pageId=" + pageId; 
	
 	switch(pageId)
	{
 		case '1':
			var validationStop =  checkValidation(validationLevelText,validationText );
			//if(getCheckedRdoBtn() == 1)
   			if(validationStop != "")
			{
 				pageAddress = directory +"&id="+ updateId + "&page=" + getParameter(insertId) +  "&position=" + escape(getCheckedRdoBtn());
				if(checkMatch('txtSponsorId', 'txtConfirmSponsorId') == 1 )
				{
 						alert("Sponsor ID not match.");
						pageAddress = "";
 						return false;
 				}
 				if(checkMatch('txtEmail', 'txtConfirmEmail') == 1 )
				{
 						alert("Email not match.");
						pageAddress = "";
 						return false;
 				}
				
 				if( validEmail(trim(document.getElementById('txtEmail').value)) == 0 )
				{
 						alert("Provide valid Email.");
						pageAddress = "";
 						return false;
 				}
				
				
				
				
			}
  		break;
		case 'my_details':
			var validationStop =  checkValidation(validationLevelText,validationText );
			pageAddress = directory +"&id="+ updateId + "&page=" + getParameter(insertId);
			
			if(validationStop != "")
			{
 				if(checkMatch('txtPassword', 'txtConfirmPassword') == 1 )
				{
 						alert("Password not match.");
						pageAddress = "";
 						return false;
 				}
			}
		break;
		
		case 'money_tranasfer':
 
			var validationStop =  checkValidation(validationLevelText,validationText );
			if(validationStop != "")
			{	
				pageAddress = directory +"&id="+ updateId + "&page=" + getParameter(insertId);
				if(parseInt(document.getElementById('lblBalance').innerHTML) < parseInt(document.getElementById('txtAmount').value))
				{
 						alert("Enter valid Transaction Amount.");
						pageAddress = "";
 						return false;
 				}
				if(checkMatch('txtTPassword', 'txtHiddenTPassword') == 1 )
				{
 						alert("Worng! Transaction Password.");
						pageAddress = "";
 						return false;
 				}
 			}
			
			
		 
		break;
		
 		case 'my_profile':
   			pageAddress = directory +"&id="+ updateId + "&page=" + getParameter(insertId);
 		break;
 		case 'my_receipts':
   			var validationStop =  checkValidation(validationLevelText,validationText );
			if(validationStop != "")
				pageAddress = directory +"&id="+ updateId + "&page=" + getParameter(insertId);
 		break;

		case 'change_password':
   			var validationStop =  checkValidation(validationLevelText,validationText );
			if(validationStop != "")
			{	
				pageAddress = directory +"&id="+ updateId + "&page=" + getParameter(insertId);
 				if(checkMatch('oldPassword', 'txtCurrentPassword') == 1 )
				{
 						alert("Worng! Current Password.");
						pageAddress = "";
 						return false;
 				}
 				if(checkMatch('txtNewPassword', 'txtConfirmPassword') == 1 )
				{
 						alert("Password not match.");
						pageAddress = "";
 						return false;
 				}
				
			}
 		break;
		
	 	case 'generate_tpassword':
  				pageAddress = directory +"&id="+ updateId + "&page="  ;
 		break;
	 	case 'change_tpassword':
   			var validationStop =  checkValidation(validationLevelText,validationText );
			if(validationStop != "")
			{ 
				pageAddress = directory +"&id="+ updateId + "&page=" + getParameter(insertId);
 				if(checkMatch('oldTPassword', 'txtCurrentTPassword') == 1 )
				{
 						alert("Worng! Current Transaction Password.");
						pageAddress = "";
 						return false;
 				}
 				if(checkMatch('txtNewTPassword', 'txtConfirmTPassword') == 1 )
				{
 						alert("Transaction Password not match.");
						pageAddress = "";
 						return false;
 				}
			}
 		break;
		case 'upgrade_account':
 
   			var validationStop =  checkValidation(validationLevelText,validationText );
			if(validationStop != "")
			{	
				pageAddress = directory +"&id="+ updateId + "&page=" + getParameter(insertId);
 				if(checkMatch('txtTPassword', 'txtHiddenTPassword') == 1 )
				{
 						alert("Worng! Transaction Password.");
						pageAddress = "";
 						return false;
 				}
 			}
 		break;
		case 'renew_account':
   			var validationStop =  checkValidation(validationLevelText,validationText );
			if(validationStop != "")
			{	
				pageAddress = directory +"&id="+ updateId + "&page=" + getParameter(insertId);
 				if(checkMatch('txtTPassword', 'txtHiddenTPassword') == 1 )
				{
 						alert("Worng! Transaction Password.");
						pageAddress = "";
 						return false;
 				}
 			}
 		break;

		case 'buy_payment_code':
   			var validationStop =  checkValidation(validationLevelText,validationText );
			if(validationStop != "")
			{	
				pageAddress = directory +"&id="+ updateId + "&page=" + getParameter(insertId);
 				if(checkMatch('txtTPassword', 'txtHiddenTPassword') == 1 )
				{
 						alert("Worng! Transaction Password.");
						pageAddress = "";
 						return false;
 				}
 			}
 		break;
		
		
		case 'new_post_inews':
   			var validationStop =  checkValidation(validationLevelText,validationText );
			if(validationStop != "")
  				pageAddress = directory +"&id="+ updateId + "&page=" + getParameter(insertId) ;
  		break;

		case 'new_post_jobs':
   			var validationStop =  checkValidation(validationLevelText,validationText );
			if(validationStop != "")
  				pageAddress = directory +"&id="+ updateId + "&page=" + getParameter(insertId) ;
  		break;
		
		case 'new_settings':
   			
			var validationStop =  checkValidation(validationLevelText,validationText );
			if(validationStop != "")
  				pageAddress = directory +"&id="+ updateId + "&page=" + getParameter(insertId) ;
  		break;
		case 'new_job_settings':
   			
			var validationStop =  checkValidation(validationLevelText,validationText );
			if(validationStop != "")
  				pageAddress = directory +"&id="+ updateId + "&page=" + getParameter(insertId) ;
  		break;
		case 'calculation':
				pageAddress = directory +"&id="+ updateId ;
  		break;
				case 'job_calculation':
				pageAddress = directory +"&id="+ updateId ;
  		break;

		
	}
	return pageAddress;
}


function insertInformation(pageId,insertId,updateId,validationLevelText,validationText,viewPageId)
{
 	// alert(pageId + insertId  +'--'+ viewPageId + validationText + viewPageId);
	// alert(validationLevelText + validationText );
 
	var xmlhttp = getXMLhttp();
	document.getElementById("progress").style.visibility="visible";	
	xmlhttp.onreadystatechange=function()
	{	  
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{ 
 			   alert(xmlhttp.responseText);
			   if(pageId == 'buy_payment_code')
			   		window.location = "index.php?pageId=payment_code_history&id=" + updateId;
			   if(pageId == 'new_settings')
			   		window.location = "index.php?pageId=value_settings&id=" + updateId;
 			   if(pageId == 'new_post_jobs')
			   		window.location = "index.php?pageId=post_jobs&page=1";
					
					
				document.getElementById("progress").style.visibility="hidden";	
		}
 	}
	pageAddress = getInsertPageAddress(pageId,insertId,updateId,validationLevelText,validationText,viewPageId );
  //   alert(pageAddress);
 	if(pageAddress != "")
	{
		xmlhttp.open("GET",pageAddress,true);
		xmlhttp.send();
	}
	else
		document.getElementById("progress").style.visibility="hidden";	
}

function activationAll(pageId, active)
{  
 
	try
	{
		var aId = document.getElementById('hidenUId').value;
	}
	catch(ex)
	{
		alert('Search users first');
		return;
	}
 
	var type = 1;
	if(document.getElementById("rdoStatus").checked == true)
	{
		type = 0;		 
	}

 	var xmlhttp = getXMLhttp();
	document.getElementById("progress").style.visibility="visible";	
	xmlhttp.onreadystatechange=function()
	{	  
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
 			alert(xmlhttp.responseText);
			document.getElementById("progress").style.visibility="hidden";

		}
	}
 
 
 	var pageAddress= "../server_script/insert.php.php?pageId=" + pageId + "&aId=" + aId + "&active=" + active + "&type=" + type;
	
 
	xmlhttp.open("GET", pageAddress,true);
	xmlhttp.send();
	 
}


function assingAll(pageId, subPageID)
{  
	try
	{
		var aId = document.getElementById('hidenAId').value;
		var uId = document.getElementById('hidenUId').value;
	}
	catch(ex)
	{
		alert('Search users first');
		return;
	}
	
	var type = 1;
	if(document.getElementById("rdoStatus").checked == true)
	{
		type = 0;		 
	}

 	var xmlhttp = getXMLhttp();
	document.getElementById("progress").style.visibility="visible";	
	xmlhttp.onreadystatechange=function()
	{	  
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
 			alert(xmlhttp.responseText);
			document.getElementById("progress").style.visibility="hidden";

		}
	}
 
 
 	var pageAddress= "../server_script/insert.php.php?pageId=" + pageId + "&aId=" + aId + "&uId=" + uId + "&SubPageId=" + subPageID + "&type=" + type;
	
 
	xmlhttp.open("GET", pageAddress,true);
	xmlhttp.send();
	 
}

function checkMatch(id1, id2)
{
	if(document.getElementById(id1).value != document.getElementById(id2).value)
  		return 1;
	else 
		return 0;
 	
}

function checkExt()
{
	var ext = /\.htm|\.html/i;
	if ( trim(document.getElementById("txtTitle").value) == "")
	{
		alert("Provide Title.");
		document.getElementById("txtTitle").focus();
 		return false;
	}
	if ( (document.getElementById("txtFile").value).search(ext) == -1)
	{
		alert("Provide HTML File.");
		document.getElementById("txtFile").focus();
 		return false;
	}
	
}
function sendAnswers(pageId, qNo, title, numOfAns, ansType)
{
 	var input = document['form1'].elements['answer'];
	 var value = "";
	 for (var i=0; i <input.length; i++) 
	 {	
		  if (input[i].value == '') 
			value = "";
		  else
			 value +=  escape(input[i].value) + "|" ;
			 //value += "&answer" +(i+1)+ "=" + escape(input[i].value) ;
	 }
	 if (value == "") 
	 {
		alert('Provide All Answer(s).');
		return false;
	 }
	
	var xmlhttp = getXMLhttp();
	document.getElementById("progress").style.visibility="visible";	
	xmlhttp.onreadystatechange=function()
	{	  
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{ 
 			//alert(xmlhttp.responseText);
			 if(xmlhttp.responseText == 1)
			 {	
				window.opener.document.getElementById("btn"+qNo).innerHTML = "Posted";
				window.opener.document.getElementById("title"+qNo).disabled = true;
				window.opener.document.getElementById("answerType"+qNo).disabled = true;
 				window.close();
			 }
			 else
			 	alert("Sorry! Failed to post.");
 			document.getElementById("progress").style.visibility="hidden";	
		}
 	}
 	 
	xmlhttp.open("POST", "../../../server_script/insert.php.php?pageId=" + pageId + "&answer=" + value + "&qNo=" + qNo + "&title=" + escape(title) +"&ansType=" + ansType  + "&numOfAns=" + numOfAns + "&jobsId=" + opener.document.getElementById('jobsId').value  ,true);
	xmlhttp.send();
 
}


  
