//Trims a string from both sides
function strTrim(tmpStr)
{
	tmpStr = tmpStr.replace(/^\s+/,"");//remove leading
	tmpStr = tmpStr.replace(/\s+$/,"");//remove trailing
	return tmpStr;
}
//Trims all fields in a form
function trimFields()
{
	for(var i=0; i < obj.elements.length; i++)
	{
		if(obj.elements[i].type == "text" || obj.elements[i].type == "textarea" || obj.elements[i].type == "password")
		{
			obj.elements[i].value = strTrim(obj.elements[i].value);
		}
	}
}
//Checks email against pattern
function chkEmail(tmpStr)
{
	var email_pat = /^[a-z][a-z0-9_\.\-]*[a-z0-9]@[a-z0-9]+[a-z0-9\.\-_]*[a-z]+$/i;
	return(email_pat.test(tmpStr))
}
//Validates text-area length
function validateTALength(strField, cntlName, maxChar)
{
	if(obj.elements[cntlName].value.length > maxChar)
	{
		alert(strField+" should be within "+maxChar+" characters.");
		obj.elements[cntlName].focus();
		obj.elements[cntlName].select();
		return false;
	}
	return true;
}
//Check the val is a integer
function IsInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
//Opens a picture window
function openPictureWindow(imageName,imageWidth,imageHeight,alt)
{
	newWindow = window.open("","newWindow","width="+imageWidth+",height="+imageHeight+",left=100,top=100, scrollbars=1");
	var doc = newWindow.document;
	doc.open();
	doc.write('<html>\n');
	doc.write('<head>\n');
	doc.write('<title>'+alt+'</title>\n');
	doc.write('<meta http-equiv="imagetoolbar" content="no">\n');
	doc.write('</head>\n');
	doc.write('<body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" ondblclick="self.close();" onblur="self.close();">\n');
	doc.write('<img src=\"'+imageName+'\" width=\"'+imageWidth+'\" height=\"'+imageHeight+'\" alt=\"'+alt+'\n(Double Click to Close)\" border="0">\n');
	doc.write('</body>\n');
	doc.write('</html>\n');
	doc.close();
	newWindow.focus();
}
//---------------------------
function alertWindow(text)
{
	newWindow = window.open("","newWindow","width=200,height=100,left=200,top=200");
	var doc = newWindow.document;
	doc.open();
	doc.write('<html>\n');
	doc.write('<head>\n');
	doc.write('<title>Message</title>\n');
	doc.write('<meta http-equiv="imagetoolbar" content="no">\n');
	doc.write('</head>\n');
	doc.write('<body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" ondblclick="self.close();" onblur="self.close();">\n');
	doc.write('<p>&nbsp;</p><p align=center><font face=verdana size=2>'+text+'</font></p>\n');
	doc.write('</body>\n');
	doc.write('</html>\n');
	newWindow.focus();
}
//---------------------------
function put_border(imagepath, imagewidth, imageheight, imagealt, image_url)
{
	strdata = '<table id="Table_01" width="214" height="196" border="0" cellpadding="0" cellspacing="0">';
	strdata+= '<tr>';
	strdata+= '<td><img src="images/border_01.gif" width="8" height="8" alt=""></td>';
	strdata+= '<td background="images/border_02.gif"><img src="images/border_02.gif" width="198" height="8" alt=""></td>';
	strdata+= '<td><img src="images/border_03.gif" width="8" height="8" alt=""></td>';
	strdata+= '</tr>';
	strdata+= '<tr>';
	strdata+= '<td background="images/border_04.gif"><img src="images/border_04.gif" width="8" height="180" alt=""></td>';
	//strdata+= '<td><a href="'+image_url+'" title="'+imagealt+'" rel="lightbox"><img src="'+imagepath+'" width="'+imagewidth+'" height="'+imageheight+'" border="0" alt="'+imagealt+'"></a></td>';
	strdata+= '<td><img src="'+imagepath+'" width="'+imagewidth+'" height="'+imageheight+'" border="0" alt="'+imagealt+'"></td>';
	strdata+= '<td background="images/border_06.gif"><img src="images/border_06.gif" width="8" height="180" alt=""></td>';
	strdata+= '</tr>';
	strdata+= '<tr>';
	strdata+= '<td><img src="images/border_07.gif" width="8" height="8" alt=""></td>';
	strdata+= '<td background="images/border_08.gif"><img src="images/border_08.gif" width="198" height="8" alt=""></td>';
	strdata+= '<td><img src="images/border_09.gif" width="8" height="8" alt=""></td>';
	strdata+= '</tr>';
	strdata+= '</table>';
	return strdata;
}
//---------------------------
function show_msg(name, val)
{
	document.getElementById(name).innerHTML = val;
}
function launch_upload_chooser(cntl_name)
{
	newWindow = window.open('popup.php?val='+cntl_name,"newWindow","width=710,height=500,left=0,top=0, scrollbars=1");
	newWindow.focus();
}
function showLink(linkText)
{
	prompt("Copy the link from the text box below: -", "http://devi.etechnoverb.com/launchpad/lp_smarty/"+linkText);
	return;
}
//---------------------------
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
function showsubmenu(id)
{
	//submenu = document.getElementById('s'+id);
	//alert(submenu);
	document.getElementById(id).style.display="block";
	//submenu.style.display="Inline";
}

function showsubmenus(id)
{
	//submenu = document.getElementById('s'+id);
	//alert(submenu);
	document.getElementById(id).style.display="none";
	//submenu.style.display="Inline";
}
