 

function change_pass_validation(pass)
{
	if(document.getElementById("existingPass").value == '')
	{
		alert("Provide existing password");
		return "";
	}
	else if(document.getElementById("newPass").value == '')
	{
		alert("Provide new password");
		return "";
	}
	else if(document.getElementById("conPass").value == '')
	{
		alert("Provide confirm password");
		return "";
	}
	else if(trim(document.getElementById("existingPass").value) != pass)
	{
		alert("Existing password doesn't match");
		document.getElementById("existingPass").value = "";
		return "";
	}
	else if(trim(document.getElementById("newPass").value) != trim(document.getElementById("conPass").value))
	{
		alert("Confirm password doesn't match");
		document.getElementById("conPass").value = "";
		return "";
	}
	else
	{
		return document.getElementById("newPass").value;
	}
	
}


function get_change_password(tag, pass)
{
	var address = "layout/change_pass.php";
	
	if(tag == '1')
	{
		var new_pass = change_pass_validation(pass);
		if(new_pass != "")
			address = "config/change_pass.php?pass=" + new_pass;
		else
			address = "";
	}
	
	var xmlhttp = getXmlhttp();
 	 
	xmlhttp.onreadystatechange=function()
	{	  
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{ 
			if( xmlhttp.responseText != -1 )
			{
 
				alert(xmlhttp.responseText);
			}
			else
			{
 
				alert("Unable to perform this operation"); 
			}
		}
	}
	

	if(address != "")
	{
 		xmlhttp.open("GET", address, true);
		xmlhttp.send(); 
	}
}







function insertGoalOpeartion(page_id, i, emp_id, id)
{
 
 
 	left = parseInt(trim(document.getElementById(("txt_left" + i)).value));
	right = parseInt(trim(document.getElementById(("txt_right" + i)).value));
 
 	if(left.toString() == 'NaN')
	{
		alert('Provide Valid Goal');
		return false;
	}
	else
	{
	 	if(left <  0)
		{
			alert('Provide Valid Goal');
			return false;
		}	
	}
 
  	if(right.toString() == 'NaN')
	{
		alert('Provide Valid Goal');
		return false;
	}
	else
	{
	 	if(right <  0)
		{
			alert('Provide Valid Goal');
			return false;
		}	
	}

//	if(left == right)
//	{
//			alert('Provide Valid Goal');
//			return false;
//	}
 
 
 
 	
	var answer = confirm ("Warning: You cannot edit the assumption any more.");
 
	
	if(answer)
	{
		
  var pageAddress = "";
 
	var xmlhttp = getXmlhttp();
	
	xmlhttp.onreadystatechange=function()
	{	  
		document.getElementById("loder").style.visibility="visible";
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{ 
		    if(xmlhttp.responseText != "")
			{
				document.getElementById("loder").style.visibility="hidden";
				
	 
				if(xmlhttp.responseText == '')
					alert(xmlhttp.responseText);
				else
					alert("Information has been successfully saved.");
				 if(page_id == 0)
					window.location = "index.php?page_id=apply";	
				else
					window.location = "index.php?page_id=answer";
			}
			else
			{
				alert("Unable to Perfrom this Oparation");
				document.getElementById("loder").style.visibility="hidden";
			}
		}
	}
 
 	if(page_id == 0)
		pageAddress =  "server_script/execute.php?emp_id=" + emp_id + "&id=" + id + "&left=" + left + "&right=" + right + '&page_id=apply';
	else
		pageAddress =  "server_script/execute.php?emp_id=" + emp_id + "&id=" + id + "&left=" + left + "&right=" + right + '&page_id=answer';

	xmlhttp.open("GET",pageAddress,true);
	xmlhttp.send();
 	
	}
		
 
}
 
 
 

 



