/*
   var ua = window.navigator.userAgent;
   if(ua.indexOf('iPhone') > -1){
    window.location = 'http://iphone.pollpub.com';
   }
*/

function animateHeight(id, size) {
el = document.getElementById(id);

var h_size1 = el.offsetHeight;

	if (grow) {
		if (h_size1 < size)	{
			el.style.height = h_size1 + (size - h_size1) / 5 + 0.5  +"px";
			document.getElementById('navContainer').style.top = h_size1 - (h_size1 / size) * 45 - 1 -115  +"px";
			grow=true;
			setTimeout("animateHeight('" + id + "','" + size + "')", 1);
		}
		else grow=false;
	}
	else {
		if (h_size1 >= 5) {
			el.style.height = h_size1 - (h_size1 / size) * 45 - 1  +"px";
			document.getElementById('navContainer').style.top =  h_size1 - (h_size1 / size) * 45 - 1 - 295 +"px";
			grow=false;
			setTimeout("animateHeight('" + id + "','" + size + "')", 1);
		}
		else
			grow=true;
	}
}


function shownextbut()
{
//alert("i'm hit");
document.getElementById('linkbuttonNext').style.display = "block";
}


function ShowHideRestricted( positionid, action, target )
{
	posid = "divrestricted" + positionid;
	posid2 = "divsetup" + positionid;

	document.getElementById(posid).style.display = 'none'; 	
	document.getElementById(posid2).style.display = 'none'; 

	if (target == "restricted") {
		posid = "divrestricted" + positionid; }
	else if (target == "setup") {
		posid = "divsetup" + positionid; }
	
	if (action == "show")
	document.getElementById(posid).style.display = 'block';
	else 
	document.getElementById(posid).style.display = 'none'; 
}

function ShowHideJudges( action )
{
	var judgedl = "dljudges";

	if (action == "show")
	document.getElementById(judgedl).style.display = 'block';
	else 
	document.getElementById(judgedl).style.display = 'none'; 
}


function ClearText(calleritem)
{
//alert("clear!");
//alert(calleritem.value);
//alert(calleritem);
if ( calleritem.value == "Enter your question here." || calleritem.value == "(optional) Enter more details about your question or poll." || calleritem.value ==  "Type poll answer here." )
{
	calleritem.value = "";
	calleritem.style.color = 'black';
}

}


function ShowHelp(help)
{

helpid = 'help' + help;
hidehelp();
document.getElementById(helpid).style.display = "inline";

}

function ClearTextShowHelp(calleritem,help)
{
//alert("clear!");
//alert(calleritem.value);
//alert(calleritem);
if ( calleritem.value == "Enter your question here." || calleritem.value == "(optional) Enter more details about your question or poll." || calleritem.value ==  "Type poll answer here." || calleritem.value == "(Optional) Keywords that will help people find your poll better, separated by spaces." )
{
//	alert(calleritem.value);
	calleritem.value = "";
	calleritem.style.color = 'black';
}

calleritem.style.color = 'black';
helpid = 'help' + help;

hidehelp();
document.getElementById(helpid).style.display = "inline";



}

function hidehelp()
{

document.getElementById('helptitle').style.display = "none";
document.getElementById('helpdesc').style.display = "none";
document.getElementById('helpcat').style.display = "none";
document.getElementById('helpnum').style.display = "none";
document.getElementById('helpprivate').style.display = "none";
document.getElementById('helppublic').style.display = "none";
document.getElementById('helpstart').style.display = "none";

}

