

// JavaScript Document

/*
	SIGNATURE
	
	Vikramjit Singh Rooprai
	September 27th, 2008
	
	This document shall hold all functions related to AJAX.
*/


/**********************************************************/


var screenW = 1000, screenH = 768;
if (parseInt(navigator.appVersion)>3) {
 screenW = screen.width;
 screenH = screen.height;
}
else if (navigator.appName == "Netscape" 
    && parseInt(navigator.appVersion)==3
    && navigator.javaEnabled()
   ) 
{
 var jToolkit = java.awt.Toolkit.getDefaultToolkit();
 var jScreenSize = jToolkit.getScreenSize();
 screenW = jScreenSize.width;
 screenH = jScreenSize.height;
}



function getHTTPObject() { 
	var XMLHttpRequestObject=false; 
		if(window.XMLHttpRequest) { 
			// Opera 8.0+, Firefox, Safari 
			XMLHttpRequestObject=new XMLHttpRequest(); 
		 } 
		else if(window.ActiveXObject) { 
			//Internet Explorer 
			XMLHttpRequestObject=new ActiveXObject("Microsoft.XMLHTTP"); 
			if(!XMLHttpRequestObject){
				XMLHttpRequestObject=new ActiveXObject("Msxml2.XMLHTTP"); 
			}
		 } 
		else{ 
			alert("Your Browser is not compatible to use this application"); 
		 } 
	return XMLHttpRequestObject; 
} 


var Hash = '';

function getPage(CallPage, Title) {

	 var http = getHTTPObject(); 
	 Hash = CallPage.replace('Ajaxpages/','');
	 Hash = Hash.replace('AjaxPages/','');

	$('ResultDiv').morph({
					 	'opacity': '0',
						'duration': 'short'
						 });

//	$('ResultDiv').innerHTML = "<div style='width:100%; height:100%; text-align:center; vertical-align:middle;'><img src='images/Loader.gif' /></div>";

	var timestamp='';

	
	if(CallPage == '' || CallPage == null)
	 {	
	 	// If no URL is specified, return the control
		return;
	 }

	//Cache work around
	var datevar = new Date();
	var timevar = datevar.getTime();
	timestamp= 'TEMP=' + timevar + Math.random();	
	if (CallPage.indexOf("?") > 0)
	 {
		CallPage = CallPage + '&' + timestamp;
	 }
	else
	 {
		CallPage = CallPage + '?' + timestamp;
	 }
	
	
	//here passing this URL to show that page in the required DIV
	http.open("GET", CallPage, true); 
	 
	http.onreadystatechange = function (){
			if (http.readyState == 4) {		
				$('ResultDiv').innerHTML = http.responseText; 
				window.location.hash = escape(encrypt(Hash));
				setTimeout("$('ResultDiv').morph({'opacity': '1'});",300);
				setTimeout('setTitle("' + Title + '");',500);
			}
		};
	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	http.send(null);	
 } 

function removeTitle()
 {
	 $('PageTitle').morph({'opacity': '0'});
	 $('Loader').morph({'opacity':'1'});
 }

function setTitle(txt)
 {
	 $('PageTitle').innerHTML = txt;
	 $('PageTitle').morph({'opacity': '1'});
	 $('Loader').morph({'opacity':'0'});
 }


