var selectedimg=1;
var ug_id="";
var color_seleted='BG';
var theme=1;
var sound='off';
var width='280';
var height='390';
var bkground='GR';

var errorpageurl= ""; 
function cameo(){
	var ok = document.getElementById("ok");
	if(ok!=null){
		ok.onclick = function() { Cameoformsubmit(); return false;}
	}
		
}

function whichBrowser() {
    var agt=navigator.userAgent.toLowerCase();
    if (agt.indexOf("opera") != -1) return 'Opera';
    if (agt.indexOf("staroffice") != -1) return 'Star Office';
    if (agt.indexOf("webtv") != -1) return 'WebTV';
    if (agt.indexOf("beonex") != -1) return 'Beonex';
    if (agt.indexOf("chimera") != -1) return 'Chimera';
    if (agt.indexOf("netpositive") != -1) return 'NetPositive';
    if (agt.indexOf("phoenix") != -1) return 'Phoenix';
    if (agt.indexOf("firefox") != -1) return 'Firefox';
    if (agt.indexOf("safari") != -1) return 'Safari';
    if (agt.indexOf("skipstone") != -1) return 'SkipStone';
    if (agt.indexOf("msie") != -1) return 'Internet Explorer';
    if (agt.indexOf("netscape") != -1) return 'Netscape';
    if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
    if (agt.indexOf('\/') != -1) {
        if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
            return navigator.userAgent.substr(0,agt.indexOf('\/'));
        } else {
            return 'Netscape';
        }
    } else if (agt.indexOf(' ') != -1) {
        return navigator.userAgent.substr(0,agt.indexOf(' '));
    } else {
        return navigator.userAgent;
    }
} 


function CameoNewView(){	
	 errorpageurl= getErrorUrl(); 

	if(jQuery("#new-680x480").hasClass("active")){
		ShowCameoEmbedCode(selectedimg,0,0,600,480,bkground);	
	}	

	jQuery("#new-680x480").click( function(){										   
		ShowCameoEmbedCode(selectedimg,0,0,600,480,bkground);
	});	
	
	jQuery("#other-sizes").click( function(){
		alert("other");

		if(document.frmwidgetSize){	
		ShowCameoEmbedCode(selectedimg,theme,sound,width,height,bkground);
		var radiolist =  document.frmwidgetSize.imgsa;
		if(radiolist!=null){
			for(i=0;i<radiolist.length;i++){
				//alert(radiolist[i].name+i);
				if(whichBrowser()=='Internet Explorer'){
					radiolist[i].onclick=function() { changeImgSize(); }
				}else{
					radiolist[i].onchange=function() { changeImgSize(); return false;}
				}
			}
		}
		var color_list = document.frmwidgetSize.colorList;
		//alert(color_list);

		if(color_list!=null){
			//alert(color_list);
			for(i=0;i<color_list.length;i++){
				if(whichBrowser()=='Internet Explorer'){
					color_list[i].onclick=function() { changeImgSize(); }
				}else{
					color_list[i].onchange=function() { changeImgSize(); return false;}
				}
			}
		}
		var cameoSound = document.frmwidgetSize.soundoption;
		if(cameoSound!=null){
			for(i=0;i<cameoSound.length;i++){
				if(whichBrowser()=='Internet Explorer'){
					cameoSound[i].onclick=function() { setSoundOption(); }
				}else{
					cameoSound[i].onchange=function() { setSoundOption(); return false;}
				}
			}
		}
		
	}
	});		
	
}

