function thumbnailOption(opt) {
	if (opt.checked) {
		$("thumbnailScale").disabled = false;
		$("numbersOnThumb").disabled = false;
		$("thumbnailScaleLabel").style.color = "#000";
		$("numbersOnThumbLabel").style.color = "#000";
	}
	else {
		$("thumbnailScale").disabled = true;
		$("numbersOnThumb").disabled = true;
		$("thumbnailScaleLabel").style.color = "gray";
		$("numbersOnThumbLabel").style.color = "gray";
	}
}

function VVCIsNumeric(text) {
	return /^[-+]?\d+(\.\d+)?$/.test(text);
}

function updateWidget() {
    
    var widget_width=new Array("", 468, 728, 120, 160, 120, 125, 250);
    var widget_height=new Array("", 60, 90, 600, 600, 240, 125, 250);
    
    var baseurl="http://www.myvideo.co.za";
    //var baseurl="http://myvideo";
    
    var wchannel=document.widgetoptions.widgetChannel.value;

    var wtitle=document.widgetoptions.widgetTitle.value;
    var wnumb=document.widgetoptions.widgetNumber.value;
    var wtype=document.widgetoptions.widgetType.value;
    var wsize=document.widgetoptions.widgetSize.value;
    
    if (wsize==0){
        document.widgetoptions.widgetWidth.disabled=false;
        document.widgetoptions.widgetHeight.disabled=false;
        var wwidth=document.widgetoptions.widgetWidth.value;
        var wheight=document.widgetoptions.widgetHeight.value;
    }else{
        document.widgetoptions.widgetWidth.disabled=true;
        document.widgetoptions.widgetHeight.disabled=true;
        var wwidth=widget_width[wsize];
        var wheight=widget_height[wsize];
    }
    
    var wscroll=document.widgetoptions.widgetScroll.checked;
    
    var wbgcolor=document.widgetoptions.widgetBackground.value;
    var whbgcolor=document.widgetoptions.widgetHoverBackground.value;
    var wfcolor=document.widgetoptions.widgetFontColor.value;
    
    var wborder=document.widgetoptions.widgetBorder.checked;
    if (wborder==true){
        document.widgetoptions.widgetBorderStyle.disabled=false;
        document.widgetoptions.widgetBorderWidth.disabled=false;
        document.widgetoptions.widgetBorderColor.disabled=false;
        var wbstyle=document.widgetoptions.widgetBorderStyle.value;
        var wbwidth=document.widgetoptions.widgetBorderWidth.value;
        var wbcolor=document.widgetoptions.widgetBorderColor.value;
    }else{
        document.widgetoptions.widgetBorderStyle.disabled=true;
        document.widgetoptions.widgetBorderWidth.disabled=true;
        document.widgetoptions.widgetBorderColor.disabled=true;
        var wbstyle='none';
        var wbwidth='0';
        var wbcolor='#000000';
    }
    
    var wtfsize=document.widgetoptions.widgetTitleFontSize.value;
    var wfsize=document.widgetoptions.widgetFontSize.value;
    
    var wlpos=document.widgetoptions.widgetLinkPosition.value;
    
    var wshowt=document.widgetoptions.widgetShowThumbnails.checked;
    
    var wtscale=document.widgetoptions.widgetThumbnailScale.value;
    var wtnumb=document.widgetoptions.widgetNumbersOnThumb.checked;
    
    var wlnumb=document.widgetoptions.widgetShowChartPos.checked;
    
    var wspace=document.widgetoptions.widgetEntrySpacing.value;
    
    var wrows=document.widgetoptions.widgetRows.value;
    var wcols=document.widgetoptions.widgetCols.value;
    if (wrows==0){
        document.widgetoptions.widgetCols.value=1;
        document.widgetoptions.widgetCols.disabled=true;
        var wcols=1;
    }else if(wcols==0){
        document.widgetoptions.widgetRows.value=1
        document.widgetoptions.widgetRows.disabled=true;
        wrows=1;
    }else{
        document.widgetoptions.widgetCols.disabled=false;
        document.widgetoptions.widgetRows.disabled=false;
    }
    
    var wtpos=document.widgetoptions.widgetTitlePosition.value;
    
    var widget_type=document.widgetoptions.widgetClass.value;
    if (widget_type==2){
        document.widgetoptions.widgetScroll.disabled=true;
        document.widgetoptions.widgetBorderStyle.disabled=true;
        document.widgetoptions.widgetLinkPosition.disabled=true;
    }else{
        document.widgetoptions.widgetScroll.disabled=false;
        document.widgetoptions.widgetBorderStyle.disabled=false;
        document.widgetoptions.widgetLinkPosition.disabled=false;
    }
    
    if (widget_type==1){
    
        var embed = '<div id="myvideoWidget"></div><script type="text/javascript" src="'+baseurl+'/widget.php';
        if (wchannel!=""){
            embed+="?channelid="+wchannel;
        }

        embed+='"></script>\n<script type="text/javascript" src="'+baseurl+'/js/widget.js"></script>\n<script type="text/javascript">\nnew MyvideoVideoChart("'+wtitle+'", '+wnumb+', '+wtype+', '+wwidth+', '+wheight+', '+wscroll+', "'+wbgcolor+'", "'+whbgcolor+'", "'+wfcolor+'", '+wborder+', "'+wbstyle+'", '+wbwidth+', "'+wbcolor+'", "'+wtfsize+'", "'+wfsize+'", '+wlpos+', '+wshowt+', '+wtscale+', '+wtnumb+', '+wlnumb+', '+wspace+', '+wrows+', '+wcols+', '+wtpos+');\n</script>\n<div style="padding: 0 2px 2px 2px; color: #999; font-size: 10px; font-family: Verdana, serif">\nSource: <a href="'+baseurl+'/" style="color: #999; font-size: 10px; font-family: Verdana, serif">Top 10 South African Videos</a>\n</div>\n';
    
    	new MyvideoVideoChart(wtitle, wnumb, wtype, wwidth, wheight, wscroll, wbgcolor, whbgcolor, wfcolor, wborder, wbstyle, wbwidth, wbcolor, wtfsize, wfsize, wlpos, wshowt, wtscale, wtnumb, wlnumb, wspace, wrows, wcols, wtpos, wchannel);
    	
    }else if (widget_type==2){
        
        var fvars="wwidth="+wwidth+"&wheight="+wheight+"&wbgcolor="+wbgcolor+"&wborder="+wborder+"&wbwidth="+wbwidth+"&wbcolor="+wbcolor+"&wtype="+wtype+"&wfsize="+wfsize+"&wfcolor="+wfcolor+"&wcols="+wcols+"&wrows="+wrows+"&wspace="+wspace+"&wnumb="+wnumb+"&wtitle="+wtitle+"&wtpos="+wtpos+"&wtfsize="+wtfsize+"&wtscale="+wtscale+"&wlnumb="+wlnumb+"&wshowt="+wshowt+"&whbgcolor="+whbgcolor;
        
        if (wchannel!=""){
            fvars+="&channelid="+wchannel;
        }
        
        var embed = '<embed src="'+baseurl+'/widget.swf" quality="high" bgcolor="#ffffff" width="'+wwidth+'" height="'+wheight+'" name="'+baseurl+'/widget" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'+fvars+'"/>';
        
        new MyvideoFlashChart(wtitle, wnumb, wtype, wwidth, wheight, wscroll, wbgcolor, whbgcolor, wfcolor, wborder, wbstyle, wbwidth, wbcolor, wtfsize, wfsize, wlpos, wshowt, wtscale, wtnumb, wlnumb, wspace, wrows, wcols, wtpos, wchannel);
    }
	document.tagForm.tag.value = embed;
}

