
function onlyNum(pn) {
	if (isNaN(pn.value)){
		alert('Please Input Numbers Only!');
		pn.value='';
		pn.focus();
		return false;
	}else{
		return true;	
	}
}
 function circleCharLimit(this_field,field1,field2,limit_field){   
	var top_field;
	var bottom_field;
	var limit_field;
	var circle_char_limit;
	field1='top1';
	field2='bot1';
	limit_field='circlelimit';
	if(document.getElementById(field1))
		top_field = document.getElementById(field1);
	if(document.getElementById(field2))
		bottom_field = document.getElementById(field2);
	if(document.getElementById(limit_field))
		limit_field = document.getElementById(limit_field);
	if(document.getElementById('clid'))
		circle_char_limit = document.getElementById('clid').value;
	var total_length = top_field.value.length + bottom_field.value.length;
	var available = circle_char_limit - total_length;
	if (available < 0){
		if (this_field != null){
			this_field.value = this_field.value.substring(0,this_field.value.length - Math.abs(available));
			available = 0;
		}else{
			var bigger_one;
			if (top_field.length > bottom_field.length)
				bigger_one = top_field;
			else
				bigger_one = bottom_field;
			bigger_one.value = bigger_one.value.substring(0,bigger_one.value.length - Math.abs(available));
			available = 0;
		}
	}
	limit_field.value = available;
	return true;
}
var pp;
function setWindowName(a,init){
	if(!window.name)
		window.name="parentwin"+a;
}

var str='';
var pin='';
function panelBlank(panel,strs,pin1){
	if(document.getElementById(panel)){
		if(document.getElementById(panel).value==""){
			if(pin1==1){
				pin=pin1;
			}
			if(strs!=''){
				str+=strs;
			}
			return false;
		}else if(document.getElementById(panel).value=="None Selected" && document.getElementById(panel).readOnly==true){
			if(pin1==1){
				pin=pin1;
			}
			if(strs!=''){
				str+=strs;
			}
			return false;
		}else{
			return true;
		}
	}
	return true;
}
function panelCheck(){
	var ret=true;
	var str1='';
	ret=panelBlank("pn1","",1);
	ret=panelBlank("top1","You have not completed the Top Panel\n",0);
	ret=panelBlank("bot1","You have not completed the Bottom Panel\n",0);
	ret=panelBlank("pn2","",1);
	ret=panelBlank("pn3","",1);
	ret=panelBlank("pn4","",1);
	ret=panelBlank("pn5","",1);
	ret=panelBlank("pn6","",1);
	ret=panelBlank("line1","You have not entered Line 1\n",0);
	ret=panelBlank("line2","You have not entetered Line 2\n",0);
	ret=panelBlank("attrib-"+seal_id,"You have not selected a Seal for your Badge\n",0);
	ret=panelBlank("badge_backing","You have not selected a Badge Backing for your Badge\n",0);
	if(ret)
		return true;
	else{
		if(pin==1)
			str1='You have not completed all panels\n';
		alert(str1+str);
		str="";
		pin="";
		str1="";
		ret="";
		return false;
	}
}

function popupWindowseal(pid){
	var pp1='',pp2='',pp3='',pp3='',pp4='',pp5='',pp6='',line1='',line2='',top11='',bot11='',bb='',sealprice='',tmp='',text_color_selected='',badge_color_ided='',text_separator_selected='',text_type_selected='',text_color_selected='',text_font_selected='',chksealprice='',zenid='',chksealprice='',zenid='',comments_selected='',comments='';
	seal_name='';
	if(document.getElementById('attrib-'+seal_id))
		popUpArgs = document.getElementById('attrib-'+seal_id);
	if(document.getElementById("attrib-"+badge_color_id)){
		tmp=document.getElementById("attrib-"+badge_color_id);
		badge_color_ided=tmp.options[tmp.selectedIndex].value;
	}
	if(document.getElementById("attrib-"+text_separator_id)){
		tmp=document.getElementById("attrib-"+text_separator_id);
		text_separator_selected=tmp.options[tmp.selectedIndex].value;
	}
	if(document.getElementById("attrib-"+text_type_id)){
		tmp=document.getElementById("attrib-"+text_type_id);
		text_type_selected=tmp.options[tmp.selectedIndex].value;
	}
	if(document.getElementById("attrib-"+text_color_option_id)){
		tmp=document.getElementById("attrib-"+text_color_option_id);
		text_color_selected=tmp.options[tmp.selectedIndex].value;
	}
	if(document.getElementById("attrib-"+text_font_option_id)){
		tmp=document.getElementById("attrib-"+text_font_option_id);
		text_font_selected=tmp.options[tmp.selectedIndex].value;
	}
	if(document.getElementById("sealpricechk"))
		chksealprice=document.getElementById("sealpricechk").value;
	if(document.getElementById("badge_backing"))
		bb=document.getElementById("badge_backing").value;
	if(document.getElementById("comments"))
		comments_selected=document.getElementById("comments").value;
	if(document.getElementById("czenid"))
		zenid=document.getElementById("czenid").value;
	if(document.getElementById("pn1"))
		pp1=document.getElementById("pn1").value;
	if(document.getElementById("top1"))
		top11=document.getElementById("top1").value;
	if(document.getElementById("bot1"))
		bot11=document.getElementById("bot1").value;
	if(document.getElementById("pn2"))
		pp2=document.getElementById("pn2").value;
	if(document.getElementById("pn3"))
		pp3=document.getElementById("pn3").value;
	if(document.getElementById("pn4"))
		pp4=document.getElementById("pn4").value;
	if(document.getElementById("pn5"))
		pp5=document.getElementById("pn5").value;
	if(document.getElementById("pn6"))
		pp6=document.getElementById("pn6").value;
	if(document.getElementById("line1"))
		line1=document.getElementById("line1").value;
	if(document.getElementById("line2"))
		line2=document.getElementById("line2").value;
	window.open('index.php?main_page=popup_seal&winid='+window.name+'&pid='+pid+'&zenid='+zenid+'&p1='+pp1+'&p2='+pp2+'&p3='+pp3+'&p4='+pp4+'&p5='+pp5+'&line1='+line1+'&line2='+line2+'&top1='+top11+'&bot1='+bot11+'&chksealprice='+chksealprice+'&text_type_selected='+text_type_selected+'&badge_color_ided='+badge_color_ided+'&text_color_selected='+text_color_selected+'&text_font_selected='+text_font_selected+'&badge_backing_selected='+bb+'&text_separator_selected='+text_separator_selected+'&comments_selected='+comments_selected+'&seal_id='+seal_id,'Select','width=570,height=450,toolbar=yes,status=yes,scrollbars=yes,resizable=no,menubar=no,location=no,direction=no');
}