function LoadSection(Sec)
 {	 
 	 removeTitle();
	 if(Sec.indexOf('AjaxPages') >= 0)
	  {
		  
		  if(Sec.indexOf('default.asp') >= 0)
		   {
		   		getPage(Sec,'HOME');
		   }
		  else if(Sec.indexOf('about.asp') >= 0)
		   {
			   getPage(Sec,'ABOUT');
		   }
		  else if(Sec.indexOf('contact.asp') >= 0)
		   {
			   getPage(Sec,'CONTACT ME');
		   }
		  else if(Sec.indexOf('portfolio.asp') >= 0)
		   {
			   getPage(Sec,'PORTFOLIO');
		   }
		  else if(Sec.indexOf('getPhotos.aspx') >= 0)
		   {
			   Sec = Sec.replace("AjaxPages/","");
			   getPage(Sec,'GALLERY');
		   }
		  else if(Sec.indexOf('blog.asp') >= 0)
		   {
			   getPage(Sec,'BLOG');
		   }
		  else if(Sec.indexOf('messenger.asp') >= 0)
		   {
			   getPage(Sec,'MESSENGER');
		   }
		  
	  }	 
	 else if(Sec == 'HOME' || Sec == '')
	  {
		  getPage('AjaxPages/default.asp','HOME');
	  }
	 else if(Sec == 'ABOUT')
	  {
		  getPage('AjaxPages/about.asp','ABOUT ME');
	  }
	 else if(Sec == 'BLOG')
	  {
		  getPage('AjaxPages/blog.asp','BLOG');
	  }
	 else if(Sec == 'CONTACT')
	  {
		  getPage('AjaxPages/contact.asp','CONTACT ME');
	  }
	 else if(Sec == 'PORTFOLIO')
	  {
		  getPage('AjaxPages/portfolio.asp','PORTFOLIO');
	  }
	 else if(Sec == 'GALLERY')
	  {
		  getPage('getPhotos.aspx','GALLERY');
	  }	
	  else if(Sec == 'MESSENGER')
	   {
		   getPage('messenger.asp','MESSENGER');
	   }
 }
 
 function changeQuote()
  {
	  $('TipOfDayTitle').morph({opacity:0});
	  $('TipOfDayContent').morph({opacity:0});
	  
	  var timestamp='';

	var CallPage = 'Ajaxpages/getRandomQuote.asp?Items=1';
	
	if(CallPage == '' || CallPage == null)
	 {	
	 	// If no URL is specified, return the control
		return;
	 }

	var http = getHTTPObject(); 

	//Cache work around
	var datevar = new Date();
	var timevar = datevar.getTime();
	timestamp= 'TEMP=' + timevar + Math.random();	
	if (CallPage.indexOf("?") > 0)
	 {
		CallPage = CallPage + '&' + timestamp;
	 }
	else
	 {
		CallPage = CallPage + '?' + timestamp;
	 }
	
	
	//here passing this URL to show that page in the required DIV
	http.open("GET", CallPage, true); 
	 
	http.onreadystatechange = function (){
			if (http.readyState == 4) {		
				parseXML(http.responseText);
				//$('TipOfDayContent').innerHTML = http.responseText; 
				setTimeout("$('TipOfDayContent').morph({'opacity': '1'});",500);
				setTimeout("$('TipOfDayTitle').morph({'opacity': '1'});",500);
			}
		};
	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	http.send(null);
	  
	  
  }
  
function parseXML(txt)
	{
		var xmlDoc;
		if (window.ActiveXObject)
		  {// code for IE
		  	xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async=false;
			xmlDoc.loadXML(txt);
		  }
		else if (document.implementation.createDocument)
		  {// code for Firefox, Mozilla, Opera, etc.
		  var parser=new DOMParser();
			xmlDoc=parser.parseFromString(txt,"text/xml");
		  }
		else
		  {
		  alert('Your browser cannot handle this script');
		  }
		
		var x=xmlDoc.getElementsByTagName("item");
		TotalStates = x.length;
		for (var i=0;i<x.length;i++)
 		 {
		 	$('TipOfDayTitle').innerHTML =  x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue.replace('+',' ').replace('+',' ') + ' Says...';
			$('TipOfDayContent').innerHTML =  x[i].getElementsByTagName("description")[0].childNodes[0].nodeValue.replace('+',' ').replace('+',' ');
			//alert(x[i].getElementsByTagName("description")[0].childNodes[0].nodeValue.replace('+',' ').replace('+',' '));
			//$('TipOfDayContent') =  x[i].getElementsByTagName("description")[0].childNodes[0].nodeValue.replace('+',' ').replace('+',' ');
		 }

	}  
	

function MouseOver(obj)
 {
	 $(obj).morph({'background-color':'#1e1644', 'color': '#ffffff'});
 }

function MouseOut(obj)
 {
	 $(obj).morph({'background-color':'#EAE7FC', 'color': '#322d50'});
 }
 
 
 function getPhotos(SetID)
  {
	  getPage('getPhotos.aspx?SetID=' + SetID,'GALLERY');
  }
  
  
  