/*******************************************************************************

function for positioning the page footer on pages with absolute positioning

*******************************************************************************/
/*
function footerPos(){
			//get the detail height
			var detail = document.getElementById('prodDetail').offsetHeight;
			
			//make sure that the footer is lower than the lowest element, either the description, or the note
			var footTop = (detail >= 250) ? (detail + 263 + 105) : (250 + 263 + 105);
			
			document.getElementById('footer').style.top = footTop + 'px';
			//now show the footer
			document.getElementById('footer').style.visibility = 'visible';
		}

*/
/*******************************************************************************

function for validating the contact us form

*******************************************************************************/
/*	
function isEmail(str){
	if(str == '') return false;
	var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i
	return re.test(str);
	}
	
	// returns true if the string only contains characters A-Z or a-z
function isAlpha(str){
	var re = /[^a-zA-Z]/g
	if (re.test(str)) return false;
	return true;
}

// returns true if the string is empty
function isEmpty(str){
	return (str == null) || (str.length == 0);
}

function validateForm(formname){
		//init an error message
			err = 'The following errors have occurred: \n';
			err_count = 0;
			aspprefix = 'Contactus1_';
			
			
			var firstname = document.getElementById(aspprefix + 'textboxFirstName').value;
			var lastname = document.getElementById(aspprefix + 'textboxLastName').value;
			var email = document.getElementById(aspprefix + 'textboxEmail').value;
			var comments = document.getElementById(aspprefix + 'textareaMessage').value;			

		//validate form fields
		
		if(!isAlpha(firstname)){
			err += 'Your First Name is not valid.\n';
			err_count++;
		}
		
		if(!isAlpha(lastname)){
			err += 'Your Last Name is not valid.\n';
			err_count++;
		}
		
		if(!isEmail(email)){
			err += 'Your Email is not valid.\n';
			err_count++;
		}
		
		if(isEmpty(comments)){
			err += 'Your Comments/Questions are empty';
		}
		
		if(err_count == 0){
		return true;
		}else{
		alert(err);
		return false;
		}
	} 
	
*/

function handlestar(star)
{
//alert (star.id);

switch (star.id)
{
case 'ctl00_LeftSide_ucVoteBig1_star1' : //alert ('star1');
					 document.getElementById('yourrating').innerHTML = "Dislike:";
					 document.getElementById('imgstar1').src = "images/filledstar.gif";	
					 document.getElementById('imgstar2').src = "images/emptystar.gif";			
					 document.getElementById('imgstar3').src = "images/emptystar.gif";			
					 document.getElementById('imgstar4').src = "images/emptystar.gif";			
					 document.getElementById('imgstar5').src = "images/emptystar.gif";							 
					 break;
case 'ctl00_LeftSide_ucVoteBig1_star2' : //alert ('star2');
					 document.getElementById('yourrating').innerHTML = "Below Avg:";
					 document.getElementById('imgstar1').src = "images/filledstar.gif";	
					 document.getElementById('imgstar2').src = "images/filledstar.gif";	
					 document.getElementById('imgstar3').src = "images/emptystar.gif";			
					 document.getElementById('imgstar4').src = "images/emptystar.gif";			
					 document.getElementById('imgstar5').src = "images/emptystar.gif";						 
					 break;
case 'ctl00_LeftSide_ucVoteBig1_star3' : //alert ('star3');
					 document.getElementById('yourrating').innerHTML = "Average:";
					 document.getElementById('imgstar1').src = "images/filledstar.gif";	
					 document.getElementById('imgstar2').src = "images/filledstar.gif";	
					 document.getElementById('imgstar3').src = "images/filledstar.gif";	
					 document.getElementById('imgstar4').src = "images/emptystar.gif";			
					 document.getElementById('imgstar5').src = "images/emptystar.gif";					 
					 break;
case 'ctl00_LeftSide_ucVoteBig1_star4' : //alert ('star4');
					 document.getElementById('yourrating').innerHTML = "Good:";
					 document.getElementById('imgstar1').src = "images/filledstar.gif";	
					 document.getElementById('imgstar2').src = "images/filledstar.gif";	
					 document.getElementById('imgstar3').src = "images/filledstar.gif";	
					 document.getElementById('imgstar4').src = "images/filledstar.gif";	
					 document.getElementById('imgstar5').src = "images/emptystar.gif";								 
					 break;
case 'ctl00_LeftSide_ucVoteBig1_star5' ://alert ('star5');
					 document.getElementById('yourrating').innerHTML = "Great:";
					 document.getElementById('imgstar1').src = "images/filledstar.gif";	
					 document.getElementById('imgstar2').src = "images/filledstar.gif";	
					 document.getElementById('imgstar3').src = "images/filledstar.gif";	
					 document.getElementById('imgstar4').src = "images/filledstar.gif";	
					 document.getElementById('imgstar5').src = "images/filledstar.gif";							 
					 break;					 
					 
default : 	alert ('nobody');
			break;
}
/*
temprating = star.id;
rating = temprating.replace('Vote1_star','')
	
	for (i = 1; i <= rating; i++)
	{
		document.getElementById('imgstar' + i).src = "images/filledstar.gif";			
	}
	
	leftover = 5 - rating;
	alert(leftover);
	
	for (i = 1; i <= leftover;i++)
	{
		
		tempnum = i + rating;
		document.getElementById('imgstar' + tempnum).src = "images/emptystar.gif";			
	}	

*/
}


