var click_count=1;
var tab_timer=null;
function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}

function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		//alert("Your Browser Sucks!\nIt's about time to upgrade don't you think?");
	}
}

var Req = getXmlHttpRequestObject();
	

function switch_tab(targetTab, params, obj) {
	//change id of containing div to apply correct css
	obj.parentNode.parentNode.id=targetTab;
	//get all tabs into array and make none have selected class
	array=obj.parentNode.getElementsByTagName('a');
	for (i in array){
		array[i].className='';
	}
	//make active tab select class
	obj.className='selected';
	//make ajax call to function and pass output to handler
	if (Req.readyState == 4 || Req.readyState == 0) {
		Req.open("GET", 'inc.function_call.php?func=' + targetTab + '&params=' + params + '&' + Math.random(), true);
		Req.onreadystatechange = handleSwitchTab; 
		Req.send(null);
	}
}
function handleSwitchTab() {
	if (Req.readyState == 4) {
	var ss = document.getElementById('ajax_tab')
	ss.innerHTML = '';
	ss.innerHTML = Req.responseText;
	run_sIFR("main_header_right_align");
	}
}

function switch_brand_tab(func, brandid, num, targetTab, obj) {
	//cancel tab timer
	if (tab_timer){
		clearTimeout(tab_timer);
	}
	//change background image
	document.getElementById('home_fav_brands').style.backgroundImage='url(../images/backgrounds/fav_brands_bg_'+targetTab+'.jpg)';
	// get tab divs into array and unselect them all
	array=obj.parentNode.parentNode.getElementsByTagName('div');
	for (i in array){
		array[i].className='brand_text_tab';
	}
	// select selected tab
	obj.parentNode.className='brand_text_tab_selected';
	//make ajax call to function and pass output to handler
	if (Req.readyState == 4 || Req.readyState == 0) {
		Req.open("GET", 'inc.function_call.php?func=' + func + '&params=' + brandid + "," + num + "&" + Math.random(), true);
		Req.onreadystatechange = handleSwitchBrandTab; 
		Req.send(null);
	}
}
function handleSwitchBrandTab() {
	if (Req.readyState == 4) {
	var ss = document.getElementById('ajax_brands')
	//ss.innerHTML = '';
	ss.innerHTML = Req.responseText;
	//run_sIFR("main_header_right_align");
	}
}

function cycle_tabs(){
		tab_timer=setTimeout("click_tab(" + click_count + ")", 6000);
			
}
function click_tab(i){
	document.getElementById('brand_tab_link_'+i).onclick();
	if (click_count < 4){
		click_count++;
	}else{
		click_count=1;
	}
	cycle_tabs();
}

function get_mod_select() {
	man_id = document.getElementById('man_select').value;
	if (Req.readyState == 4 || Req.readyState == 0) {
		Req.open("GET", '/includes/inc.get_mod_select.php?man_id=' + man_id + '&' + Math.random(), true);
		Req.onreadystatechange = handleGetModSelect; 
		Req.send(null);
	}
}
function handleGetModSelect(){
	if (Req.readyState == 4) {
	var ss = document.getElementById('phone_select_dropdown')
	ss.innerHTML = '';
	ss.innerHTML = Req.responseText;
	}
}

