function zipSearch(thePage,theName,wt,ht){
	leftPos= (screen.width-wt)/2;
	topPos = (screen.height-ht)/2;
	newWin1 = window.open(thePage,theName,'toolbars=0,status=0,resizeable=0,scrollbars=0,left='+leftPos+',top='+topPos+',width='+wt+',height='+ht);
	document.getSTYLE.target = theName;
	document.getSTYLE.submit();
}

/* This hijacks the onload event so that we can use it for our ads.  Other functions that need to be run at onLoad
should be added here. */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}


/* BEGIN: make title URL-safe
 * 
 * This encodes a title to be URL-safe. Used for google analytics event tracking.
 * Specifically, it strips HTML tags, converts spaces into underscores, and
 * removes punctuation/characters.  If a value greater than zero is passed, the
 * string will be truncated according to the count that was passed.
 */
makeURLsafe = function(str,chars) {
	var happyString = '';
	happyString = str.stripTags().replace(/[\.,;!#\$\/:\?'\(\)\[\]_\-\\]/g, "").replace(/^\s+|\s+$/g, '').replace(/ /gi, "_").replace("&nbsp", "_");
	if (chars > 0) {
		happyString = happyString.truncate(chars);
	}
	return happyString;
}
/* END: make title URL-safe */


/*
 * IFRAME AD FUNCTIONS
 * copied over from ad_functions.js
 */
    var ary = new Array();
    var iframeExpandY;
    var iframeRetractY;
    var iframeExpandX;
    var iframeRetractX;
	var adId; //variable passed by video player ad to define companion leaderboard ad

    /* Function that defines our ad object.  This is what is stored in the array and passed for injection. */
    function clsAd(strDivName, strAdURL, intAdWidth, intAdHeight) {
        this.DivName = strDivName;
        this.Url = strAdURL;
        this.Width = intAdWidth;
        this.Height = intAdHeight;
    }

    
	function InjectAd(objAd, adRand) {
        var url = objAd.Url.replace("%%adORD%%", adRand);
        $(objAd.DivName).innerHTML =
                '<IFRAME WIDTH='+ objAd.Width +' HEIGHT='+ objAd.Height +
                ' id="iframe_' + objAd.DivName + '" MARGINWIDTH=0 MARGINHEIGHT=0 HSPACE=0 VSPACE=0 FRAMEBORDER=0 SCROLLING=NO BORDERCOLOR=#FFFFFF ALLOWTRANSPARENCY=TRUE ' +
                ' src="' + url + '?">' +
                '</IFRAME>';
    }	
	
	/*Fix for galleries to generate new ord value */
	function InjectAdinGallery(objAd, ord) {
	 	var adsURL = objAd.Url.replace("[ORD]",ord);
		
        $(objAd.DivName).innerHTML =
                '<IFRAME WIDTH='+ objAd.Width +' onLoad="LoadNextAd();" HEIGHT='+ objAd.Height +
                ' id="iframe_' + objAd.DivName + '" MARGINWIDTH=0 MARGINHEIGHT=0 HSPACE=0 VSPACE=0 FRAMEBORDER=0 SCROLLING=NO BORDERCOLOR=#FFFFFF ALLOWTRANSPARENCY=TRUE ' +
                ' src="' + adsURL + '?">' +
                '</IFRAME>'; 
    }	
    	
	var ord = Math.floor(Math.random()*(10000000000000000000));
	    
	function InjectAd(objAd) {
	var adsURL = objAd.Url.replace("[ORD]",ord);
		
    $(objAd.DivName).innerHTML =
            '<IFRAME WIDTH='+ objAd.Width +' onLoad="LoadNextAd();" HEIGHT='+ objAd.Height +
            ' id="iframe_' + objAd.DivName + '" MARGINWIDTH=0 MARGINHEIGHT=0 HSPACE=0 VSPACE=0 FRAMEBORDER=0 SCROLLING=NO BORDERCOLOR=#FFFFFF ALLOWTRANSPARENCY=TRUE ' +
            ' src="' + adsURL + '?">' +
            '</IFRAME>'; 
    }
	
	globalTileIndex=1;
    
	function LoadNextAd() {
	   if (globalTileIndex <= ary.length)
	    {
		InjectAd(ary[globalTileIndex-1]);
		globalTileIndex++;
	     }
   }

    /* Calls the function that injects the ad into the div.  Note that Array.each() function
    requires the prototype.js library.*/
    //function LoadAds() {
     //   var adRand = Math.floor(Math.random()*(10000000000000000000)); // regenerate the random number
      //  ary.each(function(objAd) {InjectAd(objAd, adRand);});
    //}
	
	function LoadAds() {
	var ord = Math.floor(Math.random()*(10000000000000000000));
        ary.each(
			function(objAd){
				InjectAdinGallery(objAd, ord);
			}
			
		); 
    }
	
	
	function LoadLeaderboard(adId){
	  var adRand = Math.floor(Math.random()*(10000000000000000000)); // regenerate the random number
	  var url = 'http://ad.doubleclick.net/adi/video.mystyle.dart/;tile=14;sz=728x90;!category=default;akw=;ord=' + adRand + ';dc_seed=' + adId + ';'
        document.getElementById("ad_leaderboard").innerHTML =
                '<IFRAME WIDTH=728 HEIGHT=90'+
                ' id="iframe_divAd_728x90_1' + '" MARGINWIDTH=0 MARGINHEIGHT=0 HSPACE=0 VSPACE=0 FRAMEBORDER=0 SCROLLING=NO BORDERCOLOR=#FFFFFF ALLOWTRANSPARENCY=TRUE ' +
                ' src="' + url + '?">' +
                '</IFRAME>';
		
	}
    // Functions for expanding the iframe for our inhouse ads.
    function expandIframeHeight(iframeExpandY)
	{parent.document.getElementById("targetframe").height = iframeExpandY;}

	function retractIframeHeight(iframeRetractY)
	{parent.document.getElementById("targetframe").height = iframeRetractY;}

	function expandIframeWidth(iframeExpandX)
	{parent.document.getElementById("targetframe").height = iframeExpandY;}

	function retractIframeWidth(iframeRetractX)
	{parent.document.getElementById("targetframe").height = iframeRetractY;}

    var adORD = Math.floor(Math.random()*(10000000000000000000));
    addLoadEvent(LoadNextAd);
    
function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
function SetCookie(cookieName,cookieValue,nDays, path, domain) {
 	var today = new Date();
 	var expire = new Date();
 	if (nDays==null || nDays==0) nDays=1;
 		expire.setTime(today.getTime() + 3600000*24*nDays);
 		document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString()+";path="+path+";domain="+domain;
}
function Get_Cookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ){
		return null;
	}
	if ( start == -1 ) return null; 
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
		return unescape( document.cookie.substring( len, end ) );
}