function CameoView(){	
errorpageurl= getErrorUrl(); 
	if(document.frmwidgetSize){
		ShowCameoEmbedCode(selectedimg,theme,sound,width,height,bkground);
		var radiolist =  document.frmwidgetSize.imgsa;
		if(radiolist!=null){
			for(i=0;i<radiolist.length;i++){
				//alert(radiolist[i].name+i);
				if(whichBrowser()=='Internet Explorer'){
					radiolist[i].onclick=function() { changeImgSize(); }
				}else{
					radiolist[i].onchange=function() { changeImgSize(); return false;}
				}
			}
		}
		var color_list = document.frmwidgetSize.colorList;		
		//alert(color_list);

		if(color_list!=null){
			//alert(color_list);
			for(i=0;i<color_list.length;i++){
				if(whichBrowser()=='Internet Explorer'){
					color_list[i].onclick=function() { changeImgSize(); }
				}else{
					color_list[i].onchange=function() { changeImgSize(); return false;}
				}
			}
		}
		var cameoSound = document.frmwidgetSize.soundoption;
		if(cameoSound!=null){
			for(i=0;i<cameoSound.length;i++){
				if(whichBrowser()=='Internet Explorer'){
					cameoSound[i].onclick=function() { setSoundOption(); }
				}else{
					cameoSound[i].onchange=function() { setSoundOption(); return false;}
				}
			}
		}
		
	}
}

function changeImgSize(jsclor){
	//alert("test color");
		if(jsclor==null){
			jsclor = color_seleted;
		}
		if(document.getElementById("280")!=null && document.getElementById("280").checked){
			selectedimg = document.getElementById("280").value;
			document.getElementById("see_how_long").className='hide';
			document.getElementById("see_how").className='show_text';
			width=280;
			height=390;
			
		}else if(document.getElementById("300")!=null && document.getElementById("300").checked){
			selectedimg = document.getElementById("300").value;
			//showhideImg(jsclor,'2');
			//document.getElementById("ban_img").height=250;
			//document.getElementById("ban_img").width=300;	
			document.getElementById("see_how_long").className='hide';
			document.getElementById("see_how").className='show_text';
			width=300;
			height=250;

	
		}else if(document.getElementById("728")!=null && document.getElementById("728").checked){		
			selectedimg = document.getElementById("728").value;
			document.getElementById("see_how_long").className='show_text';
			document.getElementById("see_how").className='hide';
			//showhideImg(jsclor,'3');
			//document.getElementById("ban_img").height=90;
			//document.getElementById("ban_img").width=728;
			width=728;
			height=90;

		}
		
		var color = getSelectedColorImg();
		
		showhideImg(color,selectedimg);
}

function getSelectedColorImg(){
	if(document.getElementById("BG")!=null && document.getElementById("BG").checked){
		color_seleted =  'BG';
		
	}else if(document.getElementById("G1")!=null && document.getElementById("G1").checked){
		color_seleted =  'G1';
		
	}else if(document.getElementById("WB")!=null && document.getElementById("WB").checked){
		color_seleted =  'WB';
		
	}
	//alert("doc"+document.getElementById("G1").checked);
//alert("doc"+document.getElementById("WB").checked);

	//alert("CS"+color_seleted);
	return color_seleted;
}

function changeColor(jsclor,jsht,jswidth){
	
	if(jsclor=='BG'){
		showhideImg(jsclor,'1');
	}else if(jsclor=='G1'){
		showhideImg(jsclor,'2');
				
	}else if(jsclor=='WB'){
		showhideImg(jsclor,'3'); 
				
	}
	
}

function Cameoformsubmit(){
	document.getElementById("frmcameo").submit();
}

function showhideImg(jscolor,type){
	
	color_seleted=jscolor;
	var jdId=jscolor+type;
	//alert("jdid"+jdId);
	var imglist=document.frmwidgetSize.cameo_img;
	
	var testimg = document.images;
	
	for(i=0;i<document.images.length;i++){
		
		if(document.images[i].name=="cameo_img"){
			//alert("cameo-img");
			if(document.images[i].id==jdId){
				//alert("cameo-img"+jdId);
				document.images[i].className='show';
			}else{
				//alert("2:"+document.images[i].name);
				document.images[i].className='hide';
			}
		}
	}
	//init();
	ShowCameoEmbedCode(type,getSelectedColor(),sound,width,height,bkground);
	
}

