﻿function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // if cookie exists
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1)
         end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}

function openSurvey(){
	var l = (screen.width - 800)/2-5;
	var t = (screen.height - 400)/2-20;
	var win_position = ',left='+l+',top='+t;
	window.open ('takesurvey.html','survey','width=800,height=400,location=0,menubar=0,scrollbars=1,status=1,toolbar=0,resizable=0'+win_position);
}

//checks if user is not in the main/pb/corp landing page then checks the rest
//have to hardcode due to the inconsistance of the url
var path = window.location.href;
var showsurvey = 1;
switch (path){
	case "http://www.ocbc.com/personal-banking/index.shtm" : 
	case "http://www.ocbc.com/personal-banking/" :
	case "http://ocbc.com/personal-banking/index.shtm" :
	case "http://ocbc.com/personal-banking/" :
	case "http://www.ocbc.com.sg/personal-banking/index.shtm" :
	case "http://www.ocbc.com.sg/personal-banking/" :
	case "http://ocbc.com.sg/personal-banking/index.shtm" :
	case "http://ocbc.com.sg/personal-banking/" :
	
	case "http://www.ocbc.com/corp-banking/index.shtm" : 
	case "http://www.ocbc.com/corp-banking/" :
	case "http://ocbc.com/corp-banking/index.shtm" :
	case "http://ocbc.com/corp-banking/" :
	case "http://www.ocbc.com.sg/corp-banking/index.shtm" :
	case "http://www.ocbc.com.sg/corp-banking/" :
	case "http://ocbc.com.sg/corp-banking/index.shtm" :
	case "http://ocbc.com.sg/corp-banking/" :
	
	case "http://www.ocbc.com/sme-banking/index.shtm" : 
	case "http://www.ocbc.com/sme-banking/" :
	case "http://ocbc.com/sme-banking/index.shtm" :
	case "http://ocbc.com/sme-banking/" :
	case "http://www.ocbc.com.sg/sme-banking/index.shtm" :
	case "http://www.ocbc.com.sg/sme-banking/" :
	case "http://ocbc.com.sg/sme-banking/index.shtm" :
	case "http://ocbc.com.sg/sme-banking/" :
	
	case "http://www.ocbc.com/global/main/index.shtm" : 
	case "http://www.ocbc.com/global/main/" :
	case "http://ocbc.com/global/main/index.shtm" :
	case "http://ocbc.com/global/main/" :
	case "http://www.ocbc.com.sg/global/main/index.shtm" :
	case "http://www.ocbc.com.sg/global/main/" :
	case "http://ocbc.com.sg/global/main/index.shtm" :
	case "http://ocbc.com.sg/global/main/" :
	
	case "http://192.168.1.9/OCBC/development/personal-banking_homepage/": showsurvey = 0; break;
	
}
if (showsurvey == 1){
	//checks if user has taken the survey or has clicked not to take
	var checkSurvey = get_cookie("ocbcsurvey");
	if (checkSurvey == ""){
		//checks if user has the survey window opened
		
		console.log(checkWindow);
		if (checkWindow == ""){
			var userDate = new Date();
			var sec = userDate.getSeconds()%2;
			if (sec == 0){
				//create checkwindow cookie
				document.cookie = "ocbcsurveywindow=1;path=/;";
				openSurvey();
			}
		}
	}
}