function alreadyrated()
{
	alert("Already rated this poll.");
	document.getElementById('yourrating').innerHTML = "Thank You!";	
}

function alreadyfav()
{
	alert("This is already in your favorites");
	//document.getElementById('yourrating').innerHTML = "Thank You!";	
}


function fin()
{
__doPostBack('linkbuttonNext','');
}

function showhideupload(check,id)
{
//alert(check.checked);
//alert(id);	
var newid = id;
var idname_start = "ctl00_LeftSide_Pollwizard1_Wizard1_repeaterEntrants_ctl0";
//alert(newid);
//newcontrol = "ctlWizardStep_entrant"+newid+"_ruploadPhoto_wrapper"
if (!check.checked)
{
   // alert(idname_start+newid+'_fileuploadPhoto');
    //new Effect.SlideUp(idname_start+newid+'_fileuploadPhoto',{duration:0.3});
    new Effect.SlideUp('ctl00_LeftSide_Pollwizard1_Wizard1_repeaterEntrants_ctl01_fileuploadPhoto',{duration:0.3});
    
	//document.getElementById(idname_start+newid+'_ruploadPhoto_wrapper').style.display = "none";
}
else
    
    new Effect.SlideDown('ctl00_LeftSide_Pollwizard1_Wizard1_repeaterEntrants_ctl01_fileuploadPhoto',{duration:0.3});
    //new Effect.SlideDown(idname_start+newid+'_fileuploadPhoto',{duration:0.3});
	//document.getElementById(idname_start+newid+'_ruploadPhoto_wrapper').style.display = "inline";


}

function showhidemp3(check,id)
{
//alert(check.checked);
//alert(id);	
var newid = id - 1;
var idname_start = "ctl00_LeftSide_Pollwizard1_Wizard1_repeaterEntrants_ctl0";



//alert(newid);
//newcontrol = "ctlWizardStep_entrant"+newid+"_ruploadPhoto_wrapper"
if (!check.checked)
{
    new Effect.SlideUp(idname_start+newid+'_ruploadMp3_wrapper',{duration:0.3});
//	document.getElementById(idname_start+newid+'_ruploadMp3_wrapper').style.display = "none";
}
else
    new Effect.SlideDown(idname_start+newid+'_ruploadMp3_wrapper',{duration:0.3});
	//document.getElementById(idname_start+newid+'_ruploadMp3_wrapper').style.display = "inline";


}


function showhidetitleupload(check)
{

if (!check.checked) document.getElementById('ctlWizardStep_ruploadPhoto_wrapper').style.display = "none";
else document.getElementById('ctlWizardStep_ruploadPhoto_wrapper').style.display = "inline";


}


/*** Ajax  ***/

//builds a xmlrequestobject used for AJAX 
//For more information on ajax technology go to http://en.wikipedia.org/wiki/AJAX
function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)	
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

