﻿/*$(document).ready(function(){
	//hide the all of the element with class msg_body
	$(".msg_body").hide();
	//toggle the componenet with class msg_body
	$(".msg_head").click(function(){
		//$(".msg_body").hide();
		$(this).next(".msg_body").slideToggle(300);
		
	});
	
	
	$(".msg_head1").click(function(){
								  // $(".msg_body1").hide();
		$(this).next(".msg_body1").slideToggle(300);
			
	});
	
	
	
	
});*/
var intTextBox=1;
var intTextBoxs=1;
var intTextBox2=1;
function GetXmlHttpObject()
 {
   var objXMLHttp=null;
   
   if (window.XMLHttpRequest)
      objXMLHttp=new XMLHttpRequest();
   else if (window.ActiveXObject)
      objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
   
   return objXMLHttp
 }
function hashCodes(page)
{
	//location.replace("index.php?page=Welcome");
	location.href="index.php?page="+page;
	
	//setDivContent('content',page);
	
}
function setDivContent(divcontent,page)
{
	page = "page/"+page+".php";
	
	//window.location.hash="index.php?page=Welcome";
	//document.getElementById(divcontent).innerHTML ="";

	//tabdropdown.init(even, index);
	//page = page+".php";
	var http=GetXmlHttpObject()
	if (http==null)
     {
		alert ("Browser does not support HTTP Request")
		return false;
     }
	
var url =page;

	http.open("GET",url,true);
	
    http.onreadystatechange = 
	 function()
	  {
		if (http.readyState == 4)
		 {
			//document.getElementById(divcontent).innerHTML ="Loading";
			if(http.status==200) 
			{
			
				var response = http.responseText;
		

		
		
				if (response != "")
				{
							document.getElementById(divcontent).innerHTML=response;
						
				if(page=="page/Welcome.php")
				{
	
		
           
     
				}
				
				
					
				}
					else
					{
						
						            
						}
			}
		 }
	  }
    http.send(null);
	return false;
	
}
function adminSetContentDiv(divcontent,page)
{
	var http=GetXmlHttpObject()
	if (http==null)
     {
		alert ("Browser does not support HTTP Request")
		return false;
     }
	
var url =page;

	http.open("GET",url,true);
	
    http.onreadystatechange = 
	 function()
	  {
		if (http.readyState == 4)
		 {
			if(http.status==200) 
			{
				var response = http.responseText;
		
				if (response != "")
				{
		
		         document.getElementById(divcontent).innerHTML="";			
				document.getElementById(divcontent).innerHTML=response;	
			
				
	$(function() {
		$("#tabs").tabs();
	});

	$(function() {
		$("#datepicker").datepicker();
	});

if(page=="php/events.php")
		{
		//createEditor();
		//removeEditor();
		removeEditor();
	createEditor();
		
		}	
				
		}
			}
		 }
	  }
    http.send(null);
	return false;
}



var editor;
function reloadEditor()
{
	
window.location ="index.php";
adminSetContentDiv('adminContent','php/events.php');



	
}
function createEditor()
{
	if ( editor )
		return;

	var html = document.getElementById( 'editorcontents' ).innerHTML;

	// Create a new editor inside the <div id="editor">
	editor = CKEDITOR.appendTo( 'editor' );
	editor.setData( html );

	// This sample may break here if the ckeditor_basic.js is used. In such case, the following code should be used instead:
	/*
	if ( editor.setData )
	editor.setData( html );
	else
	CKEDITOR.on( 'loaded', function()
	{
	editor.setData( html );
	});
	*/
}

function removeEditor()
{
	if ( !editor )
		return;

	// Retrieve the editor contents. In an Ajax application, this data would be
	// sent to the server or used in any other way.
	document.getElementById( 'editorcontents' ).innerHTML = editor.getData();
	document.getElementById( 'contents' ).style.display = '';

	// Destroy the editor.
	editor.destroy();
	editor = null;
}
function str_replace (search, replace, subject, count) {
    // Replaces all occurrences of search in haystack with replace  
    // 
    // version: 909.322
    // discuss at: http://phpjs.org/functions/str_replace    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Gabriel Paderni
    // +   improved by: Philip Peterson
    // +   improved by: Simon Willison (http://simonwillison.net)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)    // +   bugfixed by: Anton Ongson
    // +      input by: Onno Marsman
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    tweaked by: Onno Marsman
    // +      input by: Brett Zamir (http://brett-zamir.me)    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   input by: Oleg Eremeev
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Oleg Eremeev
    // %          note 1: The count parameter must be passed as a string in order    // %          note 1:  to find a global variable in which the result will be given
    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
    // *     returns 1: 'Kevin.van.Zonneveld'
    // *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
    // *     returns 2: 'hemmo, mars'    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }
     for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}        }
    }
    return sa ? s : s[0];
}

