/* ADD ONLOAD FUNCTIONS */
	addLoadEvent(SearchSwap);

function SearchSwap(Flag){
	if(document.getElementById('q')){
		var Element = document.getElementById('q');
		if(Element.value==''){
			Element.value='Search Here';
		}
		else if(Element.value=='Search Here'){
			Element.value='';
		}
		if(Flag == 1){
			Element.style.color='#000000';
			Element.style.borderColor='#F5A01B';
		} else {
			Element.style.color='#808080';
			Element.style.borderColor='';
		}
	}
}

var myimages = new Array();
function preloading(){
	for (x=0; x<preloading.arguments.length; x++){
		myimages[x] = new Image();
		myimages[x].src = 'http://www.teenparent.tv/layout/images/nav_'+preloading.arguments[x]+'.gif';
	}
}
function RollOver(Element, state){
	if(state==1){
		Element.src='http://www.teenparent.tv/layout/images/nav_'+Element.id+'_over.gif';
	} else {
		Element.src='http://www.teenparent.tv/layout/images/nav_'+Element.id+'.gif';
	}
}

function RemoveElement(Element) {

	if(document.getElementById(Element)){
		var Child = document.getElementById(Element);

		if(Child.parentNode){
			Child.parentNode.removeChild(Child);
		}

	}

}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function AddUnloadEvent(func) {
  var oldunload = window.unload;
  if (typeof window.unload != 'function') {
    window.unload = func;
  } else {
    window.unload = function() {
      if (oldunload) {
        olunload();
      }
      func();
    }
  }
}

function ajax(Url){
	window.frames['hiframe'].location=Url;
}

function ajaxsave(Url){
	ajaxload(Url);
}
function ajaxload(url, ElementEndUpdate) {
    var httpRequest;

    loading();

    if (window.XMLHttpRequest) {
        httpRequest = new XMLHttpRequest();
        if (httpRequest.overrideMimeType) {
            httpRequest.overrideMimeType('text/html');
        }
    }
    else if (window.ActiveXObject) {
        try {
            httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {}
        }
    }

    if (!httpRequest) {
        alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }
    httpRequest.onreadystatechange = function() { AjaxEnd(httpRequest, ElementEndUpdate); };
    httpRequest.open('GET', url, true);
    httpRequest.send('');

}
function AjaxEnd(httpRequest, ElementEndUpdate) {

    if (httpRequest.readyState == 4) {
        if (httpRequest.status == 200) {

        	try { AjaxEndFunction(httpRequest.responseText); } catch (e) {}
        	try { change_value(ElementEndUpdate, httpRequest.responseText); } catch (e) {}
        	try { element_html(ElementEndUpdate, httpRequest.responseText); }  catch (e) {}

        	loaded();

        } else {
            calert('There Was An Error Processing Your Request. Please Try again.');
        }
    }

}

function loading() {
	show('loading');
}
function loaded() {
	hide('loading');
}