/* BEGIN:  Poll JS */
function sendPollResults(poll_id, choice_selected, content_id, supp_id) {
	if(isNaN(choice_selected)){
		return false;
	}
	if(content_id!=null && content_id!=""){
		content_id="&content_id="+content_id;
	}
	else {
		content_id="";
	}
	var myAjax = new Ajax.Request("/mystyle/services/processPoll.jsp",
		{
			method: 'get',
			parameters: "poll_id=" + poll_id + "&choice_selected=" + choice_selected+content_id + "&supp_id=" + supp_id,
			onComplete: updateCaptchaPoll
		});
		return true;
}
function sendPollResultsCaptcha(poll_id, choice_selected, content_id, supp_id, captcha) {
	if(isNaN(choice_selected)){
		return false;
	}
	if(content_id!=null && content_id!=""){
		content_id="&content_id="+content_id;
	}
	else {
		content_id="";
	}
	if(captcha!=null && captcha!=""){
		captcha="&captchaEntry="+captcha;
	}
	else {
		captcha="";
	}
    var myAjax = new Ajax.Request("/mystyle/services/processPoll.jsp",
		{
			method: 'get',
			parameters: "poll_id=" + poll_id + "&choice_selected=" + choice_selected+content_id+captcha + "&supp_id=" + supp_id,
			onComplete: updateCaptchaPoll
		});
		return true;
}
function sendRateItPollResults(poll_id, choice_selected, content_id, sectionPath) {
	if(isNaN(choice_selected)){
		return false;
	}
	if(content_id!=null && content_id!=""){
		content_id="&content_id="+content_id;
	}
	else {
		content_id="";
	}
	// CMS-606
	/*
	var myAjax = new Ajax.Request(sectionPath+"/services/processPoll.jsp",
	{
		method: 'get',
		parameters: "poll_id=" + poll_id + "&choice_selected=" + choice_selected+content_id,
		onComplete: updatePoll
	});
	*/
	// Add a GalleryItemId parameter to let processPoll know it is 
	// coming from photo gallery
	//
	// TODO: this should originate from photo gallery callers of this 
	// method such as rateItPoll.tag. galleries.tag. gallery_item.jsp, etc.
	//
	var myAjax = new Ajax.Request(sectionPath+"/services/processPoll.jsp",
	{
		method: 'get',
		parameters: "poll_id=" + poll_id + "&choice_selected=" + choice_selected + content_id + "&GalleryItemId=placeholderForNow",
		onComplete: updatePoll
	});
	// CMS-606
	return true;
}
/* NOT ONLY IS THIS FUNCTION NOT USED, IT ALSO BREAKS THE FOOTER MODAL WINDOW!!! */
/* it is being used for the customPoll --JChen*/
function collectChoiceSelected(form, choice_collected,choice_selected){
	var len = form.elements.length;
	var selected=choice_selected.value;
	var collected=choice_collected.value+","+selected;
	for(var i=0; i<len; i++){
		var curr = form.elements[i];
		if(curr.name==choice_selected.name){
			var currVal = curr.value;
			if(currVal!=selected && collected.indexOf(currVal)!=-1){
				collected=collected.replace(","+currVal,"");
			}
		}
	}
	choice_collected.value=collected;
}


