var t;
function GetotherPage(newUrl){
   window.location = newUrl;
}

function EmailFormat(eField,msgWrong){
    if ($('#'+eField).val().length==0) {return true; }
    var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
    if($('#'+eField).val().match(emailExp)){
       $('#'+eField).css({'borderColor':''}); return true;
    } else {
       alert(msgWrong); $('#'+eField).css({'borderColor':'red'}); return false;
    } 
}

function SetCookie(cookieName,cookieValue,nDays) {
    // all cookies are deleted at closing browser/session
    var today = new Date();
    var expire = new Date();
    if (nDays==null || nDays==0) {nDays=1};
    expire.setTime(today.getTime() + nDays*1000);
    document.cookie = cookieName+'='+escape(cookieValue) +
( ( expire ) ? ";expires=" + expire.toGMTString() : "" );

}	 
function GetCookie(check_name) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	for ( i = 0; i < a_all_cookies.length; i++ ){
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name ) {
			b_cookie_found = true;
			//we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )	{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			//break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ){
		return null;
	}
}				

function CountLeft(field, count, max) {
// if the length of the string in the input field is greater than the max value, trim it
if (field.value.length > max) {
  field.value = field.value.substring(0, max);
} else {
// calculate the remaining characters
count.value = max - field.value.length;
}
}

function checkTimeZone() {
    // current date and time of user
    var rightNow = new Date();
    var date5 = rightNow;
    // first januari 1st for this user
    var date1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0);
    // find july 1st for this user
    var date2 = new Date(rightNow.getFullYear(), 6, 1, 0, 0, 0, 0);
    // convert januari 1st to GMT
    var temp = date1.toGMTString();
    var date3 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
    // convert july 1st to GMT 
    temp = date2.toGMTString();
    var date4 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
    // convert current time to GMT    
    temp = date5.toGMTString();
    var date6 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
    // find the difference in hours between januari 1 user and januari 1 GMT
    var hoursDiffStdTime = (date1 - date3) / (1000 * 60 * 60);
    // find the difference in hours between juli 1 user and juli 1 GMT 
    var hoursDiffDaylightTime = (date2 - date4) / (1000 * 60 * 60);
    // If the hours differ the user uses Daylight Saving Time
    if (hoursDiffDaylightTime>hoursDiffStdTime) { DstValidForThisUser=1;} else{ DstValidForThisUser=0;}
    // Calculate the minutes difference between user en GMT
    var minsDiffCurrentTime = Math.round((date5 - date6) / (1000 * 60));
    SetCookie("TimeZone",hoursDiffStdTime);
    SetCookie("DST_Difference",hoursDiffDaylightTime);
    SetCookie("DST_Used",DstValidForThisUser);
    SetCookie("Current_difference",minsDiffCurrentTime);
}
function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
} 
function getURLQuery(){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?"));
    strReturn = strQueryString.toUpperCase();
  }
  return unescape(strReturn);
} 
