function getGMTOffset()
{
	var now = new Date();
	setCookie('gmtoffset',now.getTimezoneOffset(),null,'/','.cham03.whapps.com');
}

function setCookie(name, value, expires, path, domain, secure) 
{
 	var curCookie = name + "=" + escape(value) +
      	((expires) ? "; expires=" + expires.toGMTString() : "") +
      	((path) ? "; path=" + path : "") +
      	((domain) ? "; domain=" + domain : ".cham03.whapps.com") +
      	((secure) ? "; secure" : "");
  	document.cookie = curCookie;
}

//////// Popup Code
rnd.today=new Date();
rnd.seed=rnd.today.getTime();
                                               
                                         
function rnd() {
        rnd.seed = (rnd.seed*9301+49297) % 233280;
         return rnd.seed/(233280.0);
}   

                                    
function rand(number) {
        return Math.ceil(rnd()*number);
} 
   
function pop(URL, width, height, specname)
{
                        var name = rand(19302);
                        if (specname) { name = specname; }
                        var popup = new Object();
                        // get center of browser window
                        var winleft = (screen.width - width) / 2;
                        var wintop = (screen.height - height) / 2;
                        popup = window.open(URL, name,'width='+width+',height='+height+',top='+wintop+',left='+winleft+',resizable, dependant, scrollbars=yes')
                        popup.focus()
}     

function disableForm(theform, theButton) {

	if (document.all || document.getElementById) {
		for (i = 0; i < theform.length; i++) {
			var tempobj = theform.elements[i];
			if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset")
				tempobj.disabled = true;
			}
			return true;
	}
	else {
		theButton.disabled = true;
		return true;
   }
}

function validateFrm(theForm, reqFields)
{
        var formElements = theForm.elements;
	reqFields = " " + reqFields + " ";
	
        for (var i=0; i < formElements.length; i++)
                if (formElements[i].type == "text" 
			|| formElements[i].type == "password" 
			|| formElements[i].type == "select-one"
			|| formElements[i].type == "radio"
			|| formElements[i].type == "checkbox")
                        formElements[i].style.background = '';
	
	for (var i=0; i < formElements.length; i++)
	{
		if (reqFields.indexOf(" " + formElements[i].name + " ") != -1)
		{
			if (formElements[i].type == "text" || formElements[i].type == "password" || formElements[i].type == "select-one")
			{
				if (formElements[i].value == "")
				{
					alert("The " + formElements[i].name + " field cannot be blank.");
					formElements[i].style.background = 'yellow';
					formElements[i].focus();
					return false; 
				}
			}
			if (formElements[i].type == "checkbox")
			{
				if (! formElements[i].checked)
				{
					alert("The " + formElements[i].name +  " box must be checked to continue.");
					formElements[i].style.background = 'yellow';
					return false; 
				}
			}
		}
		
		if (formElements[i].name == "checkpass")
		{
			if (theForm.password.value != theForm.checkpass.value)
			{
				alert("The password fields must match.");
				theForm.password.style.background = 'yellow';
				theForm.checkpass.style.background = 'yellow';
				theForm.password.focus();
				return false; 
			}
		}
		
		if (formElements[i].name == "checkemail")
		{
			if (theForm.email.value != theForm.checkemail.value)
			{
				alert("The email fields must match.");
				theForm.email.style.background = 'yellow';
				theForm.checkemail.style.background = 'yellow';
				theForm.email.focus();
				return false; 
			}
		}
	}
	
	disableForm(theForm);
	
	return true;
}

function populateFrm(theDoc, popFields)
{
	for (var i=0; i < popFields.length; i++)
	{
		var tehField = theDoc.getElementById(popFields[i][0]);
		var tehValue = popFields[i][1];
		tehField.value = tehValue;
	}
}