var httpvideo = getHTTPObject();


function showhidevideo(check,id)
{
//alert(check.checked);
//alert(id);	
var newid = id;// - 1;
//alert(newid);
//newcontrol = "ctlWizardStep_entrant"+newid+"_ruploadPhoto_wrapper"
if (!check.checked)
{
    new Effect.SlideUp('addvideo'+newid,{duration:0.3});
	//document.getElementById('addvideo'+newid).style.display = "none";
}
else
    new Effect.SlideDown('addvideo'+newid,{duration:0.3});
	//document.getElementById('addvideo'+newid).style.display = "inline";

}//end of function

var currentpos;

function findvideo(videopos)
{
//alert('findme');
var videoembed = document.getElementById('videoembed' + videopos);
vid = videoembed.value;
temphidden = "ctlWizardStep_entrant"+(videopos - 1)+"_hiddenvideoid";

//alert(temphidden);
/*
alert(videoembed.value);
arvid = videoembed.value.split("?v="); 
vid = arvid[1]; 
alert(vid); */
currentpos = videopos;
checkforvideo(vid);
}

function checkforvideo( video_id )
{
//	alert('sent rated: ' + id + ', rating: ' + rating);	
/*	document.getElementById('divClientMessages').innerHTML = "Hey!";*/
  if (httpvideo.readyState == 4 || httpvideo.readyState == 0)
  {
	  client_ajax_url = "findvideo.aspx";
	  param = "?pollpubembedcode=" + video_id; //method=youtube.videos.get_details&dev_id=IRap9egoTQ0&video_id=gykVhmA5CcE";// '?rating=' + rating + '&entry_id=' + id;
 	  httpvideo.open("GET", client_ajax_url + param, true);	
  	  httpvideo.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
      httpvideo.onreadystatechange = handleVideoHttpResponse; //set handler for readystatechange event
      httpvideo.send(param); //send query to .net page	 
	  
	  //alert ( param );
  } 
}


function handleVideoHttpResponse()
{	
 	if (httpvideo.readyState == 4) 
 	{
		
  	result = httpvideo.responseText;
  	
  	
  	if (result != "novideo")
  	{
	//alert(result);
  	results = result.split('|');

	//parse result  	
  	video_thumbnail = results[0]; //video thumbnail
  	video_guid = results[1]; //video site id
  	video_id = results[2]; //pollpub video_id
  	video_title = results[3]; //video title
  	
  	
	//document.getElementById(temphidden).value;	
	document.getElementById('videoresults' + currentpos).innerHTML = "<a class=\"apreviewvideo\" onclick=\"javascript:preview_video('"+video_guid+"',"+currentpos+")\"> &nbsp;&nbsp;<img src=\""+video_thumbnail+"\" /> <br/>Click To Preview Video</a>";
	
	dotnetpos = currentpos - 1;
	
	
	//updated to for new wizard
	//use hiddenfile.uniqueid for real id
	temphidden = "ctl00_LeftSide_Pollwizard1_Wizard1_repeaterEntrants_ctl0"+dotnetpos+"_hiddenEntrantVideoId";
	temptitle  = "ctl00_LeftSide_Pollwizard1_Wizard1_repeaterEntrants_ctl0"+dotnetpos+"_textboxTextTitle";
	
	temphidden_poll = "ctl00_LeftSide_Pollwizard1_Wizard1_hiddenVideoId";
	//temptitle  = "ctlWizardStep_entrant"+dotnetpos+"_textboxTextTitle";
	//temphidden = "ctlWizardStep_entrant"+dotnetpos+"_hiddenvideoid";
	
	
	
	//temptextbox = "ctlWizardStep_entrant"+dotnetpos+"_textboxVideoId"
	
	//document.getElementById(temptextbox).value = video_id;	
	if (dotnetpos != -1)
	{
	    document.getElementById(temphidden).value = video_id;
	    document.getElementById(temptitle).value = video_title;
	}
	else
	{
	    document.getElementById(temphidden_poll).value = video_id;	    
	}
	//alert(temphidden + "value should equal: " + video_id);
	}//end of if not "novideo"
	else
	alert("Sorry, YouTube video cannot be found.  Please re-paste the YouTube embed code and try again!");
	
	
	
  	} //end of if httpproject.readystate == 4
}