function MyvideoFlashChart(wtitle, wnumb, wtype, wwidth, wheight, wscroll, wbgcolor, whbgcolor, wfcolor, wborder, wbstyle, wbwidth, wbcolor, wtfsize, wfsize, wlpos, wshowt, wtscale, wtnumb, wlnumb, wspace, wrows, wcols, wtpos, wchannel){
    var baseurl="http://www.myvideo.co.za";
    //var baseurl="http://myvideo";
    
    var fvars="wwidth="+wwidth+"&wheight="+wheight+"&wbgcolor="+wbgcolor+"&wborder="+wborder+"&wbwidth="+wbwidth+"&wbcolor="+wbcolor+"&wtype="+wtype+"&wfsize="+wfsize+"&wfcolor="+wfcolor+"&wcols="+wcols+"&wrows="+wrows+"&wspace="+wspace+"&wnumb="+wnumb+"&wtitle="+wtitle+"&wtpos="+wtpos+"&wtfsize="+wtfsize+"&wtscale="+wtscale+"&wlnumb="+wlnumb+"&wshowt="+wshowt+"&whbgcolor="+whbgcolor;
    
        if (wchannel!=""){
            fvars+="&channelid="+wchannel;
        }
    
    var embed = document.createElement("embed");
    embed.setAttribute("src", baseurl+"/widget.swf");
    embed.setAttribute("quality", "high");
	embed.setAttribute("width", wwidth);
	embed.setAttribute("height", wheight);
	embed.setAttribute("name", baseurl+"/widget.swf");
	embed.setAttribute("align", "middle");
	embed.setAttribute("allowScriptAccess", "always");
	embed.setAttribute("type", "application/x-shockwave-flash");
	embed.setAttribute("pluginspage", "http://www.macromedia.com/go/getflashplayer");
	embed.setAttribute("flashvars", fvars);
	document.getElementById("myvideoWidget").innerHTML='';
	document.getElementById("myvideoWidget").appendChild(embed);
    
}

