/**
 * This method is overridden to set the start day of week for the date
 * picker.
 */
function tu_getPreferredStartDayOfWeek() {
  // 0 is Sunday, 1 is Monday, in keeping with the builtin Date object.
  return parseInt(1, 10);
}



MSG_JAN = "Jan";
MSG_FEB = "Feb";
MSG_MAR = "Mar";
MSG_APR = "Apr";
MSG_MAY = "May";
MSG_JUN = "Jun";
MSG_JUL = "Jul";
MSG_AUG = "Aug";
MSG_SEP = "Sep";
MSG_OCT = "Oct";
MSG_NOV = "Nov";
MSG_DEC = "Dec";



MSG_JANUARY = "January";
MSG_FEBRUARY = "February";
MSG_MARCH = "March";
MSG_APRIL = "April";
MSG_MAY_LONG = "May";
MSG_JUNE = "June";
MSG_JULY = "July";
MSG_AUGUST = "August";
MSG_SEPTEMBER = "September";
MSG_OCTOBER = "October";
MSG_NOVEMBER = "November";
MSG_DECEMBER = "December";



MSG_MON = "Mon";
MSG_TUES = "Tue";
MSG_WED = "Wed";
MSG_THUR = "Thu";
MSG_FRI = "Fri";
MSG_SAT = "Sat";
MSG_SUN = "Sun";



MSG_MONDAY = "Monday";
MSG_TUESDAY = "Tuesday";
MSG_WEDNESDAY = "Wednesday";
MSG_THURSDAY = "Thursday";
MSG_FRIDAY = "Friday";
MSG_SATURDAY = "Saturday";
MSG_SUNDAY = "Sunday";



var MSG_SU = MSG_SUN;
var MSG_M = MSG_MON;
var MSG_TU = MSG_TUES;
var MSG_W = MSG_WED;
var MSG_TH = MSG_THUR;
var MSG_F = MSG_FRI;
var MSG_SA = MSG_SAT;

var MSG_SUNDAYS = "Sundays";
var MSG_MONDAYS = "Mondays";
var MSG_TUESDAYS = "Tuesdays";
var MSG_WEDNESDAYS = "Wednesdays";
var MSG_THURSDAYS = "Thursdays";
var MSG_FRIDAYS = "Fridays";
var MSG_SATURDAYS = "Saturdays";

var MSG_ORDINAL_1 = "first";
var MSG_ORDINAL_2 = "second";
var MSG_ORDINAL_3 = "third";



function modifyText(id, text) {
	if (document.getElementById) {
	  obj = document.getElementById(id);
	  obj.childNodes[0].data = text;
	}
}
function modifyTextNotClear(id, text) {
	if (document.getElementById && text != '') {
	  obj = document.getElementById(id);
	  obj.childNodes[0].data = text;
	}
}
function filterVisibleURL(text) {
	return text.replace(/^\s*/, '').replace(/\s*$/, '').replace(/^https?:\/\//, '').replace(/\/.*/, '').replace(/:[0-9]+$/, '');
}

function copyValue(destination, source) {
	if (document.getElementById) {
	  if (document.getElementById(destination) && document.getElementById(source)) {
		if ((document.getElementById(destination).value == '') && (document.getElementById(source).value != '')) {
		  document.getElementById(destination).value = document.getElementById(source).value;
		}
	  }
	}
}

function displayLength(field) {
	var count = 0;
	for (var i = 0; i < field.value.length; i ++) {
	  count += displayWidth(field.value.charAt(i));
	}
	return count;  
}

function displayWidth(ch) {
	if (ch < '\u04f9' ||
		ch == '\u05be' ||
		(ch > '\u05d0' && ch < '\u05ea') ||
		ch == '\u05F3' ||
		ch == '\u05f4' ||
		(ch > '\u0e00' && ch < '\u0e7f') ||
		(ch > '\u1e00' && ch < '\u20af') ||
		(ch > '\u2100' && ch < '\u213a') ||
		(ch > '\uff61' && ch < '\uffdc')) {
	  return 1;
	}
	return 2;
}

function overLengthIndex(field, maxlimit) {
	var count = 0;
	for (var i = 0; i < field.value.length; i++) {
	  count += displayWidth(field.value.charAt(i));
	  if (count > maxlimit) {
		return i;
	  }
	}
	return field.value.length;
}



function textCounter(fieldname, maxlimit) {
	var field;
	for(i=0; i < document.forms.length; ++i) {
	  var obj = document.forms[i].elements[fieldname];
	  if (obj) field = obj;
	}
	if (field == null) return false;
	
	var results = field.value.match(/\{keyword:[^\}]+\}/i);
	if (results) {
		maxlimit += "{keyword:}".length;
	}
	results = field.value.match(/\{keyword\}/);
	if (results) {
		maxlimit += "{keyword}".length - 1;
	}
	if (field.value.indexOf("{") == -1 ) {
	  if (displayLength(field) > maxlimit) {
		var maxindex = overLengthIndex(field, maxlimit);
		field.value = field.value.substring(0, maxindex);
	  }
	} else {
	  if (displayLength(field) > maxlimit) {
		field.style.color = 'red';
		return true;
	  }
	  else {
		field.style.color = 'black';
		return false;
	  }
	}
}