function getRecentPhotos()
  {
	  var timestamp='';

	var CallPage = 'getPhotos.aspx?Show=Recent';
	
	if(CallPage == '' || CallPage == null)
	 {	
	 	// If no URL is specified, return the control
		return;
	 }

	var http = getHTTPObject(); 

	//Cache work around
	var datevar = new Date();
	var timevar = datevar.getTime();
	timestamp= '&TEMP=' + timevar + Math.random();	
	if (CallPage.indexOf("?") > 0)
	 {
		CallPage = CallPage + '&' + timestamp;
	 }
	else
	 {
		CallPage = CallPage + '?' + timestamp;
	 }
	
	
	//here passing this URL to show that page in the required DIV
	http.open("GET", CallPage, true); 
	 
	http.onreadystatechange = function (){
			if (http.readyState == 4) {		
				$('RightBar').innerHTML = http.responseText; 				
			}
		};
	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	http.send(null);
	  
	  
  } 
  
function trapEnter(e,r,Sec)
 {
   if(e.keyCode == 13)
	{
		if(Sec == 'MSNGR')
		 {
			 ValidateName();
		 }
	} 
 }
 
function ValidateName()
 {
	 CallPage = "Ajaxpages/ValidateName.asp?VALNM=" + escape(document.getElementById('txtName').value);
	 getPage(CallPage, "MESSENGER");
 }
 
function ValidateAnswer(ID)
 {

		  val = -1
		  if($('op1') != undefined)
		   {
			   if($('op1').checked)
			    {
					val = 1;
				}
		   }
		  
		   if($('op2') != undefined)
		   {
			   if($('op2').checked)
			    {
					val = 2;
				}
		   }
		   
		   if($('op3') != undefined)
		   {
			   if($('op3').checked)
			    {
					val = 3;
				}
		   }
		   
		   if($('op4') != undefined)
		   {
			   if($('op4').checked)
			    {
					val = 4;
				}
		   } 
		  
		  CallPage = "Ajaxpages/ValidateAnswer.asp?ID=" + ID + "&OP=" + val;
		  getPage(CallPage, "MESSENGER");

 }

 
function getMessage(ID)
 {
	 CallPage = "Ajaxpages/readMessage.asp?ID=" + ID
	 getPage(CallPage, "MESSENGER");
 }
 
function SaveMessageResponse(ID, Reader)
 {
	 CallPage = "MSGID=" + ID + "&MSGBY=" + encodeURI(Reader) + "&txtResponse=" + encodeURI($('txtResponse').value);
	 
	 
	 
	 var http = getHTTPObject(); 
	 Hash = CallPage.replace('Ajaxpages/','');
	 Hash = Hash.replace('AjaxPages/','');

	$('ResultDiv').morph({
					 	'opacity': '0',
						'duration': 'short'
						 });

//	$('ResultDiv').innerHTML = "<div style='width:100%; height:100%; text-align:center; vertical-align:middle;'><img src='images/Loader.gif' /></div>";

	var timestamp='';

	
	if(CallPage == '' || CallPage == null)
	 {	
	 	// If no URL is specified, return the control
		return;
	 }
/*
	//Cache work around
	var datevar = new Date();
	var timevar = datevar.getTime();
	timestamp= 'TEMP=' + timevar + Math.random();	
	if (CallPage.indexOf("?") > 0)
	 {
		CallPage = CallPage + '&' + timestamp;
	 }
	else
	 {
		CallPage = CallPage + '?' + timestamp;
	 }*/
	
	
	//here passing this URL to show that page in the required DIV
	http.open("POST", "AJAXPAGES/SaveMessageResponse.asp", true); 
	 
	http.onreadystatechange = function (){
			if (http.readyState == 4) {		
				$('ResultDiv').innerHTML = http.responseText; 
				window.location.hash = escape(encrypt(Hash));
				setTimeout("$('ResultDiv').morph({'opacity': '1'});",300);
			}
		};
	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", CallPage.length);
	http.send(CallPage);
	 
	 
 }