function MyvideoVideoChart(wtitle, wnumb, wtype, wwidth, wheight, wscroll, wbgcolor, whbgcolor, wfcolor, wborder, wbstyle, wbwidth, wbcolor, wtfsize, wfsize, wlpos, wshowt, wtscale, wtnumb, wlnumb, wspace, wrows, wcols, wtpos, wchannel){

    var w = 100 * wtscale;
    var tpos=0;
    var ccol=0;
    var crow=0;
    
    style_div0="width: "+wwidth+"px; height: "+wheight+"px;overflow:";
    if(wscroll==true){
        style_div0+="auto;";
    }else{
        style_div0+="hidden;";
    }
    style_div0+="border-style:"+wbstyle+";border-width:"+wbwidth+";border-color:"+wbcolor+";";
    
    style_div0+="background-color:"+wbgcolor+";color:"+wfcolor+";";
    
    var div0 = document.createElement("div");
    
        div0.style.cssText = style_div0;

    var table = document.createElement("table");
    table.setAttribute("width", "100%");
    table.setAttribute("cellspacing", "0");
	table.setAttribute("cellpadding", "1");
	table.style.color=wfcolor;
	
	//table.setAttribute("style", 'color:'+wfcolor+';');
	//table.style.color = wfcolor;
	//table.style.fontSize = this.fontSize;
	//table.style.fontFamily = this.fontFamily;
	
	var tbody = document.createElement("tbody");
	table.appendChild(tbody);	
	
	if (wtpos==1){
    	var tr = document.createElement("tr");
    	tbody.appendChild(tr);
        var td1 = document.createElement("td");
        td1.setAttribute("colSpan", 20);
    	tr.appendChild(td1);
    	var divTitle = document.createElement("div");
    	divTitle.innerHTML=wtitle;
    	divTitle.style.fontSize=wtfsize;
    	divTitle.style.fontWeight=800;
    	divTitle.style.color=wfcolor;
    	divTitle.style.textAlign="center";
    	divTitle.style.width="100%";
    	td1.appendChild(divTitle);
    }
	
	document.getElementById("myvideoWidget").innerHTML='';
	
	for (var i = 0; i < wnumb; i++) {
	    if(data_title[wtype][i]==undefined){
	        break;
	    }
	    if (crow==1 && (ccol==wcols && wtpos==4)){
                var td1 = document.createElement("td");
                td1.setAttribute("rowSpan", 20);
            	tr.appendChild(td1);
            	var divTitle = document.createElement("div");
            	divTitle.innerHTML=wtitle;
            	divTitle.style.fontSize=wtfsize;
            	divTitle.style.fontWeight=800;
            	divTitle.style.color=wfcolor;
            	divTitle.style.textAlign="center";
            	divTitle.style.width="100%";
            	td1.appendChild(divTitle);
	    }
	    
	    if (crow==0 || (ccol>=wcols && wcols!=0)){
	        ccol=0;
	        crow++;
    		var tr = document.createElement("tr");
    		tbody.appendChild(tr);
	    }
	    
	    if (crow==1 && (ccol==0 && wtpos==2)){
                var td1 = document.createElement("td");
                td1.setAttribute("rowSpan", 20);
            	tr.appendChild(td1);
            	var divTitle = document.createElement("div");
            	divTitle.innerHTML=wtitle;
            	divTitle.style.fontSize=wtfsize;
            	divTitle.style.fontWeight=800;
            	divTitle.style.color=wfcolor;
            	divTitle.style.textAlign="center";
            	divTitle.style.width="100%";
            	td1.appendChild(divTitle);
	    }
if (wrows==0 || wcols==0 || (wrows>0 && crow<=wrows)){		
		
		var td1 = document.createElement("td");
		tr.appendChild(td1)
		td1.setAttribute("style", "padding: " + wspace + "px 0 " + wspace + "px 0");
		td1.style.paddingTop = wspace + "px";
		td1.style.paddingBottom = wspace + "px";
        td1.setAttribute("valign", "middle");
		td1.align = "center";
		td1.height = "100%";
		td1.style.margin = 0;
		ccol++;
		
		

		    var table4 = document.createElement("table");
            table4.setAttribute("width", "100%");
            table4.setAttribute("height", "100%");
            table4.setAttribute("cellspacing", "0");
        	table4.setAttribute("cellpadding", "0");
        	table4.setAttribute("style", "padding: " + wspace + "px 0 " + wspace + "px 0");
        	table4.onmouseover = function() {this.style.background = whbgcolor};
    		table4.onmouseout = function() {this.style.background = wbgcolor};
        	var tbody4 = document.createElement("tbody");
        	table4.appendChild(tbody4);	
        	var tr4 = document.createElement("tr");
        	tr4.align = "center";
        	tbody4.appendChild(tr4);
        	
        	var td5 = document.createElement("td");
			td5.setAttribute("valign", "middle");
			td5.style.margin = 0;
			
    		var divRel = document.createElement("div");
    		divRel.setAttribute("style", "position: relative");
    		divRel.style.position = "relative";
        	
        	var a5 = document.createElement("a");
        	td5.appendChild(divRel);
        	divRel.appendChild(a5);
				a5.setAttribute("href", data_link[wtype][i]);
				a5.style.color=wfcolor;
				a5.style.fontSize=wfsize;
			if (data_thumb[wtype][i] != null) {
				var thumb = document.createElement("img");
				thumb.setAttribute("src", data_thumb[wtype][i]);
				thumb.setAttribute("width", w);
				thumb.setAttribute("height", w*0.82);
				thumb.setAttribute("border", "1");
				thumb.setAttribute("align", "center");
				thumb.style.borderStyle="solid";
				thumb.style.borderWidth="1";
				thumb.style.borderColor="#000000";
				a5.appendChild(thumb);
			}
			else{
				a5.appendChild(document.createTextNode("No Thumb"));
			}
        	
			var td6 = document.createElement("td");
			td6.setAttribute("valign", "middle");
			
        	var a6 = document.createElement("a");
        	td6.appendChild(a6);
			a6.style.color=wfcolor;
			a6.style.fontSize=wfsize;
			var text = "";
			if (wlnumb) text += '<strong>'+ (i+1) + '.</strong> ';
			text += data_title[wtype][i];
			a6.innerHTML = text;
			a6.setAttribute("href", data_link[wtype][i]);
        	
		

				if (wtnumb==true && wshowt==true) {
					var divNum = document.createElement("div");
					divNum.setAttribute("style", "position: absolute; top: 0; left: 0; background: black; color: white; text-align: center; width: 1.3em; font-size: " + wfsize + "; font-family:" + "verdana");
					divNum.style.position = "absolute";
					divNum.style.top = 0;
					divNum.style.left = 0;
					divNum.style.background = "black";
					divNum.style.color = "white";
					divNum.style.textAlign = "center";
					divNum.style.width = "1.3em";
					divNum.style.fontSize = wfsize;
					divNum.style.fontFamily = "verdana";
					tpos=i+1;
					divNum.appendChild(document.createTextNode(""+tpos));

					divRel.appendChild(divNum);
				}
        	
        	    if (wlpos==1){
            	    tr4.appendChild(td6);
            	    td6.style.textAlign="center";
            	    td6.setAttribute("width", "100%");
            	    td6.setAttribute("height", "100%");
            	    if (wshowt){
                	    var tr5 = document.createElement("tr");
                	    tr5.align = "center";
                	    tbody4.appendChild(tr5);
                	    tr5.appendChild(td5);
                	    
                	    td5.style.textAlign="center";
                	    td5.setAttribute("width", "100%");
            	    }
            	    td1.setAttribute("valign", "bottom");
        	   }else if (wlpos==2){
        	       if (wshowt){
        	           tr4.appendChild(td5);
        	           td5.style.textAlign="center";
        	           td5.setAttribute("width", w+5);
        	       }
        	       tr4.appendChild(td6);
            	   td6.style.textAlign="left";
            	   td6.setAttribute("width", "100%");
            	   td6.setAttribute("height", "100%");
        	   }else if (wlpos==3){
        	       if (wshowt){
            	       tr4.appendChild(td5);
                	   var tr5 = document.createElement("tr");
                	   tr5.align = "center";
                	   tbody4.appendChild(tr5);
                	   tr5.appendChild(td6);
                	   
                	   td5.style.textAlign="center";
                	   td5.setAttribute("width", "100%");
                	   td6.setAttribute("height", "100%");
            	    }else{
            	       tr4.appendChild(td6); 
            	    }
            	    
            	    td6.style.textAlign="center";
            	    td6.setAttribute("width", "100%");
            	    td1.setAttribute("valign", "top");
        	   }else if (wlpos==4){
        	       tr4.appendChild(td6);
        	       td6.style.textAlign="right";
        	       td6.setAttribute("width", "100%");
        	       td6.setAttribute("height", "100%");
        	       if (wshowt){
        	           tr4.appendChild(td5);
        	           td5.style.textAlign="center";
        	           td5.setAttribute("width", w+5);
        	       }
        	   }
			/*
                    td5.style.paddingTop = spacing + "px";
            		td5.style.paddingBottom = spacing + "px";
            		td5.style.paddingLeft = "4px";
            		td6.style.margin = 0;*/
        	
		  td1.appendChild(table4);
}   
    }

    if (wtpos==3){
    	var tr = document.createElement("tr");
    	tbody.appendChild(tr);
        var td1 = document.createElement("td");
        td1.setAttribute("colSpan", 20);
    	tr.appendChild(td1);
    	var divTitle = document.createElement("div");
    	divTitle.innerHTML=wtitle;
    	divTitle.style.fontSize=wtfsize;
    	divTitle.style.fontWeight=800;
    	divTitle.style.color=wfcolor;
    	divTitle.style.textAlign="center";
    	divTitle.style.width="100%";
    	td1.appendChild(divTitle);
    }
    
    if (wtpos==4 && wcols==0){
                var td1 = document.createElement("td");
                td1.setAttribute("rowSpan", 20);
            	tr4.appendChild(td1);
            	var divTitle = document.createElement("div");
            	divTitle.innerHTML=wtitle;
            	divTitle.style.fontSize=wtfsize;
            	divTitle.style.fontWeight=800;
            	divTitle.style.color=wfcolor;
            	divTitle.style.textAlign="center";
            	divTitle.style.width="100%";
            	td1.appendChild(divTitle);
	    }
    
    div0.appendChild(table);
    document.getElementById("myvideoWidget").appendChild(div0);
    
}