function sendPollMultiQuestionResults(poll_id, choice_selected, content_id, coID) {
	if (coID > 0) {
    	var captcha = hex_md5(document.getElementById('poll_uword').value);
	    Delete_Cookie("PostCookie","/",".mystyle.com");
	    SetCookie("PostCookie",coID,5,"/",".mystyle.com");
	}

    var ary = choice_selected.value.split(",");
	for(var i=0; i<ary.length; i++){
		if(ary[i]!="" && !isNaN(ary[i])){
			if (coID > 0) {
				sendPollResultsCaptcha(poll_id, ary[i], content_id, '', captcha);
			} else {
				sendPollResults(poll_id, ary[i], content_id);
			}
		}
	}
}
function updatePoll(response) {
	//alert('in updatePoll() start');
	//var resp = response.responseText;
	var jsonObj = null;
	//alert('responseText= ' + response.responseText);
	jsonObj = eval("(" + response.responseText + ")");

	//alert('jsonObj= ' + jsonObj);
	//alert('jsonObj.answerSize= ' + jsonObj.answerSize);

	var pollResults = "";
	pollResults += "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";
	if (jsonObj.thankYouMessage) {
		pollResults += "<tr>";
		pollResults += "<td class=\"selection\">" + jsonObj.thankYouMessage + "</td>";
		pollResults += "</tr>";
	}
	else {
		for(var i = 0; i < jsonObj.answerSize; i++) {
			pollResults += "<tr>";
		 	pollResults += "<td class=\"percentage\">" + eval("jsonObj.percentage" + i) + "</td>";
			pollResults += "<td class=\"selection\">" + eval("jsonObj.answer" + i) + "</td>";
			pollResults += "</tr>";
		}
	}
	pollResults +=  "</table>";
	$("poll-div").innerHTML = pollResults;
}
function updateCaptchaPoll(response) {

	var jsonObj = null;
	//alert('responseText= ' + response.responseText);
	jsonObj = eval("(" + response.responseText + ")");

	console.log(jsonObj); // TEST ECHO OF THE JSON RETRIEVED OBJECT
	
	if (jsonObj.errorMessage!=null) {
		$('poll_captcha_message').update(jsonObj.errorMessage);
	} else {
		if (jsonObj.thankYouMessage) {
			Element.hide('poll-container-'+jsonObj.poll_id);	//hide poll
			Element.show('thank-you-'+jsonObj.poll_id);			//show thanks msg
		} else {
			$('voteBtn-'+jsonObj.poll_id).hide();				//hide vote submit button
			var poll_vote_array = $$('#poll-container-'+jsonObj.poll_id+' .vote_item input');	//hide vote radio buttons
			poll_vote_array.each(function(poll_vote_array){
				poll_vote_array.hide();
			});
			var poll_results_array = $$('#poll-container-'+jsonObj.poll_id+' .vote_item span');		//show results
			poll_results_array.each(function(poll_results_array){
				poll_results_array.show();
			});
			$('poll_captcha_'+jsonObj.poll_id).hide();						//hide captcha
		}
	}
}
GalleryPoll = {
	DisableVoting: function () {
		var poll_link_array = $$('.poll_choice_link');
		poll_link_array.each(function(poll_link_array){
			poll_link_array.removeAttribute('onclick');
		});
	}
}
BlogPoll = {
	Inject: function (pollID) {
		new Ajax.Updater("blog_poll_" + pollID, "/mystyle/includes/jsp/blog_poll.jsp?pollID=" + pollID, {
			onFailure: function() {
				$("blog_poll_" + pollID).update("There was an error loading the poll. Refresh the page to try again.");
			}
		});
	}
}