function popupWindowbacking(pid){
	var pp1='',pp2='',pp3='',pp3='',pp4='',pp5='',pp6='',line1='',line2='',top11='',bot11='',bb='',sealprice='',tmp='',text_color_selected='',badge_color_ided='',text_separator_selected='',text_type_selected='',text_color_selected='',text_font_selected='',chksealprice='',zenid='',chksealprice='',zenid='',comments_selected='',comments='';
	if(document.getElementById("attrib-"+badge_color_id)){
		tmp=document.getElementById("attrib-"+badge_color_id);
		badge_color_ided=tmp.options[tmp.selectedIndex].value;
	}
	if(document.getElementById("attrib-"+text_separator_id)){
		tmp=document.getElementById("attrib-"+text_separator_id);
		text_separator_selected=tmp.options[tmp.selectedIndex].value;
	}
	if(document.getElementById("attrib-"+text_type_id)){
		tmp=document.getElementById("attrib-"+text_type_id);
		text_type_selected=tmp.options[tmp.selectedIndex].value;
	}
	if(document.getElementById("attrib-"+text_color_option_id)){
		tmp=document.getElementById("attrib-"+text_color_option_id);
		text_color_selected=tmp.options[tmp.selectedIndex].value;
	}
	if(document.getElementById("attrib-"+text_font_option_id)){
		tmp=document.getElementById("attrib-"+text_font_option_id);
		text_font_selected=tmp.options[tmp.selectedIndex].value;
	}
	if(document.getElementById("sealpricechk"))
		chksealprice=document.getElementById("sealpricechk").value;
	if(document.getElementById("ret_sealprice")){
		seal_selected=document.getElementById("ret_sealprice").value;
	}
	if(document.getElementById("badge_backing"))
		bb=document.getElementById("badge_backing").value;
	if(document.getElementById("comments"))
		comments_selected=document.getElementById("comments").value;
	if(document.getElementById("czenid"))
		zenid=document.getElementById("czenid").value;
	if(document.getElementById("pn1"))
		pp1=document.getElementById("pn1").value;
	if(document.getElementById("top1"))
		top11=document.getElementById("top1").value;
	if(document.getElementById("bot1"))
		bot11=document.getElementById("bot1").value;
	if(document.getElementById("pn2"))
		pp2=document.getElementById("pn2").value;
	if(document.getElementById("pn3"))
		pp3=document.getElementById("pn3").value;
	if(document.getElementById("pn4"))
		pp4=document.getElementById("pn4").value;
	if(document.getElementById("pn5"))
		pp5=document.getElementById("pn5").value;
	if(document.getElementById("pn6"))
		pp6=document.getElementById("pn6").value;
	if(document.getElementById("line1"))
		line1=document.getElementById("line1").value;
	if(document.getElementById("line2"))
		line2=document.getElementById("line2").value;
	if(document.getElementById('badge_backing'))
		popUpArgs = document.getElementById('badge_backing');
	window.open('index.php?main_page=badge_backing&winid='+window.name+'&pid='+pid+'&zenid='+zenid+'&p1='+pp1+'&p2='+pp2+'&p3='+pp3+'&p4='+pp4+'&p5='+pp5+'&line1='+line1+'&line2='+line2+'&top1='+top11+'&bot1='+bot11+'&chksealprice='+chksealprice+'&text_type_selected='+text_type_selected+'&badge_color_ided='+badge_color_ided+'&text_color_selected='+text_color_selected+'&text_font_selected='+text_font_selected+'&badge_backing_selected='+bb+'&text_separator_selected='+text_separator_selected+'&comments_selected='+comments_selected+'&seal_selected='+seal_selected,'Select','width=545,height=450,toolbar=yes,status=yes,scrollbars=yes,resizable=no,menubar=no,location=no,direction=no');
}