var wcp = new wColorPicker();

function wcpPopup(inpField) 
{
	this.inpField = inpField;
	this.cpWin = window.open('', null, "dependent=yes,diretories=no,height=300,help=no,width=274,location=no,menubar=no,resizable=no,scrollbars=no,status=yes");
	this.cpWin.document.writeln(this.draw());
	this.p=opener
	this.cpWin.focus();	
}

function wcpHoverCell(new_color)
{
    var nc=""+new_color;
    this.cpWin.document.getElementById("cptext").innerHTML="#"+new_color;
    this.cpWin.document.getElementById("cpcolor").style.background=new_color;
    if(this.cpWin.document.getElementById("vpreview").checked){
        this.inpField.value = '#' + nc.toUpperCase();
        this.update();
    }
}

function wcpClickCell(new_color)
{
    var nc=""+new_color;
    this.inpField.value = '#' + nc.toUpperCase();
    this.update();
	this.cpWin.close();
}

function wcpCreateCell (R, G, B, w, h) 
{
    var ncolor=""+Dec2Hex((R << 16) + (G << 8) + B);
	return '<td bgcolor="#' + ncolor + '"><img src="'+this.spacer+'" width="10" height="10" style="cursor:hand;" onmouseover="javascript:wcpo.hover('+"'"+ncolor+"'"+');" onclick="javascript:wcpo.click('+"'"+ncolor+"'"+');"></td>';
}


