 // AJAX implementation

// GLOBAL VARIABLES

var rec_to_show = 8;			// holds the number of records to show per page
var active_page = 1;			// the first page to show ALWAYS 1
var container = 'container';	// the id of the thumbs container
var _loading = false; 
var sn= new Array();
var global_code = 'MS';                //Code to determine the Selected social networking
var wmode_change = false;         //code to change wmode for flash object
var page_cooki = new jscookie('ajax_page',1); //setting jscookie for ajax pagination on page refresh or while using browser back button

var show_all_by = '';		//Holds HTML string for show all.
var showAllArr = new Array();
//-----------------------------
//-----------------------------------------------------------------------------

function show_all(){
	//alert(arguments[0]);
	show_all_by = arguments[0];

	//if ajax is not supported then follow the normal link	
	if (! IS_AJAX_ENABLED) {		
	    return true;
	}

	if(typeof(total_rec) == 'undefined')
		return true;

	active_page = 1;
	//alert(num_pages);
	show_loading();
	if(showAllArr.length > 0){
		var output = buildShowAllHTML(show_all_by);
		var nav_bar = build_pagination_bar(0);
		document.getElementById('container').innerHTML = '';	
		document.getElementById('container').innerHTML = output;		
		document.getElementById('pagin_head').innerHTML = nav_bar;
		document.getElementById('pagin_foot').innerHTML = nav_bar;			
		//hide the loading message
		hide_loading();
		try{
			DiwaliBanner.changeAnchor();
		}catch(ex1){ }
		// refresh adverts
		refreshAds();
	}
	else{
		callAjax();
	}
	
	if(show_all_by == 'G')
		var cookie_val =  "G#" + location.href;
	else if(show_all_by == 'L')
		var cookie_val =  "L#" + location.href;
	window.page_cooki.write(cookie_val);
	return false;


}

function callAjax(){
	var page_name = getPageName();	

	var ajax_obj = new AJAX();
	ajax_obj.init('true','GET','XML',page_name,'',createShowAllContent);
	ajax_obj = null;
}

function createShowAllContent(xml){
	// get the responseXML
	// get the image collection for xml response
	if (xml == null) {
	    return;
	}else {		
		var ecard = xml.getElementsByTagName('ecard');		
		for (var i=0;i<ecard.length;i++) {
			var count = (active_page - 1) * rec_to_show + i;
			showAllArr[count] = new Array();			
			showAllArr[count]['image'] = ecard[i].getElementsByTagName("image")[0].firstChild.nodeValue;
			showAllArr[count]['thumblink'] = ecard[i].getElementsByTagName("thumblink")[0].firstChild.nodeValue;
			showAllArr[count]['redline'] = ecard[i].getElementsByTagName("redline")[0].firstChild.nodeValue;
			showAllArr[count]['greenline'] = ecard[i].getElementsByTagName("greenline")[0].firstChild.nodeValue;
			//showAllArr[count]['label'] = ecard[i].getElementsByTagName("label")[0].firstChild.nodeValue;
			showAllArr[count]['label'] = (ecard[i].getElementsByTagName("label")[0].hasChildNodes())?ecard[i].getElementsByTagName("label")[0].firstChild.nodeValue:'';
			showAllArr[count]['no_cards'] = (ecard[i].getElementsByTagName("no_cards")[0].hasChildNodes())?ecard[i].getElementsByTagName("no_cards")[0].firstChild.nodeValue:'';

			showAllArr[count]['new'] = ecard[i].getElementsByTagName("new")[0].firstChild.nodeValue;
			showAllArr[count]['alt'] = (ecard[i].getElementsByTagName("alt")[0].hasChildNodes())?ecard[i].getElementsByTagName("alt")[0].firstChild.nodeValue:'';
			
			if(ecard[i].getElementsByTagName("flloader")[0].hasChildNodes()){
				showAllArr[count]['flloader'] = unescape(ecard[i].getElementsByTagName("flloader")[0].firstChild.nodeValue);
				//showAllArr[count]['flloader'] = showAllArr[count]['flloader'].split("%3F")[0];
			}else{
				showAllArr[count]['flloader'] = '';
			}
			showAllArr[count]['flash_details'] = (ecard[i].getElementsByTagName("flash_details")[0].hasChildNodes())?ecard[i].getElementsByTagName("flash_details")[0].firstChild.nodeValue:'';	
			showAllArr[count]['newimagepath'] = (ecard[i].getElementsByTagName("newimagepath")[0].hasChildNodes())?ecard[i].getElementsByTagName("newimagepath")[0].firstChild.nodeValue:'';	

			Preload(new Array(showAllArr[count]['image']));
		}		
	}

	if(typeof(total_rec) != 'undefined' && parseInt(total_rec) > 0){
		var num_pages = Math.ceil(total_rec/rec_to_show); // calculate the number of pages
		//alert(num_pages);
		if(active_page < num_pages){
			active_page++;
			//alert(active_page);
			callAjax();
		}else{
			//alert('1-->'+show_all_by);
			var output = buildShowAllHTML(show_all_by);
			var nav_bar = build_pagination_bar(0);
			document.getElementById('container').innerHTML = '';	
			document.getElementById('container').innerHTML = output;		
			document.getElementById('pagin_head').innerHTML = nav_bar;
			document.getElementById('pagin_foot').innerHTML = nav_bar;			

			//hide the loading message
			hide_loading();
			try{
				DiwaliBanner.changeAnchor();
			}catch(ex1){ }

			// refresh adverts
			refreshAds();
		}
	}
	else
		return true;
}

