function openNewWindow(newPageURL)
{
	window.location.replace(newPageURL);
}
/* Modified to support Opera */
function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}
//====== toogle switch
function HideDiv( divId )
{
	document.getElementById(divId).style.visibility = "hidden";
	document.getElementById(divId).style.display = "none";
}
function ShowDiv( divId )
{
	document.getElementById(divId).style.visibility = "visible";
	document.getElementById(divId).style.display = "block";
}
function switchvis1(id){
   if(document.getElementById(id)){
       var ele = document.getElementById(id);
//       if(ele.style.visibility=="hidden"){
           ele.style.visibility="visible";
//       }
   }
}
function switchvis2(id){
   if(document.getElementById(id)){
       var ele = document.getElementById(id);
//       if(ele.style.visibility=="visible"){
           ele.style.visibility="hidden";
//       }
   }
}
//======== vaildate function
function handleEnter (field, event) {
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
if (keyCode == 13) {
var i;
	for (i = 0; i < field.form.elements.length; i++)
			if (field == field.form.elements[i])
			break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
} 
else
return true;
}      
// validation
function trim(str)
{
  return str.replace(/^\s+|\s+$/, '');
} 
function validateEmpty(fld) {
     if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        return 1;
    } else {
        fld.style.background = 'White';
		return 0;
    }
}
function validateChar(fld) {
	var iChars = "\ΓΕΒά!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
	var ifound = 0;
	ifound = validateEmpty(fld);
	if (ifound == 0)
	{
		for (var i = 0; i < fld.value.length; i++) {
			if (iChars.indexOf(fld.value.charAt(i)) != -1) {
				ifound += 1;
			}
		}
		if (ifound > 0)	{
			fld.style.background = 'Yellow';
		} else {fld.style.background = 'White';}		
	}
	return ifound;
}
function validateUsername(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a username.\n";
    } else if ((fld.value.length < 5) || (fld.value.length > 15)) {
        fld.style.background = 'Yellow'; 
        error = "The username is the wrong length.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = 'Yellow'; 
        error = "The username contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    } 
    return error;
}
function validatePassword(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter a password.\n";
    } else if ((fld.value.length < 7) || (fld.value.length > 15)) {
        error = "The password is the wrong length. \n";
        fld.style.background = 'Yellow';
    } else if (illegalChars.test(fld.value)) {
        error = "The password contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else if (!((fld.value.search(/(a-z)+/)) && (fld.value.search(/(0-9)+/)))) {
        error = "The password must contain at least one numeral.\n";
        fld.style.background = 'Yellow';
    } else {
        fld.style.background = 'White';
    }
   return error;
}   
function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        //error = "You didn't enter an email address.\n";
		return 1;
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        //error = "Please enter a valid email address.\n";
		return 1;
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        //error = "The email address contains illegal characters.\n";
		return 1;
    } else {
        fld.style.background = 'White';
		return 0;
    }
//    return error;
}
function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');     

   if (fld.value == "") {
        error = "You didn't enter a phone number.\n";
        fld.style.background = 'Yellow';
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else if (!(stripped.length == 10)) {
        error = "The phone number is the wrong length. Make sure you included an area code.\n";
        fld.style.background = 'Yellow';
    } 
    return error;
}
function dropdown(fld)  {
var name = fld.name;
var myindex=document.forms[0].elements[name].selectedIndex;
if (myindex==0)
{
	document.forms[0].elements[name].style.background = 'Yellow';
	return 1;
}
else {
	document.forms[0].elements[name].style.background = 'white';
	return 0;
	}
}
function radio() {
if (radio_selection=="")
alert("\nYou must check one of the radio buttons.");
else {
return true;
   }
}

// end validation

/*CountUp script
"January","February","March","April","May","June","July","August","September","October","November","December"
				usege functuion
				<div id="cpcontainer">&nbsp;</div>
				<script type="text/javascript">
				var princewedding=new countup("January 30, 2009 23:59:00", "days")
				princewedding.oncountup=function(result){
				var mycountainer=document.getElementById("cpcontainer")
				mycountainer.innerHTML="<span class='dcountupstyle'>"+result['days']+" <sup>???</sup> "+result['hours']+" <sup>????</sup> "+result['minutes']+" <sup>?????</sup> "+result['seconds']+" <sup>?????</sup></span>"
				}
				</script>
*/
function countup(startingdate, baseunit){
	this.currentTime=new Date()
	this.startingdate=new Date(startingdate)
	this.timesup=false
	this.baseunit=baseunit
	this.start()
}

countup.prototype.oncountup=function(){} //default action for "oncountup"

countup.prototype.start=function(){
	var thisobj=this
	this.currentTime.setSeconds(this.currentTime.getSeconds()+1)
	var timediff=(this.currentTime-this.startingdate)/1000 //difference btw target date and current date, in seconds
	var oneMinute=60 //minute unit in seconds
	var oneHour=60*60 //hour unit in seconds
	var oneDay=60*60*24 //day unit in seconds
	var dayfield=Math.floor(timediff/oneDay)
	var hourfield=Math.floor((timediff-dayfield*oneDay)/oneHour)
	var minutefield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour)/oneMinute)
	var secondfield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour-minutefield*oneMinute))
	if (this.baseunit=="hours"){ //if base unit is hours, set "hourfield" to be topmost level
		hourfield=dayfield*24+hourfield
		dayfield="n/a"
	}
	else if (this.baseunit=="minutes"){ //if base unit is minutes, set "minutefield" to be topmost level
		minutefield=dayfield*24*60+hourfield*60+minutefield
		dayfield=hourfield="n/a"
	}
	else if (this.baseunit=="seconds"){ //if base unit is seconds, set "secondfield" to be topmost level
		var secondfield=timediff
		dayfield=hourfield=minutefield="n/a"
	}
	var result={days: dayfield, hours:hourfield, minutes:minutefield, seconds:secondfield}
	this.oncountup(result)
	setTimeout(function(){thisobj.start()}, 1000) //update results every second
}

// --------------------------------------------------------------------
// Sets a cookie in the user's browser
//
// Parameters:
//		name		Name of the cookie
//		value		Value of the cookie
//		[expires]	Expiration date of the cookie (expires at end of 
//					session by default)
//		[path]		Path where the cookie may be accessed (path of calling 
//					document by default)
//		[domain]	Domain where the cookie may be accessed (domain of 
//					calling document by default)
//		[secure]	Boolean indicating if cookie requires secure connection
// --------------------------------------------------------------------
function SetCookie(name, value, expires, path, domain, secure)
{
    document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toUTCString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}


// --------------------------------------------------------------------
// Gets the value of the cookie
//
// Parameters:
//		name	Name of the cookie
//
// Returns a string containing the value of the cookie, or null if
// cookie does not exist in user's browser
// --------------------------------------------------------------------
function GetCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    
    if ( begin == -1 ) {
        begin = dc.indexOf(prefix);
        if (begin != 0) {
			return "";
		}
    }
    else {
        begin += 2;
    }
    
    var end = document.cookie.indexOf(";", begin);
    
    if ( end == -1 ) {
        end = dc.length;
    }
    
    return unescape(dc.substring(begin + prefix.length, end));
}


// --------------------------------------------------------------------
// Deletes a cookie from the user's browser
//
// Parameters:
//		name		Name of the cookie
//		[path]		Path of the cookie
//		[domain]	Domain of the cookie
// --------------------------------------------------------------------
function DeleteCookie(name, path, domain)
{
    if ( GetCookie(name) ) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Sun, 01-Jan-06 00:00:01 GMT";
    }
}