var ActualWidth = new Array;
function ScaleImage(Id, MaxWidth){
	var IMG = document.getElementById(Id);
	ActualWidth[Id] = IMG.width;
	if(IMG.width>MaxWidth){
		IMG.style.width = MaxWidth+'px';
	}
}
function show_message(Id, Message){
	window.clearTimeout(window.timeoutid);
	element_html(Id, Message);
	Effect.SlideDown(Id, { duration: 0.3 });
}
function close_message(Id){
	window.timeoutid = setTimeout(function(){  Effect.SlideUp(Id, { duration: 0.3 }); }, 2500);
	/*window.setTimeout(function(){ element_html(Id, ''); Effect.show(Id); }, 3000);*/

}
function ToggleImage(Id, Max){

	Element = document.getElementById(Id);

	var actualWidth = ActualWidth[Id];

	if(!actualWidth){
		return false;
	}

	if(actualWidth > Element.width){

		Element.style.width = actualWidth+'px';
		ContainerResize(actualWidth);
		return true;
	}
	if(actualWidth <= Max){

		Element.style.width = actualWidth+'px';
		ContainerResize(Max);
		return true;
	}

	Element.style.width = Max+'px';
	ContainerResize(Max);

}
function ContainerResize(Width){
	document.getElementById('ImgContainter').style.width = (parseInt(Width)+20)+'px';

}
function s_h(Show, Hide){
	show(Show);
	hide(Hide);
}
function getSelectionId(text, li) {
	change_value('q', addslashes(li.id));
	document.q_form.submit();
}
function addslashes(str) {
	return str.replace('"','\"');
}
function menu_swap(Element){

	/* GET ID */
		var temp = new Array();
		temp = Element.id.split('-');
		var TheId = temp[1];

	/* CHANGE STYLES & HIDE/SHOW */
		for (x = 1; x < 6; x++){
			force_style('subnav hide', 'subnav-'+x);
			force_style('a', 'nav-'+x);
		}
		force_style('a on', 'nav-'+TheId);
		force_style('subnav', 'subnav-'+TheId);

	/* HIDE SUB-MENUS */

}
function resetform(Element){
	if(Element.value==''){
		Element.value='type here to search';
	}
	else if(Element.value=='type here to search'){
		Element.value='';
	}
}
function s_q(Str){
	Str.replace("'","");
	Str.replace('"',"");
	return Str;
}
function addvalue(Name, Value){
	change_value(Name, element_value(Name) + "." + Value);
}
function deletevalue(Name, Value){
	change_value(Name,  element_value(Name).replace("."+Value, ""));
}
function change_image(name, NewImage){
	document.getElementById(name).src = NewImage;
}
function preload_images(Array){
	for (var i = 0; i < Array.length; i++) {
		  pic1= new Image(100,25);
		  pic1.src=Array[i];
	}
}
function preload_image(Image_Path){
	pic= new Image(5,5);
	pic.src=Image_Path;
}
function selectText(Element){
	Element.select();
}
function change_value(name, value){
	document.getElementById(name).value = value;
}
function change_title(name, value){
	document.getElementById(name).title = value;
}
function element_html(name, html){
	document.getElementById(name).innerHTML = html;
}
function inner_html(name){
	return document.getElementById(name).innerHTML;
}
function hide(Element){
	document.getElementById(Element).style.display = 'none';
}
function show(Element){
	document.getElementById(Element).style.display = 'block';
}
function element_display(name, display){
	 document.getElementById(name).style.display = display;
}
function element_value(name){
	return document.getElementById(name).value;
}
function element_width(name, new_width){
	document.getElementById(name).style.width = new_width;
}
function element_ok(name, message){
	document.getElementById(name).innerHTML = '<font class="orange">'+message+'</font>';
}
function element_bad(name, message){
	document.getElementById(name).innerHTML = '<font class="red">'+message+'</font>';
}
function throbber_on(name){
	show(name);
	element_html(name, '<img src="http://www.teenparent.tv/layout/images/throbber.gif">');
}
function throbber_message(name, message){
	show(name);
	element_html(name, '<img src="http://www.teenparent.tv/layout/images/throbber.gif" align="left">&nbsp;&nbsp;&nbsp;'+message);
}
function setfocus(name){
	document.getElementById(name).focus();
}
function togglestyle(name, Style1, Style2){
	Element = document.getElementById(name);
	if(Element.className == Style1){
		Element.className = Style2;
	} else {
		Element.className = Style1;
	}
}
function throbber_off(name){
	var innerhtml = document.getElementById(name).innerHTML;
	innerhtml = innerhtml.replace('<img src="http://www.teenparent.tv/layout/images/throbber.gif">', "");
	element_html(name, innerhtml);
}
function loop_force_showhide(s_prefix,show,h_prefix,hide){	for (x = 0; x < show.length; x++)	{		forceshow(s_prefix+show[x]);	}	for (x = 0; x < hide.length; x++)	{		forcehide(h_prefix+hide[x]);	}}