function popupWindowDescription(optid){
	window.open('index.php?main_page=show_description&optid='+optid,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=545,height=300,screenX=150,screenY=50,top=100,left=150')
}

function popupWindow(url) {
 window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=600,height=700,screenX=150,screenY=150,top=150,left=150')
}

function update_preview(){
	if(document.getElementById("attrib-"+badge_color_id)){
		var get_badge_color_option=document.getElementById("attrib-"+badge_color_id);
		var badge_color_text=get_badge_color_option.options[get_badge_color_option.selectedIndex].text;
		price=badge_color_text.substring(badge_color_text.indexOf('$')+1,badge_color_text.length-1);
	}
	if(document.getElementById("attrib-"+text_type_id))
		var change_option_text_type=document.getElementById("attrib-"+text_type_id);
	if(document.getElementById("attrib-"+seal_id)){
		if(seal_name==''){
			if(document.getElementById("attrib-"+seal_id).value!="None Selected"){
				seal_name=document.getElementById("attrib-"+seal_id).value;
			}
		}
	}
	if(document.getElementById("attrib-"+badge_color_id)){
		if(badge_color_text.match("Gold on Rhodium")||badge_color_text.match("Rhodium on Gold")||badge_color_text.match("Gol-Ray")||badge_color_text.match("Sil-Ray") )	{
			if(document.getElementById("attrib-"+seal_id)){
				if(seal_name.indexOf(' ($')>0){
					if(document.getElementById("attrib-"+seal_id).value!="None Selected")
						document.getElementById("attrib-"+seal_id).value=seal_name.substring(0,seal_name.indexOf(' ($'));
				}else {
					if(document.getElementById("attrib-"+seal_id).value!="None Selected")
						document.getElementById("attrib-"+seal_id).value=seal_name;
				}
			}
			if(document.getElementById("attrib-"+text_type_id)){
				if(change_option_text_type.options.length==2){
					for(i=0;i<change_option_text_type.options.length;i++){
						newOptName[i]=change_option_text_type.options[i].text;
						newOptvalue[i]=change_option_text_type.options[i].value;
					}
				}	
				change_option_text_type.options.length=0;
				change_option_text_type.options[change_option_text_type.options.length]=new Option(font_type_name,font_type_value);
			}
			document.getElementById("sealpricechk").value='1';
		}else{
			if(document.getElementById("attrib-"+seal_id)){
				if(seal_name.indexOf(' ($')<0){
					document.getElementById("attrib-"+seal_id).value='None Selected';
				}else{
					if(document.getElementById("attrib-"+seal_id).value!="None Selected")
						document.getElementById("attrib-"+seal_id).value=seal_name;
					price=(parseFloat(price)+parseFloat(seal_name.substring(seal_name.indexOf('$')+1,seal_name.length-1)));
				}
			}
			document.getElementById("sealpricechk").value='0';
			if(document.getElementById("attrib-"+text_type_id)){
				if(change_option_text_type.options.length==1){
					change_option_text_type.options.length=0;
					for(i=0;i<2;i++){
						change_option_text_type.options[i]=new Option(newOptName[i],newOptvalue[i]);
					}
				}
				var text_type_option_text=change_option_text_type.options[change_option_text_type.selectedIndex].text;
				if(text_type_option_text.indexOf('$')>0){
					font_type_price_adjust=text_type_option_text.substring(text_type_option_text.indexOf('$')+1,text_type_option_text.length-1);
				}else{
					font_type_price_adjust=0;
				}
				if(parseFloat(font_type_price_adjust)>0){
					price=(parseFloat(price)+parseFloat(font_type_price_adjust));
				}else {
					price=(parseFloat(price)-parseFloat(font_type_price_adjust));
				}
			}
		}
	}
	if(parseFloat(price)>0){
		if(model!='')
			price=price+model;
		document.getElementById("price").innerHTML='$'+price;
	}
	if(document.getElementById("czenid"))
		zenid=document.getElementById("czenid").value;
	document.cart_quantity.action='action.php?zenid='+zenid;
	document.cart_quantity.target='flash_preview';
	document.getElementById("pleaseWait").style.display='';
	document.cart_quantity.submit();
}

function addtocart(pid){
	document.cart_quantity.action='index.php?main_page=product_info?products_id='+pid+'&action=add_product&zenid='+zenid;
	document.cart_quantity.target='_self';
	document.cart_quantity.submit();
}