function Dec2Hex(v) 
{
	v = v.toString(16);
	for(; v.length < 6; v = '0' + v);
	return v;
}

function wcpDrawCP() 
{
	var outStr = '<script language="JavaScript">var wcpo = opener.wcp;</script><table>';
	for (i = 0; i < 12; i ++) {
		outStr+="<tr>";
		for (j = 0; j < 3; j ++)
			for (k = 0; k <= 5; k ++)
				outStr += this.createCell(j * 51 + (i % 2) * 51 * 3, Math.floor(i / 2) * 51, k * 51, 8, 10);
		outStr+="</tr>";
	}
	return outStr+='</table><br><br><table cellspacing="0" cllpadding="10"><tr><td align="center" style="text-align:center;">Color Code:</td><td>&nbsp</td></tr><tr height="20"><td width="137"><div id="cptext" align="center" style="text-align:center;">&nbsp;</div></td><td width="137"><div id="cpcolor" align="center" style="text-align:center;">&nbsp;</div></td></tr></table><br/><center><form id="tform" name="tform"><input type="checkbox" name="vpreview">Design Preview</form></center>';
}

function wColorPicker() 
{
    this.spacer="http://myvideo/images/cp_spacer.gif";
	this.draw = wcpDrawCP;
	this.popup   = wcpPopup;
	this.createCell = wcpCreateCell;
	this.hover = wcpHoverCell;
	this.click = wcpClickCell;
	this.update=updateWidget;
}