function loop_showhide(prefix,array){	for (x = 0; x < array.length; x++)	{		showhide(prefix+array[x]);	}}
function loop_show(prefix,array){	for (x = 0; x < array.length; x++)	{		forceshow(prefix+array[x]);	}}
function loop_hide(prefix,array){	for (x = 0; x < array.length; x++)	{		forcehide(prefix+array[x]);	}}
function showhide(ElementName){	ElementId = document.getElementById(ElementName);     if (ElementId.style.display == 'none')     {          ElementId.style.display = 'block';     }     else     {          ElementId.style.display = 'none';     }}
function forceshow(ElementName){	ElementId = document.getElementById(ElementName);	ElementId.style.display = 'block';}
function forcehide(ElementName){	ElementId = document.getElementById(ElementName);	ElementId.style.display = 'none';}

function loop_setstyle(style, s_prefix, array){	for (x = 0; x < array.length; x++)	{		force_style(style, s_prefix+array[x]);	}}
function force_style(style, ElementName){	ElementId = document.getElementById(ElementName);	ElementId.className=style;}
function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit){
		field.value = field.value.substring(0, maxlimit);
	} else {
		countfield.value = maxlimit - field.value.length;
	}
}
function ValidateMediaType(Element){
	var name = Element.value;
	var name = name.toLowerCase();

	var temp = new Array();
	temp = name.split('.');
	var type = temp[temp.length-1];
	if(	(type != "wmv") && (type != "mpeg") && (type != "mpg") && (type != "avi") && (type != "divx") && (type != "mp4") && (type != "flv") && (type != "asf")  && (type != "mov")  && (type != "rm")){
		alert('"' +type + '" Is an incorrect File Type');
		Element.value = "";
	}
}
function CleanComment(comment) {
	var reg = new RegExp("<([^<>\s]*)(\s[^<>]*)?>", "g");
    return comment.replace(reg,"");
}
function donothing(){}
function ResizeIt(offset){
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			winH = window.innerHeight;
	}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winH = document.body.offsetHeight;
		}
	}
	document.getElementById('iframe').style.height = (winH - offset)+'px';
}
function ValidateUrl(Url) {
    var v = new RegExp();
    v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
    if (!v.test(Url)) {
        return true;
    } else {
    	return false;
    }
}