function addElement()
{

intTextBox2 = intTextBox2 + 1;
var contentID = document.getElementById('coursediv');
var newTBDiv = document.createElement('div');
newTBDiv.setAttribute('id','strText'+intTextBox);
newTBDiv.style.width = "350px";
newTBDiv.innerHTML = "<br><br><table width='550px' ><tr><td align='right' rowspan='2'>"+intTextBox2+".</td><td align='left'><b>Position&nbsp;Name:</b></td colspan='2'><input type='text' id='PosName" + intTextBox + "' name='PosName" + intTextBox + "' size='80'></td></tr><tr><td><b>Position&nbsp;Description:</b></td><td><input type='text' id='PosDesc" + intTextBox + "' name='PosDesc" + intTextBox + "' size='80' ></td><td><span id='"+intTextBox+"' onclick=removeElement('"+intTextBox+"')><a>[x]</a></span></td></tr></table>";
contentID.appendChild(newTBDiv);
intTextBox = intTextBox + 1;
calcHeight2();
}

//FUNCTION TO REMOVE TEXT BOX ELEMENT
function removeElement(i)
{
dimHeight2();
var contentID = document.getElementById('coursediv');
contentID.removeChild(document.getElementById('strText'+i));
if(document.dynamictext.length==4)
{
intTextBox2=1;
}
}





function RegistrationEvent()
{
var http=GetXmlHttpObject()
	if (http==null)
     {
		alert ("Browser does not support HTTP Request")
		return false;
     }
	
var url ="page/EventRegistration.php";


	http.open("GET",url,true);
	
    http.onreadystatechange = 
	 function()
	  {
		if (http.readyState == 4)
		 {
			if(http.status==200) 
			{
				var response = http.responseText;
		
			//	if (response != "")
				//{
				
				//document.getElementById(divcontent).innerHTML=response;			
				document.getElementById("content").innerHTML=response
					
			//	}
				//	else
					//{
						
						            
						//}
			}
		 }
	  }
    http.send(null);
	return false;
	
}



function pickCom(textbox,id)
{
	
	document.getElementById(textbox).value="";
	document.getElementById(textbox).value=id;
}

function nextRegi(txt,div)
{
	var text = document.getElementById(txt).value;
	if (text=="")
	{
		document.getElementById(div).innerHTML = "<h2><font color='red'><b>Error</b>!Please Select A Company</font></h2>";
		calcHeight1();
	}
	else
	{
		window.location = "NextRegi.php?id="+text;
	
	}
}


function calcHeight()
{ 
//find the height of the internal pages
var the_height=
    document.getElementById('frame').contentWindow.
      document.body.scrollHeight;
	  var the_width=
    document.getElementById('frame').contentWindow.
      document.body.scrollWidth;
	  var h=
    document.getElementById('frame').contentWindow.
      document.body.id;
   // document.getElementById('frame').contentWindow.
    if(h=="registration")
	{
		document.getElementById('frame').height = the_height;
	}
	else
	{
	//document.body.id;
	document.getElementById('frame').height = the_height;
	document.getElementById('frame').style.border = "none";
	document.getElementById('frame').width = 722;

	}
}
//PROCUREMENT TRAINING
function addElementTrain()
{

if(intTextBoxs<=4)
{

intTextBox2 = intTextBox2 + 1;
var contentID = document.getElementById('Traindiv');
var newTBDiv = document.createElement('div');
newTBDiv.setAttribute('id','strTexts'+intTextBoxs);
newTBDiv.style.width = "100%";
newTBDiv.innerHTML = "<table style='border:none;'><tr><td style='border:none;'><input type='text' id='Proc" + intTextBoxs + "' name='Proc" + intTextBoxs + "' size='35'><br><i>Procurement Related Training</i></td><td style='border:none;'><input type='text' id='Per" + intTextBoxs + "' name='Per" + intTextBoxs + "' size='12' ><br><i>Duration/Date of Training</i></td><td style='border:none;'><input type='text' id='Con" + intTextBoxs + "' name='Con" + intTextBoxs + "' size='20' ><br><i>Conducted By</i></td><td style='border:none;'><span id='"+intTextBoxs+"' onclick=removeElementTrain('"+intTextBoxs+"')><a>[x]</a></span></td></tr></table>";
contentID.appendChild(newTBDiv);
calcHeight1();
intTextBoxs = intTextBoxs + 1;
}

}