function revealForm(blockid) {
	changeObjectDisplay(blockid, 'block');
	window.location='#create';
}

function hideForm(blockid)  {
	changeObjectDisplay(blockid, 'none');
	window.location='#create';
}

function verifyCreativeLineLength() {
	if (textCounter('creative.line1', 25) ||
		textCounter('creative.line2', 35) ||
		textCounter('creative.line3', 35) ||
		textCounter('creative.visibleUrl', 35)) {
	 alert("One or more lines of your ad text exceeds our character limits. Please revise your ad text to comply with our limits.");
	 return false; 
	}
	return true;
}


function confirmLink(msg, link) {
	if(confirm(msg)) {
	  window.location=link;
	}
}

(function() {
var h=Object;function i(a,b){return a.disabled=b}var j="call",k=k||{},l=this,m=function(a,b,e){var f=a.split("."),c=e||l,d;!(f[0]in c)&&c.execScript&&c.execScript("var "+f[0]);while(f.length&&(d=f.shift()))if(!f.length&&typeof b!="undefined")c[d]=b;else c=c[d]?c[d]:(c[d]={})};
var o=function(a){var b=typeof a;if(b=="object")if(a){if(typeof a.length=="number"&&typeof a.splice!="undefined"&&!n(a,"length"))return"array";if(typeof a[j]!="undefined")return"function"}else return"null";else if(b=="function"&&typeof a[j]=="undefined")return"object";return b},p=function(a,b){if(b in a)for(var e in a)if(e==b&&h.prototype.hasOwnProperty[j](a,b))return true;return false};
if(h.prototype.propertyIsEnumerable)var n=function(a,b){return a instanceof h?h.prototype.propertyIsEnumerable[j](a,b):p(a,b)};else n=p;var q=function(a){var b=o(a);if(b=="object"||b=="array"){if(a.clone)return a.clone();var e=b=="array"?[]:{};for(var f in a)e[f]=q(a[f]);return e}return a},r=function(a,b,e){m(a,b,e)};(function(){var a="";function b(c){a=c}function e(c){if(a&&a!="")c.action=c.action+"#"+a;return true}function f(c,d){var g=document.getElementById(c);if(g){i(g["timeperiod.simpletimeperiod"],!d);i(g["timeperiod.begin.year"],d);i(g["timeperiod.begin.month"],d);i(g["timeperiod.begin.day"],d);i(g["timeperiod.begin.dateField"],d);i(g["timeperiod.end.year"],d);i(g["timeperiod.end.month"],d);i(g["timeperiod.end.day"],d);i(g["timeperiod.end.dateField"],d)}}r("dateRangePicker.changeFormActionAnchor",e);r("dateRangePicker.setAnchor",
b);r("dateRangePicker.toggleDateSelector",f)})();
})()