/* END:  Poll JS */




/* BEGIN: Modal form validation */
validateSendForm = function(){
	if ($F('friendEmail')=='') {
		alert('Please enter a recipient')
	}
	else if ($F('yourEmail')=='') {
		alert('Your email address is blank!')
	}
	else if(($F('friendEmail').lastIndexOf('@') >= $F('friendEmail').lastIndexOf('.')) || ($F('friendEmail').lastIndexOf('.') > ($F('friendEmail').length - 3))) {
		alert($F('friendEmail')+' is not a valid email address.')
	}
	else if(($F('yourEmail').lastIndexOf('@') >= $F('yourEmail').lastIndexOf('.')) || ($F('yourEmail').lastIndexOf('.') > ($F('yourEmail').length - 3))) {
		alert($F('yourEmail')+' is not a valid email address.')
	}
	else {
		/* Oringal Method */
		new Ajax.Updater('overlay_send_form', '/mystyle/includes/jsp/email.jsp', {
			parameters:$('overlay_send_form').serialize()
		});
	}
}

function keyHolder(textAreaId)
{
	if ($F(textAreaId).length >= 1000)
		return false;
}

function cutMsg(textAreaId, charsLeftId)
{
	enteredText = $(textAreaId).value;
	$(charsLeftId).update((1000 - enteredText.length > 0 ? 1000 - enteredText.length : 0));
	if (enteredText.length > 1000)
	{
		$(textAreaId).value = enteredText.substr(0, 1000);
		return false;
	}
}

function disableAnchor(id)
{
	if (!($(id).value.length > 0))
		return false;
}

//function submitFormLoader(){
//	// update the submit button styles and disable it to prevent any more clicks
//	$('submit_animator').style.visibility='visible';
//	$('overlay_submit_button').className ='button_send_deactive';
//	$('overlay_submit_button').disabled = 'true';
//}
/* END: Modal form validation */