function popconfirm(message)
{
	var agree=confirm(message);
	if (agree){
		return true ;
	} else {
		return false ;
	}
}
function gotourl(url) {
	window.location = url;
}
function confirmmove(url){
	var agree=confirm("Are you sure you to Leave this page?");
	if (agree){
		window.location = url;
		return true ;
	} else {
		return false ;
	}
}
function confirmSubmit(message){
	var agree=confirm("Are you sure you to " + message);
	if (agree) {
		return true ;
	} else {
		return false ;
	}
}
function ShareThis(social_site, url, title, content){

	if (url != ''){

		if(social_site == 'delicious'){
			var url = 'http://del.icio.us/post?v=4&noui&jump=close&url=' + url + '&title=' + title;

		} else if (social_site == 'digg'){
			var url = 'http://digg.com/submit?phase=2&url=' + url + '&title=' + title + '&bodytext=' + content;

		} else if (social_site == 'dropjack'){
			var url = 'http://www.dropjack.com/submit.php?url=http://redirect.alexa.com/redirect?' + url + '&title=' + title;

		} else if (social_site == 'sphinn'){
			var url = 'http://sphinn.com/login.php?return=/submit.php?url=http://redirect.alexa.com/redirect?' + url + '&title=' + title;

		} else if (social_site == 'furl'){
			var url = 'http://furl.net/storeIt.jsp?u=http://redirect.alexa.com/redirect?' + url + '&t=' + title;

		} else if (social_site == 'netscape'){
			var url = 'http://www.netscape.com/submit/?U=http://redirect.alexa.com/redirect?' + url + '&T=' + title;

		} else if (social_site == 'yahoo'){
			var url = 'http://myweb2.search.yahoo.com/myresults/bookmarklet?u=' + url + '&t=' + title + '&ei=UTF-8';

		} else if (social_site == 'stumbleupon'){
			var url = 'http://www.stumbleupon.com/submit?url=' + url + '&title=' + title;

		} else if (social_site == 'google_bmarks'){
			var url = 'http://www.google.com/bookmarks/mark?op=edit&bkmk=http://redirect.alexa.com/redirect?' + url + '&title=' + title;

		} else if (social_site == 'technorati'){
			var url = 'http://www.technorati.com/faves?add=http://redirect.alexa.com/redirect??' + url;

		} else if (social_site == 'blinklist'){
			var url = 'http://blinklist.com/index.php?Action=Blink/addblink.php&Url=http://redirect.alexa.com/redirect?' + url + '&Title=' + title;

		} else if (social_site == 'newsvine'){
			var url = 'http://www.newsvine.com/_wine/save?u=http://redirect.alexa.com/redirect?' + url + '&h=' + title;

		} else if (social_site == 'magnolia'){
			var url = 'http://ma.gnolia.com/bookmarklet/add?url=http://redirect.alexa.com/redirect?' + url + '&title=' + title;

		} else if (social_site == 'reddit'){
			var url = 'http://reddit.com/submit?url=' + url + '&title=' + title;

		} else if (social_site == 'windows_live'){
			var url = 'https://favorites.live.com/quickadd.aspx?marklet=1&mkt=en-us&url=http://redirect.alexa.com/redirect?' + url + '&title=' + title + '&top=1';

		} else if (social_site == 'tailrank'){
			var url = 'http://tailrank.com/share/?link_href=http://redirect.alexa.com/redirect?' + url + '&title=' + title;

		} else if (social_site == 'facebook'){
			var url = 'http://www.facebook.com/sharer.php?u=' + url + '&t=' + title;

		}

		window.open(url, 'ShareThis');

	}
}
function animate(Element, NumImgs){
	icnt=0;
	AniEle = Element;
	orig_url = Element.src;
	num_imgs = NumImgs;
	ImgPrts = ImageParts(orig_url);
	Timeout = '';

	if(NumImgs>0){
		Timeout=setTimeout("DoSwap()", 100);
	}
}
function DoSwap(){

	icnt++;
	AniEle.src = ImgPrts[0]+ImgPrts[1]+'-ani-'+icnt+'.jpg';

	if(icnt>num_imgs) icnt = 0;

	clearInterval(Timeout);
	Timeout=setTimeout("DoSwap()", 600);

}
function Reset(Element){
	Element.src = orig_url;
	icnt=0;
	clearInterval(Timeout);
}
function ImageParts(orig_img_url){

	imgpath = 	orig_img_url.substring(0, orig_img_url.lastIndexOf("/"))+"/";
	imgsrc = 	orig_img_url.substring((orig_img_url.lastIndexOf("/")+1));

	var temp =	new Array();
	var output =new Array();

	temp = 		imgsrc.split('.');
	temp = 		temp[0].split('-');
	imgnam = 	temp[0];
	for_ext = 	temp[1];

	output[0] = imgpath;
	output[1] = imgnam;

	return output;

}

function RateUp(Module, BreakDown){
	$.get('http://www.teenparent.tv/modules/rates/process.php?RateUp='+Module+'&Breakdown='+BreakDown, function(Data){

		$('#Rating').html('Feedback Submitted. Thanks');

	});
}
function RateDown(Module, BreakDown){
	$.get('http://www.teenparent.tv/modules/rates/process.php?RateDown='+Module+'&Breakdown='+BreakDown, function(){

		$('#Rating').html('Feedback Submitted. Thanks');

	});
}