function run_sIFR(replace)
{
	if(typeof sIFR == "function")
	{
		switch (replace)
		{		

			
			case "main_header_left_align" :
				sIFR.replaceElement(named({sSelector:".prod_header, .checkout_sec_header, .cs_header, .handset_header, .compat_header, .home_header, .myaccount_page_header, .prod_properties_header, .myaccount_page_header, .search_header", 
				sFlashSrc:"/includes/swf/verona.swf", sColor:"#000000", sLinkColor:"#000000", sBgColor:"#FFFFFF", 
				sHoverColor:"#FFF", nPaddingTop:20, nPaddingBottom:0, 
				sFlashVars:"textalign=left&offsetTop=0&offsetBottom=0"}));
			break;
			
			case "sub_header_cs" :
					sIFR.replaceElement(named({sSelector:".cs_subheader, .search_subheader, .myaccount_page_subheader", sFlashSrc:"/includes/swf/modena.swf", 
					sColor:"#77B900", sLinkColor:"#000000", sBgColor:"#FFFFFF", sHoverColor:"#FFF", 
					nPaddingTop:20, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=0"}));
			break;
			
			case "sub_header_left_align" :
					sIFR.replaceElement(named({sSelector:".contact_content_header, .contact_content_text, .phone_text, .contact_content_no, .myaccount_page_subheader, .forgot_pass_txt, .co_column_orderid, .co_column_date, .co_column_total, .co_column_status, .prod_column_qty, .prod_column_code, .prod_column_items, .prod_column_total, .prod_column_status, .rtn_column_desc, .rtn_column_no, .rtn_column_qty, .rtn_column_reason", 
					sFlashSrc:"/includes/swf/modena.swf", sColor:"#000000", sLinkColor:"#e11f55", 
					sBgColor:"#FFFFFF", sHoverColor:"#000000", nPaddingTop:20, nPaddingBottom:0, 
					sFlashVars:"textalign=left&offsetTop=0"}));
			break;
			
			case "sub_header_left_align_magenta" :
					sIFR.replaceElement(named({sSelector:".search_subheader_zero", 
					sFlashSrc:"/includes/swf/modena.swf", sColor:"#E01E53", sLinkColor:"#e11f55", 
					sBgColor:"#FFFFFF", sHoverColor:"#000000", nPaddingTop:20, nPaddingBottom:0, 
					sFlashVars:"textalign=left&offsetTop=0"}));
			break;
			
			case "sub_header_bgcolour" :
					sIFR.replaceElement(named({sSelector:"", sFlashSrc:"/includes/swf/modena.swf", 
					sColor:"#FFFFFF", sLinkColor:"#000000",  sBgColor:"#79BA04", nPaddingTop:20, nPaddingBottom:0, 
					sFlashVars:"textalign=right&offsetTop=0"}));
			break;
			
			default:
		}
	}
}

var origcont;
function staf(prod_id){
	var sender_email = document.getElementById('sender_email').value;
	var friend_email = document.getElementById('friend_email').value;
	
	if (!origcont){
		document.getElementById('sender_email').value='';
		document.getElementById('friend_email').value='';
		origcont=document.getElementById('staf_box').innerHTML;
	}
	if (Req.readyState == 4 || Req.readyState == 0) {
		Req.open("GET", '/staf.php?prod_id=' + prod_id + '&sender_email=' + sender_email + '&friend_email=' + friend_email + '&' + Math.random(), true);
		Req.onreadystatechange = handleStaf; 
		Req.send(null);
	}
}

function handleStaf(){
	if (Req.readyState == 4) {
		var div = document.getElementById('staf_box')
		var str = Req.responseText;
		div.innerHTML = str + origcont;
	}
}

function show_req_payment(){
	method=document.getElementById('payment_method').value;
		document.getElementById('card_no_ast').style.visibility="visible";
		document.getElementById('sec_no_ast').style.visibility="visible";
		document.getElementById('name_ast').style.visibility="visible";
		document.getElementById('expiry_ast').style.visibility="visible";
	switch (method){
		case "VISA" :
			document.getElementById('valid_ast').style.visibility="visible";
			document.getElementById('iss_ast').style.visibility="hidden";
			break;
		case "DELTA" :
			document.getElementById('valid_ast').style.visibility="visible";
			document.getElementById('iss_ast').style.visibility="hidden";
			break;
		case "UKE" :
			document.getElementById('valid_ast').style.visibility="visible";
			document.getElementById('iss_ast').style.visibility="hidden";
			break;
		case "MC" :
			document.getElementById('valid_ast').style.visibility="visible";
			document.getElementById('iss_ast').style.visibility="hidden";
			break;
		case "SOLO" :
			document.getElementById('valid_ast').style.visibility="hidden";
			document.getElementById('iss_ast').style.visibility="visible";
			break;
		case "MAESTRO" :
			document.getElementById('valid_ast').style.visibility="hidden";
			document.getElementById('iss_ast').style.visibility="visible";
			break;
		default:
	}
}
 
// voucher functions start

function check_voucher() {
	var voucher_code = document.getElementById('voucher_code1').value + document.getElementById('voucher_code2').value + document.getElementById('voucher_code3').value + document.getElementById('voucher_code4').value
	if (Req.readyState == 4 || Req.readyState == 0) {
		Req.open("GET", '../includes/check_code.php?voucher_code=' + voucher_code + "&" + Math.random(), true);
		Req.onreadystatechange = handleVoucherCode; 
		Req.send(null);
	}
}

function nextbox(fldobj, nbox) { 
if (fldobj.value.length==fldobj.maxLength) {
fldobj.form.elements[nbox].focus();
}
} 

function handleVoucherCode() {
	if (Req.readyState == 4) {
		if (Req.responseText==''){
			window.location = "basket.php"
		}
	var ss = document.getElementById('voucher_details')
	ss.innerHTML = '';
	ss.innerHTML = Req.responseText;
	}
}

function showPhone(src)
{
	var img = document.getElementById("phone_display");
	//var select = document.getElementById("mod_select");
	img.src = src;
	img.style.display = '';
	
	img.onmouseout = function()
	{
		alert("out");
		img.style.display = 'none';
	}
}

function redirect(url)
{
	window.location = url;
}

function sending_pay()
{
	var btn = document.getElementById("buy_btn");
	btn.src = "images/ajax-loader.gif";
	var link = document.getElementById("buy_link");
	link.removeAttribute('href');
	var t = setTimeout(redirect("checkout_confirm.htm?action=order"), 10000);
}