// JavaScript Document

// function to get the selected custom field in the textBody on Double cliking 
function getCFldName(oSel)
{
	var id;
	var selValue;
	var mOldvalue;
	
	id=oSel.selectedIndex;
	
	selValue=oSel.options[id].text;
	
	//alert(m);
	
	mOldvalue=document.forms[0].MemoBody.value;
	document.forms[0].MemoBody.value = mOldvalue + " " + selValue;	
}

function CheckEditable(ChkEdit, strSuffix, bSysField)
{
	if (ChkEdit.checked){
		//if editable can not be hidden, uncheck the hidden
		eval('document.FrmLayOut.HiddenChkBox_'+strSuffix+'.checked=false');
		//if editable it may be required		
						
	}else{
		//if not editable it may be hidden
		
		//if not editable can not be required, uncheck the required
		eval('document.FrmLayOut.RequiredChkBox_'+strSuffix+'.checked=false');
	}	
}
function CheckRequired(ChkReq, strSuffix, bSysField)
{
	if (ChkReq.checked){
		//if required it should be editable, check editable
		eval('document.FrmLayOut.EditableChkBox_'+strSuffix+'.checked=true');
		//if requied can not be hidden
		eval('document.FrmLayOut.HiddenChkBox_'+strSuffix+'.checked=false');
	}else{
		//if not required  it can be either editable or hidden
	}
}
function CheckHidden(ChkHidden, strSuffix, bSysField)
{
	if (ChkHidden.checked){
		//if it is hidden can not be editable and required
		eval('document.FrmLayOut.EditableChkBox_'+strSuffix+'.checked=false');
		eval('document.FrmLayOut.RequiredChkBox_'+strSuffix+'.checked=false');				
	}else{
		//if not hidden it may be both editable and required
	}
}
function chkEnterKey()
{	var key;
	
	if (document.captureEvents)	//non-IE
		key= arguments.callee.caller.arguments[0].which	//to get the event code for netscape, firefox
	else
		key=window.event.keyCode;

	if (key == 13) {
		if (document.getElementById("divAdvanceSearchSection").style.display == "")
			SubmitSearch(document.forms[0]);
		else
			SubmitSimplifiedValue(document.forms[0]);
	}
	//End Enter Key  Search
}

//  check for valid numeric strings
function IsNumeric(strString){
	var strValidChars = "0123456789.";
	var strChar;
	var blnResult = true;

	if (strString.length == 0) return false;

	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
		{
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
			{
			blnResult = false;
			}
		}
	return blnResult;
}

function IsValidEmail(src) {
	var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
	var regex = new RegExp(emailReg);
	return regex.test(src);
}

function TextAreaMaxLength( field, countfield, maxlimit ) {
//syntax: parameters should be passed as this.form.fieldname
//maxlimit is number
	if ( field.value.length > maxlimit )
	{
		field.value = field.value.substring( 0, maxlimit );
		alert( 'Textarea value can only be ('+ maxlimit + ') characters in length.' );
		return false;
	}
	else
	{
		//alert(countfield == null);
		if (countfield != '' && countfield != null){
			countfield.value = maxlimit - field.value.length;
		}
	}
}

function trim(s) {
	while (s.substring(0,1) == ' ') {
		s = s.substring(1,s.length);
	}
	while (s.substring(s.length-1,s.length) == ' ') {
		s = s.substring(0,s.length-1);
	}
	return s;
}

function GotoBC(nodeLocation, totalDiv)
{			
	for (var i=1; i <= totalDiv; i++)
	{
		if (i == nodeLocation)
		{
			document.getElementById("divBreadCrumb_" + i).style.display = "";
		}
		else
		{
			document.getElementById("divBreadCrumb_" + i).style.display = "none";
		}
	}
}


function bcAction(FormID, FormAction, FormTarget, iTab) {
	if (iTab != '') {
		top.HeaderFrame.SelectTab(iTab);
	}
	if (FormAction != '') {
		bcRedirect(FormID, FormAction, FormTarget);
	}
}

function bcRedirect(FormID, FormAction, FormTarget) {
	document.title="entellium";
	if (FormID == '')
	{
		if (FormTarget != '') {
			//document.getElementById(FormID).target = FormTarget;
			document.forms[0].target = FormTarget;
		}
		document.forms[0].method = "post";
		document.forms[0].action = FormAction;
		document.forms[0].submit();
	}
	else
	{
		if (FormTarget != '') {
			document.getElementById(FormID).target = FormTarget;
		}
		document.getElementById(FormID).method = "post";
		document.getElementById(FormID).action = FormAction;
		document.getElementById(FormID).submit();
	}	
}