function buildShowAllHTML(){
	var tableHTML = new Array();	
	var thumb_image_path = 'http://img.123greetings.com/thumbs/'; // thumb image source path
	//alert('2-->'+arguments[0].toUpperCase());
	
	if(arguments[0].toUpperCase() == 'G'){
		var disp_thumb_no = (screen.width>=1024) ? 4 : 3;	
		tableHTML[tableHTML.length] = '<table border="0" cellspacing="2" cellpadding="2" width="100%" align="center">';
		for(var i=0;i<showAllArr.length;i++){
			var alttxt = (showAllArr[i]['alt'] != '')?showAllArr[i]['alt']:showAllArr[i]['redline'] + '  '+showAllArr[i]['greenline'];
			alttxt = alttxt.replace(/\'/g,"\'");
			if(showAllArr[i]['label'] != '')
				alttxt += ' ['+getType(showAllArr[i]['label'])+']';
	
			if(!(i%disp_thumb_no))
				tableHTML[tableHTML.length] = '<tr>';
	
				tableHTML[tableHTML.length] = '<td align="center">';
				tableHTML[tableHTML.length] = '<table width="140" height="140" cellspacing="1" cellpadding="1" border="0"><tbody>';
				tableHTML[tableHTML.length] = '<tr><td valign="middle" background="http://img.123greetings.com/images/imgback_thumb.gif" align="center" style="border-color: transparent; background-repeat: no-repeat;">';
				tableHTML[tableHTML.length] = '<a title="'+alttxt+'" href="'+showAllArr[i]['thumblink']+'">';
				tableHTML[tableHTML.length] = '<img width="115" height="115" border="0" align="absmiddle" alt="'+alttxt+'" src="'+thumb_image_path+showAllArr[i]['image']+'"/>';
			tableHTML[tableHTML.length] = '</a>';
			tableHTML[tableHTML.length] = '</td></tr>';
			tableHTML[tableHTML.length] = '</tbody></table>';

			if(i%disp_thumb_no == (disp_thumb_no -1))
				tableHTML[tableHTML.length] = '</tr>';
		}

		if(showAllArr.length%disp_thumb_no){
			for(var i=showAllArr.length%disp_thumb_no+1;i<=4;i++){
				tableHTML[tableHTML.length] = '<td align="center">&nbsp;</td>';
			}
			tableHTML[tableHTML.length] = '</tr>';
		}

		tableHTML[tableHTML.length] = '</table>';
	}
	else if(arguments[0].toUpperCase() == 'L'){
		var disp_thumb_no = 2;
		sn.length=0;

		tableHTML[tableHTML.length] = '<table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">';
		tableHTML[tableHTML.length] = '<tr><td align="center" colspan="4">&nbsp;</td></tr>';

		for(var i=0;i<showAllArr.length;i++){

			if(showAllArr[i]['label'] != ''){
				//***********************************************************************
				//var type = getType(showAllArr[i]['label']);
				var im_type = showAllArr[i]['label'];
				var image_path = (showAllArr[i]['newimagepath'] == '')?'http://img.123greetings.com/eventsnew/'+showAllArr[i]['image']:showAllArr[i]['newimagepath']+showAllArr[i]['image'];
				var thumb_link = showAllArr[i]['thumblink'];
				var floader = showAllArr[i]['flloader'];
				var flashDetails = showAllArr[i]['flash_details'];
				var temp = flashDetails.split('#');

				if(typeof floader.split("%3F")[1] != 'undefined' && floader.split("%3F")[1] != ''){
					var mus = floader.split("%3F")[1];
					mus = mus.split('=')[0] + '=http://img.123greetings.com' + mus.split('=')[1] + '=';
					floader = floader.split("%3F")[0] + '?' + mus;
				}else{
					floader = floader.split("%3F")[0];
				}
				
				
				if (im_type.toUpperCase() == 'F') {					
					image_path = image_path.replace(/eventsnew/,'thumbs');
					sn[i]={'thumb' : image_path,'path' : thumb_link,'type' : "F",'flash_url':floader+"#"+temp[1]+","+temp[2]};				
				}else if (im_type.toUpperCase() == 'I') {
					var is_flash = (flashDetails.indexOf('.swf') > -1) ? true : false;
					
					if (is_flash) {
						image_path = image_path.replace(/eventsnew/, 'thumbs');
					}

					var loader_path = '';
					if(floader != '') {
						loader_path = floader+"#"+temp[1]+","+temp[2];
					}else {
						loader_path = flashDetails;
					}
					//image type
					var im_type = is_flash ? "F" : "A";

					sn[i] = {
						'thumb': image_path, 
						'path' : thumb_link, 
						'type' : im_type,
						'flash_url' : loader_path
					};
				}else{				
					sn[i]={'thumb': image_path,'path': thumb_link,'type': "A",'flash_url': ''};				
				}
			//***********************************************************************
			}
			
			var alttxt = (showAllArr[i]['alt'] != '')?showAllArr[i]['alt']:showAllArr[i]['redline'] + '  '+showAllArr[i]['greenline'];
			alttxt = alttxt.replace(/\'/g,"\'");
			alttxt = alttxt.replace(/<br>/g,'');

			var newImg = (showAllArr[i]['new'] > 0)?'<img src="http://img.123greetings.com/homeimages/new2.gif" border="0" width="23" height="9" alt="New">':'';

			if(!(i%disp_thumb_no))
				tableHTML[tableHTML.length] = '<tr>';
			
			tableHTML[tableHTML.length] = '<td align="center">';
			tableHTML[tableHTML.length] = '<table width="140" height="140" cellspacing="1" cellpadding="1" border="0"><tbody><tr><td background="http://img.123greetings.com/images/imgback_thumb.gif" align="center">';
			tableHTML[tableHTML.length] = '<a title="'+alttxt+'" href="'+showAllArr[i]['thumblink']+'"><img width="115" height="115" border="0" align="absmiddle" alt="'+alttxt+'" src="'+thumb_image_path+showAllArr[i]['image']+'"/></a>';
			tableHTML[tableHTML.length] = '</td></tr>';
			tableHTML[tableHTML.length] = '</tbody></table>';
			tableHTML[tableHTML.length] = '</td>';

			tableHTML[tableHTML.length] = '<td width="21%" valign="middle">';
			tableHTML[tableHTML.length] = '<a href="'+showAllArr[i]['thumblink']+'"><font size="2" face="MS SANS SERIF" color="#cc0000"><b>'+showAllArr[i]['redline']+'</b></font></a><br/>';
			tableHTML[tableHTML.length] = '<a href="'+showAllArr[i]['thumblink']+'"><font size="1" face="MS SANS SERIF" color="#006600">'+showAllArr[i]['greenline']+'<br/>';
			//alert(parseInt(showAllArr[i]['no_cards']));
			if(parseInt(showAllArr[i]['no_cards']) > 0)
				tableHTML[tableHTML.length] = '<b>[ '+showAllArr[i]['no_cards']+' Cards ]</b></font></a>';
			else
				tableHTML[tableHTML.length] = '<b>[ '+getType(showAllArr[i]['label'])+' ]</b></font></a>';

			tableHTML[tableHTML.length] = '&nbsp;'+newImg+'&nbsp;<br/><br/>';
			
			if(showAllArr[i]['label'] != ''){
				try{
					var sn_src = window.config[window.code].img_url.split('#')[0];
					var sn_imgW = window.config[window.code].img_url.split('#')[1].split(',')[0];
					var sn_imgH = window.config[window.code].img_url.split('#')[1].split(',')[1];
				}catch(ex1){
					var sn_src = 'http://img.123greetings.com/images/social_networking/buttons/add_space.gif';
					var sn_imgW = '102';
					var sn_imgH = '16';
					window.code = global_code;
				}			
				tableHTML[tableHTML.length] = '<img width="'+ sn_imgW +'" height="'+ sn_imgH +'" border="0" style="cursor: pointer;" onclick="dhtml.showBox1(event,'+(i+1)+')" title="" src="'+ sn_src +'" snbutton="1"/>';
			}

			tableHTML[tableHTML.length] = '</td>';
			
			if(i%disp_thumb_no == 1)
				tableHTML[tableHTML.length] = '</tr><tr><td align="center" colspan="4">&nbsp;</td></tr>';

		}

		if(showAllArr.length%disp_thumb_no){
			tableHTML[tableHTML.length] = '<td align="center" valign="middle">&nbsp;</td>';	
			tableHTML[tableHTML.length] = '<td valign="middle" width="21%">&nbsp;</td>';
			tableHTML[tableHTML.length] = '</tr>';
			tableHTML[tableHTML.length] = '<tr><td align="center" colspan="4">&nbsp;</td></tr>';
		}

		tableHTML[tableHTML.length] = '</table>';
	}	
	return tableHTML.join('');
}

//-----------------------------------------------------------------------------
/*	This function initiates call to AJAX */
function call() {
	//if ajax is not supported then follow the normal link
	if (! IS_AJAX_ENABLED) {		
	    return true;
	}
	// if arguments has value then it is the active page number
	// otherwise this is the first time call		
	active_page = (arguments[0] != null && typeof(arguments[0]) == 'number') ? parseInt(arguments[0]) : 1 ;
	
	// get the active page path to call
	var page_name = getPageName();

	if (!page_name) {
	    return true;
	}

	//show loading message
	show_loading();

	// initiate call to AJAX
	var ajax_obj = new AJAX();
	ajax_obj.init('true','GET','XML',page_name,'',createContentBlock);
	ajax_obj = null;
	var cookie_val = active_page + "#" + location.href;
	window.page_cooki.write(cookie_val);
	// return false
	return false;
}

/* returns page name */
function getPageName() {
	if (typeof(total_rec) != 'undefined') {			
		if (total_rec > 0) {			
			var num_pages = Math.ceil(total_rec/rec_to_show); // calculate the number of pages
			if (active_page <= num_pages) {
				return 'page' + active_page + '.xml'; // returns page name to read
			}else {				
				return;
			}
		}else {			
			return;
		}
	}else {		
	     return;
	}
}


/**
* This function creates the content blocks of the pages
*/
function createContentBlock(xml) {
	// get the responseXML
	// get the image collection for xml response
	// this is case-sensitive make sure the xml contains small case
	if (xml == null) {
	    return;
	}else {
		var imgcol = xml.getElementsByTagName('ecard');	
		
		// get page title and change it
		try {
			var pageTitle = xml.getElementsByTagName('pagetitle')[0].firstChild.nodeValue;
			document.title = pageTitle;
		}catch(e) {}
		
		// now get the image collection to get the attribute
		var output = buildTable(imgcol);
		var nav_bar = build_pagination_bar(active_page);	

		// change the innerHTML of the container	
		document.getElementById('container').innerHTML = '';	
		document.getElementById(container).innerHTML = output;		
		document.getElementById('pagin_head').innerHTML = nav_bar;
		if (nav_bar.length == 0) {
			// no records so set the bg of the cell to transparent
		    document.getElementById('pagin_head').style.backgroundColor = 'transparent';
			try {
				document.getElementById('pagin_foot').style.backgroundColor = 'transparent';   
			}
			catch (e){}				
		}
		try{
			document.getElementById('pagin_foot').innerHTML = nav_bar;
		}catch(e){}		
	}
	//hide the loading message
	hide_loading();
	try{
		DiwaliBanner.changeAnchor();
	}catch(ex1){ }
	// refresh adverts
	refreshAds();
}


/**
* Builds the table structure of the thumb container
*
*/
function buildTable(imgcol) {	
	var tableHTML = new Array();
	tableHTML[tableHTML.length] = '<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td colspan=4>&nbsp;</td></tr><tr>';	
	var row_ctr = 0; // row counter creates new row/<tr> if exceeds 2
	var temp;
	var thumb_link = thumb_src = redline = type = greenline = newimage = bigimage = floader = flashDetails = image_type = '';
	var strWrite = ''; // holds either card type or number of records
	var thumb_image_path = 'http://img.123greetings.com/thumbs/'; // thumb image source path
	sn.length=0;
	var new_card;
	var imgalt_txt = '';
	for (var i=0; i < imgcol.length; i++ ) {		
		if (row_ctr == 2) {
		    tableHTML[tableHTML.length] = '</tr><tr><td colspan=4>&nbsp;</td></tr><tr>';
			row_ctr = 0;
		}
		// get the image elements array
		node = imgcol[i];
		try
		{
			floader = unescape(node.getElementsByTagName("flloader")[0].firstChild.nodeValue);
			//floader = floader.split("%3F")[0];
			if(typeof floader.split("%3F")[1] != 'undefined' && floader.split("%3F")[1] != ''){
				var mus = floader.split("%3F")[1];
				mus = mus.split('=')[0] + '=http://img.123greetings.com' + mus.split('=')[1] + '=';
				floader = floader.split("%3F")[0] + '?' + mus;
			}else{
				floader = floader.split("%3F")[0];
			}
		}
		catch (ex)
		{
			floader = '';
		}
		
		try
		{
			flashDetails = node.getElementsByTagName("flash_details")[0].firstChild.nodeValue;
		}
		catch (ex)
		{
			flashDetails='';
		}

		
		
		thumb_link = node.getElementsByTagName("thumblink")[0].firstChild.nodeValue;
		thumb_src = thumb_image_path + node.getElementsByTagName("image")[0].firstChild.nodeValue;
		redline = node.getElementsByTagName("redline")[0].firstChild.nodeValue;
		greenline = node.getElementsByTagName("greenline")[0].firstChild.nodeValue;		
		// big image path
		bigimage = node.getElementsByTagName("image")[0].firstChild.nodeValue; 
		//get image type
		//image_type = node.getElementsByTagName("image_type")[0].firstChild.nodeValue;
		
		temp = flashDetails.split('#');

		try {
			newimage = node.getElementsByTagName("newimagepath")[0].firstChild.nodeValue;
		}catch(e) {
			newimage = '';
		}


		// if label is blank then look for no_cards tag
		try {
		    type = node.getElementsByTagName("label")[0].firstChild.nodeValue;
		}
		catch (e){
		    type = '';
		}

		if (type == '') {
			no_of_cards = node.getElementsByTagName("no_cards")[0].firstChild.nodeValue;
			strWrite = (no_of_cards > 0) ? "[ " + no_of_cards + " cards ]" : "";
		}else {
			type = getType(type);
			strWrite = "[ " + type + " ]";
		}
		
		//to check the card has new=1
		//alert(parseInt(node.getElementsByTagName("new")[0].firstChild.nodeValue));
		try
		{
			new_card =  parseInt(node.getElementsByTagName("new")[0].firstChild.nodeValue);
		}
		catch (ex)
		{
			new_card = 0;
		}
		
		var new_card_img = (new_card == 1)? "<img src='http://img.123greetings.com/homeimages/new2.gif 'border=0 width=23 height=9 alt='New'/>" : "";

		//get the image alt text
		try{
			imgalt_txt = node.getElementsByTagName("alt")[0].firstChild.nodeValue;
		}catch(e1){
			imgalt_txt = redline + ' ' + greenline;
		}
		imgalt_txt = imgalt_txt.replace(/<br>/g, '');
		//imgalt_txt = (imgalt_txt != '')?imgalt_txt:redline + ' ' + greenline;		
		//end of image alt text

		// fill up images array for preloading
		// call preloader
		Preload(new Array(thumb_src));
		
		tableHTML[tableHTML.length] = '<td align="center" valign="middle" width="29%"><table width=140 height=140 border=0 cellspacing=1 cellpadding=1 > <tr><td valign="middle" background="http://img.123greetings.com/images/imgback_thumb.gif" align="center" style="background-repeat: no-repeat;border-color: transparent"><a href=' + thumb_link + ' title="' + imgalt_txt + '"><img border="0" src=' + thumb_src + ' alt="' + imgalt_txt + '" height="115" width="115" align="absmiddle"></a></td></tr></table></td>';
		
		tableHTML[tableHTML.length] = '<td valign="middle" width="21%"><a href="' + thumb_link + '" title="' + imgalt_txt + '"><FONT face="MS SANS SERIF" color=#cc0000 size=2><B>' + redline + '</b></font></a><BR><a href="' + thumb_link + '" title="' + imgalt_txt + '"><FONT face="MS SANS SERIF" color=#006600 size=1>' + greenline + '</font></a><br><a href="' + thumb_link + '" title="' + imgalt_txt + '"><FONT face="MS SANS SERIF" color=#006600 size="1"><b>' + strWrite + '</font></b></a></font>&nbsp;&nbsp;' + new_card_img;
		
		//show my_space logo only if type is not blank
		//alert(type);
	    var image_path = '';
		if (newimage == '') {
			image_path = 'http://img.123greetings.com/eventsnew/' + bigimage;
		}else{
			image_path = newimage + bigimage;
		}

		
		if (type != '') {
			if (type == 'Flash') {					
				image_path = image_path.replace(/eventsnew/,'thumbs');
				sn[i]={'thumb' : image_path,'path' : thumb_link,'type' : "F",'flash_url':floader+"#"+temp[1]+","+temp[2]};				
			}else if (type == 'Interactive') {
				// if interactive card
				/*if (image_type == 'F') {
				    image_path = image_path.replace(/eventsnew/, 'thumbs');
				}
				var loader_path = '';
				if(floader != '') {
					loader_path = floader+"#"+temp[1]+","+temp[2];
				}else {
				    loader_path = flashDetails;
				}
			    sn[i] = {
					'thumb': image_path, 
					'path' : thumb_link, 
					'type' : image_type,
					'flash_url' : loader_path
				};*/
				var is_flash = (flashDetails.indexOf('.swf') > -1) ? true : false;
				
				if (is_flash) {
				    image_path = image_path.replace(/eventsnew/, 'thumbs');
				}

				var loader_path = '';
				if(floader != '') {
					loader_path = floader+"#"+temp[1]+","+temp[2];
				}else {
				    loader_path = flashDetails;
				}
				//image type
				var im_type = is_flash ? "F" : "A";

				sn[i] = {
					'thumb': image_path, 
					'path' : thumb_link, 
					'type' : im_type,
					'flash_url' : loader_path
				};
			}else{				
				sn[i]={'thumb': image_path,'path': thumb_link,'type': "A",'flash_url': ''};				
			}
			var jsFunc = 'dhtml.showBox1(event,'+ (i+1) + ')';
			try{
				tableHTML[tableHTML.length] = '<BR>&nbsp;<BR><IMG SRC="'+ window.config[window.code].img_url.split('#')[0] +'"  BORDER="0" ALT=""  SNBUTTON=1 onClick="' + jsFunc + '" style="cursor:pointer"></td>';
			}catch(ex){
				window.code = global_code;
			}
		}else {
			/*try{
				tableHTML[tableHTML.length] = '<BR>&nbsp;<BR><IMG SRC="'+ window.config[window.code].img_url.split('#')[0] +'" BORDER="0" ALT="" SNBUTTON=1 onClick="dhtml.showBox1(event,' + (i+1) + ')" style="cursor:pointer"></td>';
			}catch(ex){
				window.code = global_code;
			}*/
		}		
		
		row_ctr++; // increase counter
	
		
	}
	//------ if the no of ecards are odd.add extra blank td for right formatting
	if(imgcol.length%2){
		tableHTML[tableHTML.length] = '<td align="center" valign="middle" width="29%">&nbsp;</td>';	
		tableHTML[tableHTML.length] = '<td valign="middle" width="21%">&nbsp;</td>';
	}
	//------
	tableHTML[tableHTML.length] = '<tr><td colspan=4>&nbsp;</td></tr></table>';	
	return tableHTML.join('');	
}


/* function to determine the card type like Postcard, Flash, Animated etc. */
function getType(type) {
	var card_type = '';
	switch (type.toUpperCase()) {
		case 'F':
			card_type = 'Flash';
			break;
		case 'I':
			card_type = 'Interactive';
			break;
		case 'A':
			card_type = 'Animated';
			break;
		case 'P':
			card_type = 'Postcard';
			break;
		case 'O':
			card_type = 'Clickcard';
			break;
		case 'PC':
			card_type = '[ Photocard ]';
			break;
	}

	return card_type;
}

/* copies the top navigation bar to footer */
function copy_header() {
	if (document.getElementById('pagin_head').innerHTML != '') {	
		document.getElementById('pagin_foot').innerHTML = document.getElementById('pagin_head').innerHTML;
	}else {
		// no records so set the bg of the cell to transparent
	    document.getElementById('pagin_foot').bgColor = 'transparent';
	}
}

/**
* Builds the pagination/navigation bar of the thumbpage
* 
*/
function build_pagination_bar(page) {
	//alert(page);
	var nav_str = new Array();
	var num_pages = Math.ceil(total_rec/rec_to_show);
	
	if (total_rec > 0) {	// check whether total_rec that holds number of records is > 0
		
		if (total_rec > 8) {		
			
			if (num_pages > 0) {	
				
				nav_str[nav_str.length] = '<TABLE cellpadding=1 cellspacing=0 width="100%" border=0><TBODY><TR bgColor=#efefef>';
				
				// determines the placement of Separator or Vertical Bar '|'
				if (page == 1 || !page) {
					nav_str[nav_str.length] = '<TD align=left width="15%"><FONT face=Verdana color=#00058a size=1>&nbsp;</FONT></TD>';    
				}else {
					nav_str[nav_str.length] = '<TD align=left width="15%"><FONT face=Verdana color=#00058a size=1>&nbsp;<a href="javascript:void(0)" onmouseover="self.status=\'\';return true;" onClick="prev_records('+(page-1)+');"><B>&lt;Back</B></A></FONT></TD>';
				}				
				nav_str[nav_str.length] = '<TD align="center" width="70%" valign="absmiddle" style="padding-bottom: 2px">';
				
				for (var i = 1; i <= num_pages; i++ ) {
					// determines the placement of Separator or Vertical Bar '|'
					if (i==page) {
						if (i==num_pages) {
							nav_str[nav_str.length] = '<FONT face="verdana" color="gray" size="1"><B>'+i+'</b></font>';    
						}else {
							nav_str[nav_str.length] = '<FONT face="verdana" color="gray" size="1"><B>'+i+'</b></font><FONT face=verdana color="#00058a" size="1"> | </font>';
						}			    
					}else {
						// determines the current page being viewed
						
						if (i == num_pages) {
							nav_str[nav_str.length] = '<FONT face=Verdana color=#00058a size=1><A href="javascript:void(0)" onmouseover="self.status=\'\';return true;" onClick="call('+(i)+')"><B>'+i+'</B></A></font>';    
						}else {
							nav_str[nav_str.length] = '<FONT face=Verdana color=#00058a size=1><A href="javascript:void(0)" onmouseover="self.status=\'\';return true;" onClick="call('+(i)+')"><B>'+i+'</B></A></font><FONT face=verdana color=#00058a size=1> | </font>';
						}				
					}
				}

				if(!page){					
					if(typeof(show_all_by) == 'string' && show_all_by.toUpperCase() == 'L')
						nav_str[nav_str.length] = '<FONT face=Verdana color=gray size=1> | <B>[List View]</B> | </font>';
					else
						nav_str[nav_str.length] = '<FONT face=Verdana color=#00058a size=1> | <A href="javascript:void(0)" onmouseover="self.status=\'\';return true;" onClick="show_all(\'L\');"><B>[List View]</B></A> | </font>';

					if(typeof(show_all_by) == 'string' && show_all_by.toUpperCase() == 'G')
						nav_str[nav_str.length] = '<FONT face=Verdana color=gray size=1><B>[Grid View]</B></font>';
					else
						nav_str[nav_str.length] = '<FONT face=Verdana color=#00058a size=1><A href="javascript:void(0)" onmouseover="self.status=\'\';return true;" onClick="show_all(\'G\');"><B>[Grid View]</B></A></font>';

				}else
					nav_str[nav_str.length] = '<FONT face=Verdana color=#00058a size=1> | <A href="javascript:void(0)" onmouseover="self.status=\'\';return true;" onClick="show_all(\'L\');"><B>[List View]</B></A> | <A href="javascript:void(0)" onmouseover="self.status=\'\';return true;" onClick="show_all(\'G\');"><B>[Grid View]</B></A></font>';

				if (page == num_pages || !page) {
					nav_str[nav_str.length] = '</TD><TD align=right width="15%"><FONT face=Verdana color=#00058a size=1>&nbsp;</FONT></TD></TR></TBODY></TABLE>';    
				}else {
					nav_str[nav_str.length] = '</TD><TD align=right width="15%"><FONT face=Verdana color=#00058a size=1><A href="javascript:void(0)" onmouseover="self.status=\'\';return true;" onClick="next_records('+(page+1)+');"><B>Next&gt;</B></A>&nbsp;</FONT></TD></TR></TBODY></TABLE>';
				}		
			}
		}else {
		     nav_str[nav_str.length] = '';
		}
	}else {
		// total records can't be empty if is then return null
	    return;
	}
	return nav_str.join('');
}

/**
* Navigates to next set of records
*/
function next_records(page) {	
	num_pages = Math.ceil(total_rec/rec_to_show);
	if (page <= num_pages) {		
		active_page = page;		
	    return call(page);
	}
}

/**
* Navigates to previous set of records
*/
function prev_records(page) {	
	if (page >= 1) {
		active_page = page;
		return call(page);
	}
}

/******************************** IMAGE PRELOADING ****************************/
var aImages=new Array();
function Preload() {
	var temp = Preload.arguments;
	var tempLen = temp.length;
	for(x=0; x < tempLen; x++) {
		aImages[x]=new Image();
		aImages[x].src=Preload.arguments[x];
	}
}

/*************************** show loading ********************/
/*
* Function when called displays a dynamically created div with loading message.
*/
var image = new Image();
image.src = 'http://img.123greetings.com/images/loading.gif';
image.align = 'absmiddle';

function show_loading(){	
	//show loading message text
	if (!_loading) {
		var oDiv = document.createElement('div');
		oDiv.setAttribute('id','loading');
		oDiv.id = 'loading';
		oDiv.style.position = 'absolute';
		oDiv.style.zIndex = '50';		
		oDiv.style.top = findPosY(document.getElementById('pagin_head')) - 10; // add top scroll amount		
		oDiv.style.left = (parseInt(getWinSize() / 2)- parseInt(200/2));
		oDiv.style.height = 50;
		oDiv.style.width = 200;
		oDiv.style.paddingTop = 15;
		oDiv.style.backgroundColor = '#FFFFFF';//'#00A8F9';
		oDiv.style.opacity = .95;
		oDiv.style.filter = 'alpha(opacity=' + 95 + ')';
		oDiv.style.textAlign = 'center';
		oDiv.style.fontFamily = 'verdana, Geneva, Helvetica';
		oDiv.style.fontWeight = 'bold';
		oDiv.style.fontSize = '10';
		oDiv.style.color = '#000000';
		oDiv.style.borderStyle = 'ridge';		
		oDiv.style.borderColor = '#808080';
		oDiv.style.borderWidth = 1;
		oDiv.style.visibility = 'visible';
		//create image
		oDiv.appendChild(image);
		oDiv.appendChild(document.createTextNode("   Loading...."));		
		document.body.insertBefore(oDiv, document.body.childNodes[0]);
		_loading = true;
	}
}
	

/*
*
* Function used to hide the loading message
*
*/
function hide_loading() {		
	// code to hide loading message	
	if (_loading) {	
		document.body.removeChild(document.getElementById('loading'));
		_loading = false;
	}	
}

function getWinSize() {
	var winW;
	// get window size adjusted for scrollbars
	if (window.innerWidth) {
		winW = window.innerWidth-16;
	}
	if (document.body.offsetWidth) {
		winW = document.body.offsetWidth-20;
	}
	return winW;
}

/* Find a Top position of an element in the page */
function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

/* This function refreshes ads */
function refreshAds() {
	var adPos = OAS_listpos.split(',');
	var iframeSrc = 'http://img.123greetings.com/banner_js/showad.html';
	var strAdvertBanner = '<IFRAME name="bannerFrame" id="bannerFrame" marginheight="0" marginwidth="0" align="middle" height="HE" width="WI" frameborder="0" allowtransparency="true" src="SRC" scrolling=no></iframe>';
	//change top banner 728 x 90
	if (document.getElementById('top_banner')) {
		var strBanner = strAdvertBanner.replace(/HE/,'90');
		strBanner = strBanner.replace(/WI/,'748');
		strBanner = strBanner.replace(/SRC/, iframeSrc + '#' + adPos[0] + '|' + OAS_listpos + '|' + OAS_sitepage + '|' + OAS_query);
		document.getElementById('top_banner').innerHTML = strBanner;
	}
	// change right banner 128 x 600
	if (document.getElementById('right_banner')) {
		var strBanner = strAdvertBanner.replace(/HE/,'620');
		strBanner = strBanner.replace(/WI/,'128');
		strBanner = strBanner.replace(/SRC/, iframeSrc + '#' + adPos[1] + '|' + OAS_listpos + '|' + OAS_sitepage + '|' + OAS_query);
		document.getElementById('right_banner').innerHTML = strBanner;
	}
	//change middle banner 300 x 250
	if (document.getElementById('middle_banner')) {
		var strBanner = strAdvertBanner.replace(/HE/,'258');
		strBanner = strBanner.replace(/WI/,'320');
		strBanner = strBanner.replace(/SRC/, iframeSrc + '#' + adPos[2] + '|' + OAS_listpos + '|' + OAS_sitepage + '|' + OAS_query);
		document.getElementById('middle_banner').innerHTML = strBanner;
	}
}


/*********Function to load Javascript Libararies asynchronously **********/
var scr
function load_js(script_src,callback){
var t;
var script_loaded = false;
var temp = document.getElementsByTagName('script');
for(i=0;i<temp.length;i++)
	{
		if(temp[i].src == script_src){
			script_loaded = true;
		}
	}
	if (!script_loaded)
	{
		scr = document.createElement('script');
		var temp_id = script_src.split("/");
		scr.id = temp_id[temp_id.length -1].split(".")[0];
		scr.type = "text/javascript";
		scr.src = script_src;
		scr.onload = callback;//firefox only
		scr.onreadystatechange = function() {if(scr.readyState=='complete' || scr.readyState=='loaded')callback(); } //IE only
		document.getElementsByTagName('head')[0].appendChild(scr);
		return false;
	}else{
		callback();
	}
}

/**************Function for Cookie using JS (primarily used for ajax pagination)****************/
function jscookie(cookie_name,days){
	if(cookie_name != ''){
		this.name = cookie_name;
	}else{
		throw new Error (1001,"JS-COOKIE : Cookie Name cannot be blank");
	}
	//this.value = val || '';
	this.days = days || '';
}

var jscookie_proto = jscookie.prototype;
jscookie_proto.write = function(val){
		if (this.days) {
			var date = new Date();
			date.setTime(date.getTime()+(this.days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}else{
		   var expires = "";
		}
	document.cookie = this.name+"="+val+expires+"; path=/";
	

}

jscookie_proto.read = function(){
	var search = this.name + "=";   
			if (document.cookie.length > 0) { // if there are any cookies 
				offset = document.cookie.indexOf(search);       
			if (offset != -1) { // if cookie exists          
				offset += search.length;          
			 // set index of beginning of value 
				end = document.cookie.indexOf(";", offset);          
			 // set index of end of cookie value         
			 if (end == -1)             
				end = document.cookie.length;         
				return unescape(document.cookie.substring(offset, end));      
			}    
		}

}

/************************************ End JS COOKIE******************************/
function load_cookie(){
	if(page_cooki.read()){
	var page = page_cooki.read();
	page = page.split('#');
		if(typeof(page[0]) == 'string' && page[0].toUpperCase() == 'G' && page[1] == location.href ) {
			show_all('G');
		}
		else if(typeof(page[0]) == 'string' && page[0].toUpperCase() == 'L' && page[1] == location.href ) {
			show_all('L');
		}
		else if(parseInt(page[0]) != 1 && page[1] == location.href ) {
			call(parseInt(page[0]));
		}
    }
}

//function addEvent_to_container(){
//
//var addEvent = function(obj, type, fn){
//	if (obj.addEventListener) {
//			obj.addEventListener(type, fn, false );
//		}else {
//			if ( obj.attachEvent ) { 
//				obj['e'+type+fn] = fn; 
//				obj[type+fn] = function(){ obj['e'+type+fn]( window.event ); } 
//				obj.attachEvent( 'on'+type, obj[type+fn] ); 
//			}
//     	}
//};
//try{
//	var elem = document.getElementById('container');
//	addEvent(elem,'load',load_cookie);
//}catch(ex){
//	alert('Error loading contents from cookie');
//}
//
//
//}();
//window.onload = load_cookie;

