

function $(id) {
	return document.getElementById(id);
}

function href(link) {
	location.href = link;
}

function displayPopup(url, width, height) {
	var Win = window.open(url,"displayPopup",'width=' + width + ',height=' + height + ',resizable=no,scrollbars=no,menubar=no');
}

function valPhone(obj) {
	val = obj.value;
	id = obj.id;
	check = $(id).value.substr(($(id).value.length)-1,1);
	if(check!= '+' && check!= '(' && check!= ' ' && check!= ')' && isNaN(check)){
		$(id).value = $(id).value.substr(0, ($(id).value.length)-1);
	}
}

function valIntLimit(obj,limit) {
	val = obj.value;
	id = obj.id;
	check = $(id).value.substr(($(id).value.length)-1,1);
	if (isNaN(val) || $(id).value.length>limit) {
		$(id).value = $(id).value.substr(0, ($(id).value.length)-1);
	}
}

function valNo(obj){
	val = obj.value;
	id = obj.id;
	check = $(id).value.substr(($(id).value.length)-1,1);
	if(isNaN(check)){
		$(id).value = $(id).value.substr(0, ($(id).value.length)-1);
	}
}


/******************/


function showSubmenu() {
	if ($('submenu').style.display == 'none') {
		$('submenu').style.display = 'block';
	}
	else {
		$('submenu').style.display = 'none';
	}
}

function changeCategory() {
	if ($('category').value!='') {
		var action  = $('root').value;
		var subpage = $('category').value + '/';
		href(action + subpage);
	}
}


function changePrice() {
	var id = $('material_size').value;

	if (id!='') {

		advAJAX.post({
			url: "lib/functions.ajax.php?f=changePrice&id="+id,
			onLoading : function(obj) { 
				$('buy_option').innerHTML = 'Please wait ...';
			},
			onSuccess : function(obj) { 
				$('buy_option').innerHTML = obj.responseText;
			}
		});

	}
	else {
		$('buy_option').innerHTML = '<span class="btn_buy_" onclick="_tip();">BUY</span><div id="_tip"></div>';
	}
}

function _tip() {
	$('_tip').innerHTML = 'Choose your option...';
}


function buyProduct() {
	var id = $('material_size').value;
	if (id!='') {
		advAJAX.post({
			url: "lib/functions.ajax.php?f=buy&id="+id,
			onLoading : function(obj) { 
				$('basket_container').innerHTML = 'Please wait ...';
			},
			onSuccess : function(obj) { 
				$('basket_container').innerHTML = obj.responseText;
			}
		});
	}
}


function submit(id) {
	document.getElementById(id).submit();
}


function remove_price(id) {
	$('p_'+id).innerHTML = '';
	$('p_'+id).style.display = 'none';
}



function getStyleObject(objectId) {
	if(document.getElementById && $(objectId)) {
		return $(objectId).style;
	} else if (document.all && document.all(objectId)) {
		return document.all(objectId).style;
	} else if (document.layers && document.layers[objectId]) {
		return getObjNN4(document,objectId);
	} else {
		return false;
	}
} 

function changeObjectVisibility(objectId, newVisibility) {
	var styleObject = getStyleObject(objectId, document);
	if(styleObject) {
		styleObject.visibility = newVisibility;
		return true;
	} else {
		return false;
	}
}
function changeObjectPositionType(objectId, newPositionType) {
	var styleObject = getStyleObject(objectId, document);
	if(styleObject) {
		styleObject.position = newPositionType;
		return true;
	} else {
		return false;
	}
}


function show_prices() {
	//alert($('active').checked);
	if ($('active').checked==true) {
		$('prices_container').style.display = 'block';
	}
	else {
		$('prices_container').style.display = 'none';
	}

}

function confirmation(link,msg) {
	conf = confirm(msg);
	if (conf == true) {
		location.href = link;
	}
}

function bookmarkme() {
	var txt = "Bookmark Us!"
	var url = "http://www.photoartfactory.co.uk/";
	var who = "photo ART factory"

	var ver = navigator.appName
	var num = parseInt(navigator.appVersion)
	if ((ver == "Microsoft Internet Explorer")&&(num >= 4)) {
		window.external.AddFavorite(url,who);
	}else{
		alert('Hit Ctrl+D to bookmark this page');
	}

}


function counter_bar(field, countfield, max) {
	var fld = field;
	var cnt = $(countfield);
	var bar = $('bar');

	if (fld.value.length > max) {
		fld.value = fld.value.substring(0, max);
	}
	cnt.value = max - fld.value.length;
	var width = ((fld.value.length*100)/max)+'%';
	bar.style.width = width;
}