function SwithMainAction(URL, iTab ){
    top.HeaderFrame.SelectTab(iTab);
    GotoURL(URL);
}
function GotoURL(URL){
	document.FrmInput.action = URL;
	document.FrmInput.method = 'post';
	document.FrmInput.submit();
}

function GetLayout(){
	var strURL = '' ;
	if((strURL.substr(0, 7).toLowerCase())!= 'http://')
	{
		var  strhttp = 'http://www.viccs.com/news.html';
	}
	else
	{
		var  strhttp= '';
	}
	document.FrmInput.action = strhttp + strURL;
	document.FrmInput.method = 'post';
	document.FrmInput.submit();
}

function FormSubmit(Action, ValidateFields){
	var bError = false;
	var message = '';
	message = 'The following is(are) required field(s).\n\n';
	if (ValidateFields != ''){
		var arrFields = ValidateFields.split(',');
		for (var i=0; i < arrFields.length; i++){
			var FieldItem = arrFields[i].split('*');
			if (eval('document.FrmInput.'+FieldItem[0]+'.value') == ''){
    			message = message +'   * ' + FieldItem[1]+ '\n';
    			bError = true;
			}

		}
	}
	
	if (bError == false){
	    //Added By Lai On 15/11/2006
	    //Disable the button after user submit form
	    document.getElementById('Button1').disabled=true;
	    document.getElementById('Button2').disabled=true;

		document.FrmInput.action = 'http://www.entelliumgreen.net/esam/eSalesForceAdmin/Create_WebLead.asp?Action=1';
		document.FrmInput.method = 'post';
		document.FrmInput.submit();
	}else{
		alert(message);
	}
}

function GetQueryStringInfo()
{
	var qs = new Querystring();
	var strSearchEngineName = qs.get("engine");
	var strSearchKeyword = qs.get("keyword");
	var strSearchType = qs.get("type");
	var strReferrerURL = document.referrer;
	
	document.getElementById('SearchEngineName').value = strSearchEngineName;
	document.getElementById('SearchKeyword').value = strSearchKeyword;
	document.getElementById('SearchType').value = strSearchType;
	document.getElementById('ReferrerURL').value = strReferrerURL;
}

function Querystring(qs) 
{
	this.params = new Object()
	this.get = Querystring_get;
	
	if(qs == null)
	{
		qs = location.search.substring(1,location.search.length)
	}
	
	if (qs.length == 0) 
	{
		return
	}
	
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&')
	
	for (var i=0;i<args.length;i++) 
	{
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		
		this.params[name] = value
	}
}

function Querystring_get(key, default_) 
{
	if (default_ == null) default_ = null;
	
	var value=this.params[key]
	if (value==null) value=default_;
	
	return value
}

function AssignState(strState) 
{ 
	document.FrmInput._OfficeState102990.value = strState; 
} 

function DisplayCountry() 
{ 
var strDisplayUSA, strDisplayCanada, strDisplayOther; 
var strCountry; 
	strDisplayUSA = 'none'; 
	strDisplayCanada='none'; 
	strDisplayOther = 'none'; 
	strCountry = document.getElementById('_OfficeCountry102987').value;	
 	if (strCountry == 'USA'){ 
		document.FrmInput.txtOtherState.value = ''; 
		strDisplayUSA = ''; 
		AssignState(document.FrmInput.cmbUSAState.value); 
	}else if (strCountry == 'Canada'){ 
		document.FrmInput.txtOtherState.value = ''; 
		strDisplayCanada = ''; 
		AssignState(document.FrmInput.cmbCanadaState.value); 
	}else{ 
		strDisplayOther = ''; 
		AssignState(document.FrmInput.txtOtherState.value); 
	}; 
	if(navigator.appName == 'Netscape') { 
		document.getElementById('DivUS').style.display     = strDisplayUSA; 
		document.getElementById('DivCanada').style.display = strDisplayCanada; 
		document.getElementById('DivOthers').style.display = strDisplayOther; 
	}else { 
		document.all.DivUS.style.display		= strDisplayUSA; 
		document.all.DivCanada.style.display	= strDisplayCanada; 
		document.all.DivOthers.style.display	= strDisplayOther; 
	}; 
}

function SetTime()
{
	var d = new Date();
	var year = d.getFullYear();
	var day = d.getDate();
	var month = d.getMonth();
	var hours = d.getHours();
	var minutes = d.getMinutes();
	var seconds = d.getSeconds();
	var shortMonths = new shortMonthArray();
	month = month + 1;

	DisplayCountry();


}
function shortMonthArray() {
	this[0] = "Jan";	this[1] = "Feb";	this[2] = "Mar";
	this[3] = "Apr";	this[4] = "May";	this[5] = "Jun";
	this[6] = "Jul";	this[7] = "Aug";	this[8] = "Sep";
	this[9] = "Oct";	this[10] = "Nov";	this[11] = "Dec";
return (this);
}