function removeElementTrain(i)
{

var contentID = document.getElementById('Traindiv');
contentID.removeChild(document.getElementById('strTexts'+i));
intTextBoxs = intTextBoxs-1;
dimHeight1();
}
//END OF PROCUREMENT TRAINING



function addElementOrg()
{

if(intTextBox<=4)
{

intTextBox2 = intTextBox2 + 1;
var contentID = document.getElementById('coursediv');
var newTBDiv = document.createElement('div');
newTBDiv.setAttribute('id','strText'+intTextBox);
newTBDiv.style.width = "350px";
newTBDiv.innerHTML = "<table style='border:none;'><tr><td style='border:none;'><input type='text' id='Org" + intTextBox + "' name='Org" + intTextBox + "' size='35'><br><i>Procurement Related Positions</i></td><td style='border:none;'><input type='text' id='Pos" + intTextBox + "' name='Pos" + intTextBox + "' size='12' ><br><i>Period Covered</i></td><td style='border:none;'><span id='"+intTextBox+"' onclick=removeElementOrg('"+intTextBox+"')><a>[x]</a></span></td></tr></table>";
contentID.appendChild(newTBDiv);
calcHeight1();
intTextBox = intTextBox + 1;
}

}


function calcHeight2()
{

adminheight=parent.document.getElementById('adminframe').scrollHeight;
adminheight=adminheight+100;
parent.document.getElementById('adminframe').height=adminheight;
}

function dimHeight2()
{

adminheight=parent.document.getElementById('adminframe').scrollHeight;
adminheight=adminheight-100;
parent.document.getElementById('adminframe').height=adminheight;
}




function calcHeight1()
{

adminheight=parent.document.getElementById('frame').scrollHeight;
adminheight=adminheight+100;
parent.document.getElementById('frame').height=adminheight;
}

function dimHeight1()
{

adminheight=parent.document.getElementById('frame').scrollHeight;
adminheight=adminheight-100;
parent.document.getElementById('frame').height=adminheight;
}

//FUNCTION TO REMOVE TEXT BOX ELEMENT
function removeElementOrg(i)
{
dimHeight1();
var contentID = document.getElementById('coursediv');
contentID.removeChild(document.getElementById('strText'+i));
intTextBox = intTextBox-1;
}

function EnableButton()
{
	if(document.getElementById("agree").checked==true)
	{
		document.getElementById("proceed").disabled = false;
	}
	else
	{
		document.getElementById("proceed").disabled = true;
	}
}
	//]]>
function saveComment(div,name,con)
{
	var Cname = document.getElementById(name).value;
	var content = document.getElementById(con).value;
	var divMsg = document.getElementById(div);
	
	
	if(Cname==""&&content=="")
	{
	divMsg.style.border="1px solid red";
	divMsg.style.backgroundColor = "white";
	divMsg.style.color = "red";
	divMsg.innerHTML='<b style=color:red;font-size:14px;>Please Fill up the fields before Submiting.</b>';
	}
	else
	{
	
	
	
	var http=GetXmlHttpObject()
	if (http==null)
     {
		alert ("Browser does not support HTTP Request")
		return false;
     }
	
var url ="../php/query/SaveComments.php";
url = url+"?Cname="+Cname+"&txt="+content;

	http.open("GET",url,true);
	
    http.onreadystatechange = 
	 function()
	  {
		if (http.readyState == 4)
		 {
			if(http.status==200) 
			{
				var response = http.responseText;
				if(response==1)
				{
				divMsg.style.border="1px solid green";
				divMsg.style.backgroundColor = "white";
				divMsg.style.color = "green";
				divMsg.innerHTML='<b style=color:green;font-size:14px;>Your Comment has been Successfully Submitted.</b>';
				}
				else
				{
					divMsg.style.border="1px solid red";
					divMsg.style.backgroundColor = "white";
					divMsg.style.color = "red";
					divMsg.innerHTML=response;
				}
			}
		 }
	  }
    http.send(null);
	return false;

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	}
}