var alreadyshown = false;

function preview_video(video_guid,pos)
{
//alert(video_guid);

if ( alreadyshown == false ) 
{
viewobject = "<a class=\"closepreview\" href=\"javascript:close_preview("+pos+");\">Close Preview</a><br/><object width=\"425\" height=\"350\"><param name=\"movie\" value=\"http://www.youtube.com/v/j97V-aMjeTk\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"http://www.youtube.com/v/"+video_guid+"\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"425\" height=\"350\"></embed></object>";
document.getElementById('videopreview' + pos).innerHTML = viewobject;
document.getElementById('videoresults' + pos).style.display = "none";
alreadyshown = true;
}
else
{
//alert('already saw this');
document.getElementById('videopreview' + pos).style.display = "block";
document.getElementById('videoresults' + pos).style.display = "none";
}

//videopreview
}

function close_preview(pos)
{
document.getElementById('videoresults' + pos).style.display = "block";
document.getElementById('videopreview' + pos).style.display = "none";

}


function favoriteadded()
{
alert("added");

}


function loginmessage(action)
{
alert("Please login or sign-up to use this function");

}



/* Poll Admin  */

//builds a xmlrequestobject used for AJAX 
//For more information on ajax technology go to http://en.wikipedia.org/wiki/AJAX
function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)	
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

var httpuser = getHTTPObject();

//close open divs on row (if any open), then perform slideout
function closeDivAndUpdate( comp_id , thisaction, targetelement, thiselement )
{

//alert(thiselement.id);

//baseid = thiselement.id.split('linkbutton')[0];

//alert(baseid);

//results = result.split('|');
	
//	lastuserid2 = results[0];	
baseid = thiselement.id.split('linkbutton')[0];

//alert ( rownum + thisaction + targetelement );
//close the div that just was saved 
new Effect.SlideUp(targetelement,{duration:0.3});
//send off update to ajax
SendUserUpdate(comp_id , thisaction, baseid); //this function will use the thisaction to figure out 

return false;
}


lastuserid = "";


function SendUserUpdate(user_id, action, baseid) {
 
  //check if xmlrequest object is ready
  if (httpuser.readyState == 4 || httpuser.readyState == 0) {
  
  url_out = "ajax_1.aspx"; 
  param = '?action=' + action + '&id=' + user_id;
  
  lastuserid=user_id;
  
  
  //add additional parameters needed for each action
	switch (action)
	{
		case 'edit':
		

		privacy = document.getElementById(baseid + 'dropdownPrivacy').value;
		website = document.getElementById(baseid + 'textboxWebsite' ).value;
		strict = document.getElementById(baseid + 'checkboxStrict' ).checked;
		
//		alert('before');
//		alert(privacy);
//		alert(website);
//		alert(strict);

		
		//alert( flname + email );
		
		param = param + '&privacy=' + privacy + '&strict=' + strict + '&website=' + website;
        alert(param);
		break;
		
		case 'delete':
		
//		office_id = document.getElementById('inputoffice_id').value;
		param = param + '&password=' + 'abc';
		break;

		case 'password':
		newpassword = document.getElementById('newpassword' + user_id).value;		
		param = param + '&newpassword=' + newpassword;
		document.getElementById('newpassword' + user_id).value = "";				
		break;
		
		case 'expire':
		passwordexpire = document.getElementById('month' + user_id).value + '/' + document.getElementById('day' + user_id).value + '/' + document.getElementById('year' + user_id).value;
		param = param + '&passwordexpire=' + passwordexpire;
		alert(param);
		break;
		
		default:
		param = param + '&name=test unknown action';			
		break;
	}
		  
  
  
  //  alert (url_out + param);

  httpuser.open("POST", url_out + param, true);
  
  httpuser.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  httpuser.onreadystatechange = handleUserUpdate; //set handler for readystatechange event
  httpuser.send(param); //send query to .net page
  

   } //end of if
  else  //wait a second, not ready
  {
		setTimeout('SendUserUpdate(userid,action);',500);
  }
  
}