function get_parameter(insert_field)
{
	 
	var pageParameter='';
	insert_field = insert_field.split('|');
 
	for(var i = 0; i < (insert_field.length-1); i++)
	{
	  
		pageParameter +=  "&" + insert_field[i] + "=" +  escape(trim(document.getElementById(insert_field[i]).value)) ;
    }
	return  pageParameter;
}

 
function getXmlhttp()
{
	var xmlhttp;
	
 	try
	{
		xmlhttp = new XMLHttpRequest();
	} 
	catch(e)
	{
		// Internet Explorer Browsers
		try
		{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch(e) 
		{
			try
			{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e)
			{
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	return xmlhttp;
}

function insertOpeartion(id)
{
 
 	if(id == 'varify')
	{
		if(trim(document.getElementById("txt_pin").value) == '')
		{
			alert('Provide your pin');
			return false;
		}
		else
		{
			window.location = "index.php?page_id=register&id=" + document.getElementById("txt_pin").value;
		}
	}
	else if(id == 'login_action')
	{
		if(trim(document.getElementById("username").value) == '')
		{
			alert('Provide your Pin');
			return false;
		}
		else if(trim(document.getElementById("password").value) == '')
		{
			alert('Provide your Password');
			return false;
		}
		else
		{
			window.location = "index.php?page_id=login_action&id=" + document.getElementById("username").value + "&pass=" + document.getElementById("password").value;	
			
		}
		
	}
	else
	{
		if(trim(document.getElementById("txt_password").value) == '')
		{
			alert('Provide your Password');
			return false;
		}
		else if(trim(document.getElementById("txt_con_password").value) == '')
		{
			alert('Provide Confirm Password');
			return false;
		}
		else if(trim(document.getElementById("txt_date_of_birth").value) == '')
		{
			alert('Provide Date of Birth');
			return false;
		}
		else if(trim(document.getElementById("txt_con_password").value) != trim(document.getElementById("txt_password").value))
		{
			alert('Confirm Password and Password Could Not Match');
			document.getElementById("txt_con_password").value = "";
			document.getElementById("txt_password").value = "";
			return false;
			
		}
		else
		{
			window.location = "index.php?page_id=verify&id=" + document.getElementById("txt_pin").value + "&pass=" + document.getElementById("txt_password").value + "&dob=" + document.getElementById("txt_date_of_birth").value ;	
			 
			  
			
		}
		
	}
	
}
 
 
  
 
 

function trim(str) {
    while (str.substring(0, 1) == ' ') {
        str = str.substring(1, str.length);
    }
    while (str.substring(str.length - 1, str.length) == ' ') {
        str = str.substring(0, str.length - 1);
    }
    return str;
}
function checked_validation()
{
 
	if(trim(document.getElementById("fullname").value) == '')
	{
		alert('Provide Full name');
		return false;
	}
	else if(trim(document.getElementById("address").value) == '')
	{
		alert('Provide Address Name');
		return false;
	}
 	else if(trim(document.getElementById("email").value) == '')
	{
		alert('Provide Email');
		return false;
	}
	else if(trim(document.getElementById("tel").value) == '')
	{
		alert('Provide Phone');
		return false;
	}
	else if(trim(document.getElementById("content").value) == '')
	{
		alert('Provide Messege');
		return false;
	}
	else
	{
		var x=document.getElementById("email").value;
		var atpos=x.indexOf("@");
		var dotpos=x.lastIndexOf(".");
		if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
  		{
  			alert("Not a valid e-mail address");
  			return false;
  		}
	}
	
	return true;
}

function Reset()
{
 		
 	document.getElementById("leave_from_date").value = "";
	document.getElementById("leave_to_date").value = "";
	document.getElementById("txt_contuct").value = "";
	document.getElementById("txt_leave_place").value = "";
	document.getElementById("txt_leave_reson").value = "";
	document.getElementById("chk_cl").checked = true;
	document.getElementById("pk_id").value = "0";
		 
}

function get_leave_application_parameter(generic_address)
{
 		
	if(document.getElementById("leave_from_date").value == "")
	{
		alert('Provide Leave From');
		return "";
	}
	else
		generic_address += "&leave_from_date=" +  document.getElementById("leave_from_date").value;
		
	if(document.getElementById("leave_to_date").value == "")
	{
		alert('Provide Leave To');
		return "";
	}
	else
		generic_address += "&leave_to_date=" +  document.getElementById("leave_to_date").value;	
		
	if(document.getElementById("txt_contuct").value == "")
	{
		alert('Provide Contact');
		return "";
	}
	else
		generic_address += "&txt_contuct=" +  document.getElementById("txt_contuct").value;	
	
	if(document.getElementById("txt_leave_place").value == "")
	{
		alert('Provide Leave Palce');
		return "";
	}
	else
		generic_address += "&txt_leave_place=" +  document.getElementById("txt_leave_place").value;
	
	if(document.getElementById("txt_leave_reson").value == "")
	{
		alert('Provide Leave Reson');
		return "";
	}
	else
		generic_address += "&txt_leave_reson=" +  document.getElementById("txt_leave_reson").value;
		
		
	if(document.getElementById("chk_cl").checked == true) 
		generic_address += "&leave_type=1";
	else if(document.getElementById("chk_sl").checked == true) 
		generic_address += "&leave_type=3";
	else 
		generic_address += "&leave_type=2";	
	
	generic_address += "&pk_id=" + document.getElementById("pk_id").value;	
	
 
	
	return generic_address; 
}

function searchPageAddress(page_id, element_id, sub_element_id, page_no, recourd, menu_id, access_id)
{
 
	var pageAddress = "";
	var parameter = "";
	var generic_address = "";
	var location = "";
 
	
	if(page_id == 'product_list' || page_id == 'send_message')
		location = "server_script/view.php";
	else if(page_id == 'pay_slip')
		location = "pages/session_page/pay_slip_preview.php";
	else if(page_id == 'attendance')
		location = "pages/session_page/attendance_preview.php";
	else if(page_id == 'leave_search')
		location = "pages/session_page/leave_application_preview.php";
	else if(page_id == 'employee_info')
		location = "pages/session_page/employee_info_preview.php";
	else if(page_id == 'leave_application')
		location = "server_script/execute.php";	
		
 
 
	
	generic_address = location + "?page_id=" + page_id + "&element_id=" +  element_id + "&sub_element_id=" + sub_element_id + "&page_no=" + page_no + "&recoud=" + recourd + "&menu_id=" +  menu_id + "&access_id=" + access_id;
	
	switch(page_id)
	{
		case 'product_list':
		case 'client_list':
		
		case 'rating_list':
			pageAddress = generic_address + "&field=" + 6 + get_parameter(document.getElementById("search_field").value);
   		break;
		case 'send_message':
			pageAddress = generic_address + "&field=" + 6 + get_parameter(document.getElementById("search_field1").value);
   		break;
		case 'attendance':
			pageAddress = generic_address + "&field=" + 7 + get_parameter(document.getElementById("search_field_session").value);
			pageAddress = pageAddress + "&state=" + document.getElementById("dtp_date").checked;
		break;
 
		case 'leave_application':
			pageAddress = generic_address + "&field=" + 7 + get_parameter(document.getElementById("search_field_session").value);
			pageAddress = pageAddress + "&state=" + document.getElementById("dtp_date").checked;
		break;
 
 
 
 		case 'employee_info':
			pageAddress = generic_address + "&field=" + 8 + get_parameter(document.getElementById("search_field_session").value);
			pageAddress = pageAddress + "&state=" + document.getElementById("dtp_date").checked;
 
		break;
		case 'leave_search':
			pageAddress = generic_address + "&field=" + 8 + get_parameter(document.getElementById("search_field_session").value);
			pageAddress = pageAddress + "&state=" + document.getElementById("dtp_date").checked;
 
		break;
		case 'leave_apply':
			pageAddress = get_leave_application_parameter(generic_address);  
 
		break;
		case 'pay_slip':
			pageAddress = generic_address + "&field=" + 8 + get_parameter(document.getElementById("search_field_session").value);
			 
		break;
		
 	}
 
	return pageAddress;
}

function searchOperationPage(page_id, element_id, sub_element_id,  page, recourd, menu_id, access_id)
{
 	var pageAddress = "";
 
 
 
	var xmlhttp = getXmlhttp();
 	 
	xmlhttp.onreadystatechange=function()
	{	  
	 	if(page_id == 'rating_list' || page_id == 'product_list')
			document.getElementById("loder1").style.visibility="visible"
		else
			document.getElementById("loder").style.visibility="visible"
		
		if (xmlhttp.readyState == 4 && xmlhttp.status==200)
		{ 	
			if(page_id == 'send_message')
			{
				document.getElementById("childAjax").innerHTML=xmlhttp.responseText;
				reset_all();	
			}
			else if(page_id == 'attendance' || page_id == 'pay_slip' || page_id == 'employee_info' || page_id == 'leave_search' )
			{
				document.getElementById("childAjax").innerHTML=xmlhttp.responseText;
			}
			else if(page_id == 'rating_list')
			{
				document.getElementById("lbl_rating").innerHTML=xmlhttp.responseText;
			}
			else if(page_id == 'leave_application')
			{
				
				alert(xmlhttp.responseText);
				window.location.reload(); 
			}
			else
			{
				document.getElementById("cs_banner").innerHTML=xmlhttp.responseText;
				document.getElementById("cmbRecourd").value = recourd;
			}
			
			if(page_id == 'rating_list'  || page_id == 'product_list')
				document.getElementById("loder1").style.visibility="hidden";
			else
				document.getElementById("loder").style.visibility="hidden";
			
			
		}
	}
	
 	if(page_id == 'send_message')
 	{
		if(checked_validation())
			pageAddress = searchPageAddress(page_id, element_id, sub_element_id, page, recourd, menu_id, access_id);
		else
			pageAddress = "";
	}
	else
	{
		pageAddress = searchPageAddress(page_id, element_id, sub_element_id, page, recourd, menu_id, access_id);
 
	}

 
 
 
   	if(pageAddress  != "")
   	{
		xmlhttp.open("GET",pageAddress,true);
		xmlhttp.send();
   	}
	
} 

function reset_all()
{
	document.getElementById("fullname").value = '';
	document.getElementById("address").value = '';
	document.getElementById("email").value = '';
	document.getElementById("tel").value = '';
	document.getElementById("content").value = '';
 
}
function generateAsciiCharacterString(prefix)
{
	var ascii_character = "";
	
	for(var i = 0; i < (prefix.length); i++)
		ascii_character += (prefix.charCodeAt(i) + "|");
		 
 	return ascii_character;
}

function open_generic_report(page_id, element_id, sub_element_id, titel, count)
{
 
	
 	var address = "report_engine/index.php?page_id=" + page_id + "&element_id=" + element_id + "&sub_element_id=" + sub_element_id + "&titel=" +  titel + "&query=" +  generateAsciiCharacterString(document.getElementById("query").value) + "&count=" + count;
 
	window.open(address);	
}

function download()
{
	var parameter = "?query=" + document.getElementById("query").value + "&file_name=" + document.getElementById("file_name").value;
	
	if(parameter != "")	
 		window.open('dowanload.php'+ parameter, 'download',                              
	'width=50,height=50,resizable=no,location=no,left=50%,top=50%,scrollbars=yes');
}
 
 