function Cameodisplay(){
	
	
			//alert("test cameo");
		//document.getElementById("imgs_view").className='show';
		//document.getElementById("widget_item").className='hide';
		//document.getElementById("swfDiv").className='photo hide';
		//document.getElementById("cameo_cd").className="textarea_widget show";
		//document.getElementById("holdtext").className="hide";
		ShowCameoEmbedCode(selectedimg,theme,sound,width,height,bkground);
	
	
}

function setNewSoundOption(){
	if(document.getElementById("on")!=null && document.getElementById("on").checked){
		sound ='on'
	}else{
		sound ='off'
	}		
	ShowCameoEmbedCode(selectedimg,0,sound,600,480,bkground);
}


function setSoundOption(){
	if(document.getElementById("on")!=null && document.getElementById("on").checked){
		sound ='on'
	}else{
		sound ='off'
	}
	ShowCameoEmbedCode(selectedimg,theme,sound,width,height,bkground);
}

function getSelectedImg(){
	return selectedimg;
}

function showWidget(){
	
	if(document.getElementById("wigdet_view").checked){
		
		document.getElementById("swfDiv").className='photo show';
		initWidget();
		showWidgetEmbedCode();
		//init();
		document.getElementById("widget_item").className='show';
		document.getElementById("holdtext").className="textarea_widget show";
		document.getElementById("cameo_cd").className="hide";
		if(document.getElementById("imgs_view")!=null){
			document.getElementById("imgs_view").className='hide';
		}
		
		
	}else{
		if(document.getElementById("widget_item")!=null){
			document.getElementById("widget_item").className='hide';
		}
		document.getElementById("cameo_cd").className="hide";
	}
	
}

function getSelectedColor(){
	
	if(color_seleted=="BG"){
		theme=1;
		bkground='GR';
	}
	else if(color_seleted=="G1"){
		theme=2;
		bkground='OR';
	}else if(color_seleted=="WB"){
		theme=3;
		bkground='BL';
	}
	return theme;
}

function getSoundOption(){
	return sound;
}

function widgetReset(){
	document.getElementById("width").value=150;
	document.getElementById("height").value=240;
	updateHeight();
}




function showMin_window() {
	errorpageurl=getErrorUrl();
	var browserType = whichBrowser();
	if(browserType!=null && browserType=='Internet Explorer'){
		
		if (typeof document.body.style.maxHeight != "undefined") {
  			// IE 7, mozilla, safari, opera 9
			
		} else {
			
  			$("body","html").css({height: "100%", width: "100%"});
			$("select","html").css({visibility: "hidden"});
			$("html").css("overflow","hidden");
		}

			
	}

	var errorbox = document.getElementById('errorbox');
	errorbox.innerHTML = "<iframe id='errorFrame' src='"+errorpageurl+"' frameborder='0' class='error-pg'></iframe>";
	document.getElementById('errorbox').className='show'; 
	document.getElementById('lightbox').className='lightbox show'; 
	document.getElementById('errorFrame').className='error-pg show';
	}
	
	function closeMin_window() {	
	var errorbox = document.getElementById('errorFrame');
	errorbox.parentNode.removeChild(errorbox);
	document.getElementById('lightbox').className='hide';
	document.getElementById('errorbox').className='hide';
	$("body","html").css({height: "auto", width: "auto"});
	$("select","html").css({visibility: "visible"});
	$("html").css("overflow","");
	}
	
	
	
	function addLoadEvent(func) { 

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

	} else { 
		window.onload = function() { 
			if (oldonload) { 
				oldonload(); 

			} 
			func();
		} 
		
	} 
}

if(document.getElementById && document.createTextNode) {
	addLoadEvent(CameoView);
	//addLoadEvent(CameoNewView);
	
	
}

function getErrorUrl(){
return '/g2/webapp/groups/GroupErrorDisplay.wmt';
}

	







	