function handleUserUpdate()
{
 if (httpuser.readyState == 4) 
 {
  	result = httpuser.responseText;
	
	//alert(result); 
	
	results = result.split('|');
	
	lastuserid2 = results[0];	
	lastaction = results[1];
	statusmessage = results[2];
	
	lastuserid2 = lastuserid2.replace(/^\s*|\s*$/g,"") 
	lastdivrow = 'divinforow' + lastuserid2;	
	
	//Show result, Comment out after debugging
	//alert(lastuserid2);
	//alert(last); 
	//alert(lastdivrow);
	//alert(lastuserid);		
	
	//TODO: add check for just plan php error
	if (result.indexOf('OK') != -1)
	{

		
		//if action was name
		if (lastaction == "edit")
		{		
			//show green highlight effect
			new Effect.Highlight('mainrow' + lastuserid2,{startcolor:'#ccffcc', endcolor:'#f2f2f2', delay:.4}); 	
			
			document.getElementById('divStatus').style.color = "#3A6A44";
			document.getElementById('divStatus').innerHTML = "Changes Saved";		
			document.getElementById('divStatus').style.display = "block";
			new Effect.Fade('divStatus',{delay:4});					
		}
		
		//if action was delete
		if (lastaction == "delete")
		{
			new Effect.Fade('mainrow' + lastuserid2);				
			
			document.getElementById('divStatus').style.color = "#3A6A44";
			document.getElementById('divStatus').innerHTML = "User Deleted";		
			document.getElementById('divStatus').style.display = "block";
			new Effect.Fade('divStatus',{delay:4});					
		}		
	
		//if action was password change
		if (lastaction == "password")
		{
			//show green highlight effect
			new Effect.Highlight(lastdivrow,{startcolor:'#ccffcc', endcolor:'#f2f2f2', delay:.4}); 				
			
			document.getElementById('divStatus').style.color = "#3A6A44";
			document.getElementById('divStatus').innerHTML = "Password Changed";		
			document.getElementById('divStatus').style.display = "block";
			new Effect.Fade('divStatus',{delay:4});					
		}		
		
		//if action was password expiration change
		if (lastaction == "expire")
		{
			//show green highlight effect
			new Effect.Highlight(lastdivrow,{startcolor:'#ccffcc', endcolor:'#f2f2f2', delay:.4}); 				
			newexpire = results[3];				
			
			document.getElementById('divStatus').style.color = "#3A6A44";
			document.getElementById('divStatus').innerHTML = "Password Expiration Set to " + newexpire;		
			document.getElementById('divStatus').style.display = "block";
			new Effect.Fade('divStatus',{delay:4});					
		}			
	
		

	}
	//if something went wrong or error
	else
	{
		//alert('BAD');
		//show red highlight effect  
		document.getElementById('divStatus').style.color = "#C21818";
		document.getElementById('divStatus').innerHTML = statusmessage;
		document.getElementById('divStatus').style.display = "block";		
		
		if (lastaction == "name")
		{				
			newflname = results[3];
			newemail = results[4];	
			document.getElementById('aName' + lastuserid2).innerHTML = newemail + '<br/>(' + newflname + ')';		
		}
		
		new Effect.Highlight(lastdivrow,{startcolor:'#C21818', endcolor:'#f2f2f2', delay:.4});		
		new Effect.Fade('divStatus',{delay:4});			
	}


  }		
}


