/***************************************************************************************************
	Library Name	:	Date Library
	File Name		:	commonlib.js
	Version			:	1.0.0
	Author			:	Subbaraman K (ksubbaraman@gmail.com)
	Date			:	6th Apr 2005
***************************************************************************************************/

FORMAT_DDMMYYYY		=	0;
FORMAT_MMDDYYYY		=	1;
FORMAT_YYYYMMDD		=	2;
FORMAT_YYYYMONDD	=	3;
FORMAT_MONDDYYYY	=	4;
FORMAT_DDMONYYYY	=	5;

DEFAULT_DATEFORMAT		=	FORMAT_DDMMYYYY;
DEFAULT_DATESEPERATOR	=	"-";

function __lib_String_replaceGlobal(strInputText, strFind, strReplaceWith, blnIgnoreCase){
var	ptnPattern;	ptnPattern	= eval("/" + strFind + ((blnIgnoreCase)?"/gi":"/g"));
return strInputText.replace(ptnPattern,strReplaceWith);
}
function __lib_String_replaceAll(strFind, strReplaceWith){
	return __lib_String_replaceGlobal(this, strFind, strReplaceWith, false);
}
function getParameter(strSearchParameter){
	var strQueryString = new String(location.search);	if(strQueryString.length==0) return null;
	var intIndex1=0,intIndex2=0;
	intIndex1=strQueryString.toLowerCase().indexOf("&" + strSearchParameter.toLowerCase() + "=",0);
	if(intIndex1==-1)	intIndex1=strQueryString.toLowerCase().indexOf("?" + strSearchParameter.toLowerCase() + "=",0);
	if(intIndex1==-1)	return null;
	intIndex1 = intIndex1 + strSearchParameter.length + 2;
	intIndex2=strQueryString.indexOf("&",intIndex1);
	if(intIndex2==-1)	intIndex2=strQueryString.length;
	return(unescape(strQueryString.substring(intIndex1,intIndex2)));
}
function __lib_MonthDB(){this.arrName=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
this.getName=__lib_MonthDB__getMonthName;this.getShortName=__lib_MonthDB__getMonthShortName;}
function __lib_MonthDB__getMonthName(intMonthArrayIndex){return this.arrName[intMonthArrayIndex];}
function __lib_MonthDB__getMonthShortName(intMonthArrayIndex){return this.arrName[intMonthArrayIndex].substr(0,3);}
var Months = new __lib_MonthDB();
function __lib_Date_getMonthName(){return Months.getName(this.getMonth());}
function __lib_Date_getMonthShortName(){return Months.getShortName(this.getMonth());}
Date.prototype.getMonthName		=	__lib_Date_getMonthName;
Date.prototype.getMonthShortName=	__lib_Date_getMonthShortName;


function getStringFromDate(dtDate, strFormat, strSeperator){
	if(typeof(dtDate)=='undefined')	return null;
	else if(dtDate==null)			return null;
	else if(dtDate=="")				return null;
	
	var intDay, intMonth, intYear;
	intDay		=	dtDate.getDate();
	intMonth	=	dtDate.getMonth();
	intYear		=	dtDate.getFullYear();

	if(typeof(strSeperator)=='undefined')	strSeperator	=	DEFAULT_DATESEPERATOR;
	else if(strSeperator==null)	strSeperator	=	DEFAULT_DATESEPERATOR;
	else if(strSeperator=="")	strSeperator	=	DEFAULT_DATESEPERATOR;

	switch(intFORMAT){
		case FORMAT_MMDDYYYY	:	strDate = (((intMonth+1)<10)?"0":"") + (intMonth+1) + strSeperator + ((intDay<10)?"0":"") + intDay + strSeperator + intYear; break;
		case FORMAT_YYYYMMDD	:	strDate = intYear + strSeperator + (((intMonth+1)<10)?"0":"") + (intMonth+1) + strSeperator + ((intDay<10)?"0":"") + intDay; break;
		case FORMAT_YYYYMONDD	:	strDate = intYear + strSeperator + dtDate.getMonthShortName() + strSeperator + ((intDay<10)?"0":"") + intDay; break;
		case FORMAT_MONDDYYYY	:	strDate = dtDate.getMonthShortName() + strSeperator + ((intDay<10)?"0":"") + intDay + strSeperator + intYear; break;
		case FORMAT_DDMONYYYY	:	strDate = ((intDay<10)?"0":"") + intDay + strSeperator + dtDate.getMonthShortName() + strSeperator + intYear; break;
		case FORMAT_DDMMYYYY	:	strDate = ((intDay<10)?"0":"") + intDay + strSeperator + (((intMonth+1)<10)?"0":"") + (intMonth+1) + strSeperator + intYear; break;
	}
	return strDate;
}
String.prototype.replaceAll				=	__lib_String_replaceAll;

function Synopsis(){
	this.ReleaseDate	=	new Date();
	this.Place			=	new String("");
	this.Heading		=	new String("");
}

function Contact(){
	this.data			=	new String("");
	this.email			=	new String("");
}
function Article(){
	this.ReleaseDate	=	new Date();
	this.Place			=	new String("");
	this.Heading		=	new String("");
	this.SubHeading		=	new String("");
	this.Body			=	new String("");
	this.Footing		=	new String("");
	this.NoOfContacts	=	new Number(0);
	this.Contacts		=	new Array();
	this.addContact		=	__lib_AddContact;
	this.getContactData		=	__lib_getContactData;
}
function __lib_AddContact(data, email){
	this.Contacts[this.NoOfContacts]		=	new Contact();
	this.Contacts[this.NoOfContacts].data	=	data;
	this.Contacts[this.NoOfContacts].email	=	email;
	this.NoOfContacts++;
}
function __lib_getContactData(indexNo){
	if(indexNo > 0 && indexNo <= this.NoOfContacts) return this.Contacts[indexNo-1];
	return new Contact();
}

var synSynopsis		=	new Array();
var intCount		=	new Number(-1);

 function replace2jsformat(strText){
	 /*
	 //Replace Slashes and backSlashes
	if(strText.indexOf("\\")>-1)
	 	strText	=	strText.replaceAll("\\\\","\\\\");
	if(strText.indexOf("\/")>-1)
	 	strText	=	strText.replaceAll("\\\/","\\\/");
 	//Replace Double and Single quotes
	if(strText.indexOf("\"")>-1)
	 	strText	=	strText.replaceAll("\\\"","\\\"");
	if(strText.indexOf("\'")>-1)
	 	strText	=	strText.replaceAll("\\\'","\\\'");
	*/
	
 	//Replace New Line
 	if(strText.indexOf("\r\n")>-1)
	 	strText	=	strText.replaceAll("\\r\\n","\\n");
	else if(strText.indexOf("\r")>-1)
		strText	=	strText.replaceAll("\\r","\\n");
	else if(strText.indexOf("\n")>-1)
	 strText	=	strText.replaceAll("\\n","\\n");
 	return strText;
 }
 function replace2defaultformat(strText){
	//Replace New Line
 	if(strText.indexOf("\\n")>-1)
	 	strText	=	strText.replaceAll("\\\\n","\n");
 	return strText;
 }