document.getElementsByClassName = function(cl) {
	var retnode = [];
	var myclass = new RegExp('\\b'+cl+'\\b');
	var elem = this.getElementsByTagName('*');
	for (var i = 0; i < elem.length; i++) {
	var classes = elem[i].className;
	if (myclass.test(classes)) retnode.push(elem[i]);
	}
	return retnode;
	}; 
	
function lib_bwsrcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=(navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie7=(this.ver.indexOf("MSIE 7")>-1 && this.dom && !this.opera5)?1:0;
	this.ie8=(this.ver.indexOf("MSIE 8")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6||this.ie7||this.ie8
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bwsr=(this.ie8 || this.ie7 || this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
} 
var bwsr=new lib_bwsrcheck();

function validate_link_form(frm) {
	var i=0;
	var link_type_checked = false;
	for (i=0;i<3;i++) {
		if (frm.link_type[i].checked == true) {
			link_type_checked = true;	
		}
	}
	
	if (frm.link_name_eng.value=="" || frm.link_name_fre.value=="") {
		alert("Please enter menu name in French and English.")
		if (frm.link_name_eng.value=="") frm.link_name_eng.focus();
		else if (frm.link_name_fre.value=="") frm.link_name_fre.focus();
		
		return false;
	}
	
	if (link_type_checked == false) {
		
		alert('Please select menu type.');
		frm.link_type[0].focus();
		return false;
		
	}
	
	
}


function show_preview(site_url,label_path,images_url) {
	var text1 = document.frmpreview.label_text1.value;
	var text2 = document.frmpreview.label_text2.value;
	
	var labelimage = site_url + "/image.php?bcolor="+label_path+"/rvl/l1.jpg&call=text&text="+text1+"&text2="+text2+"&font_name=COOPER.TTF&size=20&padding=90&text_align=center";
	
	// wait animation
	document.imgpreview.src = images_url + "/loader.gif";
	document.imgpreview.style.display="block";
	
	var im = new Image();
	im.src = labelimage;
	
	im.onload = function() {
		document.imgpreview.src = im.src;
		document.imgpreview.style.display="block";
	}
	
	document.imgpreview.src = labelimage;
}

function load_preview(site_url,link_id,opid,theme) {
	//alert(theme);return;
	$('#preview_main').html('<img name="imgpreview" src="'+site_url+'/images/loader.gif" align="middle" />');
	
	var text1 = document.frmpreview.label_text1.value;
	var text2 = document.frmpreview.label_text2.value;
	var i=0;
	var theme_p="";
	for(i=0;i<theme.length;i++) {
		theme_p += theme[i]+"|";
	}
	theme_p = theme_p.substr(0,theme_p.length-1);
	
	$('#preview_main').load(site_url + "/load_preview.php",{action:'load_label',link_id:link_id,opid:opid,theme:theme_p,text1:text1,text2:text2}, function(){
		 //$('#uploader').html($('#uploader1').html());
		 //	alert(document.getElementById('preview_main').clientHeight);
		 
	});
	
}

function load_newsletter_form(site_url,newsletter) {
	
	$.prettyPhoto.open(site_url+'/load_newsletter.php&iframe=true', '', newsletter); 
	return false;
	
	//$('#preview_main').html('<img name="imgpreview" src="'+site_url+'/images/loader.gif" align="middle" />');
	/*
	$('#l1').load(site_url + "/load_newsletter.php",{action:'load_nl'}, function() {
				 
	});
	
	return popup(1);
	*/
}

function send_coupon_request(site_url,code,shipcost,shipname) {
	
	
	$('#couponresponse').html('Please wait...');
	
	$('#couponresponse').load(site_url + "/jq_coupon_request.php",{action:'load_label',code:code,shipcost:shipcost}, function(){
		 //$('#uploader').html($('#uploader1').html());
		 //	alert(document.getElementById('preview_main').clientHeight);
		 
	});
	
}

function load_shipopt(site_url,country,state,city,zip) {
	$('#shipopt').html('Loading Canada Post Shipping. Please wait...');
	
	$('#shipopt').load(site_url + "/canship/developer.demo.php",{action:'load_label',country:country,state:state,city:city,zip:zip}, function(){
		
		if ($('#shipopt').html().length < 10) {
			
			$('#coupon_and_cardinfo').show("fast");
		}
		 //$('#uploader').html($('#uploader1').html());
		 
		 //	alert(document.getElementById('preview_main').clientHeight);
		 
	});
}

function loadorder(elm) {
	// 369 = $(elm).attr('href')
	$('#l1').html("Please wait...");
	
	$('#l1').load('orderdetail.php',{order_id:$(elm).attr('href'),call:'detail'}, function(){
	   
	});
}

function validate_product_form(frm) {
	
	if (frm.pname_eng.value=="" || frm.pname_fre.value=="") {
		alert("Please enter product name in French and English.")
		
		if (frm.pname_eng.value=="") frm.pname_eng.focus();
		else if (frm.pname_fre.value=="") frm.pname_fre.focus();
		
		return false;
	}
	
	if(frm.link_id.selectedIndex == -1) {
		alert("Please select product.")
		return false;
	}
	
	var gap = frm.link_id.options[frm.link_id.selectedIndex].text.charAt(0);
	
	gap += gap + gap + gap + gap + gap;
	if(frm.link_id.options[frm.link_id.selectedIndex].text.indexOf(gap) != 0) {
		alert("Please select product.")
		return false;
	}
	
	if (frm.price.value=="") {
		alert("Please enter product price.")
		
		frm.price.focus();
			
		return false;
	}
	
	
}

function domodal() { 
	
	if (bwsr.ie) {
		document.getElementById('modal').style.height = document.body.scrollHeight;
		
		document.getElementById('modal').style.top = 0;
		
		document.getElementById('modalmsg').style.top = document.documentElement.scrollTop; //((document.documentElement.scrollTop+(( document.body.clientHeight-document.getElementById('modalmsg').style.height)/2))-20) + "px";
		
		left = ((document.body.clientWidth-document.getElementById('modalmsg').style.width)/2)-20;
	}
	else {
		
		document.getElementById('modal').style.height = document.body.scrollHeight + "px"; //window.pageYOffset+window.innerHeight;
		
		document.getElementById('modal').style.top = 0;
		document.getElementById('modalmsg').style.top = ((window.pageYOffset+((window.innerHeight-document.getElementById('modalmsg').style.height)/2))-20) + "px";
		//alert(document.getElementById('modalmsg').style.width);
		left = (((window.innerWidth-document.getElementById('modalmsg').style.width)/2)-40) + "px";
	}
	
	document.getElementById('modalmsg').style.left = left;
	
	document.getElementById('modal').style.display = 'block';
	
	document.getElementById('modalmsg').style.display = 'block';
	
	//window.onscroll = domodal;
	
}

function move_preview_indicator() {
	var offset;
	
	offset = (bwsr.ie) ? document.documentElement.scrollTop : window.pageYOffset;
	
	offset = offset + 154;
	
	//document.getElementById("preview_main").innerHTML = offset;
	document.getElementById("rarrow").style.top = offset+"px";
	
	if ((document.getElementById('preview_main').clientHeight-20) != $('#preview_form_div').height()) {
		if((document.getElementById('preview_main').clientHeight) > (document.getElementById('preview_form_div').clientHeight-20)) {
			//$('#preview_form_div').minheight(document.getElementById('preview_main').clientHeight-20);
			document.getElementById('preview_form_div').style.minHeight = document.getElementById('preview_main').clientHeight-20 + "px";
		}
		else {
			//$('#preview_main').minheight(document.getElementById('preview_form_div').clientHeight-20);
			document.getElementById('preview_main').style.minHeight = document.getElementById('preview_form_div').clientHeight-20 + "px";
			
		}
	}
		
	
	//window.onscroll = move_preview_indicator;
}

function doaction(oForm) {
	domodal();
		
	oForm.target = 'ifra';
	oForm.action = 'upload_image.php';
	oForm.submit();
	
	
	return false;
}

function doaction1(oForm) {
	//domodal();
			
	oForm.target = 'ifra';
	oForm.action = 'remove_image.php';
	oForm.submit();
	
	
	return false;
}

function appendOptionLast(selectX,food)
{
	
  var elOptNew = document.createElement('option');
  
  elOptNew.text = "testa";
  elOptNew.value = "test";

  var elSel = document.getElementById(selectX);

  try {
    elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
  }
  catch(ex) {
    elSel.add(elOptNew); // IE only
  }
}

function draw_form(n,opt,langarr) {
	var i;
	if (n>100) {
		n=100;
	}
	
	var form_string = "";
	var form_template = '<div class="gform"> \
						<fieldset > \
							<legend>{LEGEND}</legend> \
							<label>'+langarr[1]+'</label><input type="text" name="pname[]" /> \
							<div class="clear"></div> \
							<label>'+langarr[2]+'</label><select name="design[]"><option>-- '+langarr[3]+' '+langarr[2]+' --</option>{OPTIONS}</select> \
							<div class="clear"></div> \
						</fieldset> \
					</div> \
					';
	
	;
	for (i=1;i<=n;i++) {
		form_string += form_template.replace(/{LEGEND}/i,langarr[0] + " " + i).replace("{OPTIONS}",opt);
	}
	$("#block1").html(form_string);
}

function rowCss() {
	elms=document.getElementsByClassName('row')
	for(var i=0,j=elms.length;i<j;i++)
	{
		if(elms[i].nodeName.toLowerCase()=="div") {
				elms[i].onmouseover=function() {
				this.className+=" over";
			};
				elms[i].onmouseout=function() {
				this.className=this.className.replace(" over", "");
				
			};
		}
	}
}

window.onload=function() {
	rowCss();
	
};

